当前位置:网站首页>【树莓派】树莓派调光
【树莓派】树莓派调光
2022-08-05 03:30:00 【吾爱吃西红柿】
一、树莓派非PWM引脚,模拟PWM调光
#include <stdio.h>
#include <stdlib.h>
#include <wiringPi.h>
#include <pthread.h>
unsigned int bedroom_brightness;
void *bedroom_brightness_set(void *arg)//线程函数
{
while(1){
// 设置一个周期为1ms,占空比为60%
//2引脚低电平时发光
digitalWrite(2, LOW);
delayMicroseconds(1000-(bedroom_brightness*100));
//高电平时熄灭
digitalWrite(2, HIGH);
delayMicroseconds(bedroom_brightness*100); // 微秒级延迟,0.4ms
// }
}
}
void main(){
pthread_t id;
id = pthread_create(&id, NULL, bedroom_brightness_set, NULL);//创建线程
wiringPiSetup(); //初始化硬件环境
pinMode(2, OUTPUT);
while(1)
{
printf("brightness;");
scanf("%d", &bedroom_brightness);//设定亮度,数值(0-10)
}
}
二、树莓派PWM引脚调光
PS:仅支持PWM引脚,树莓派PWM引脚默认有GPIO1,其他参考引脚图
#include <wiringPi.h>
void bedroom_brightness_set(int *bedroom_brightness, int *bright_last)
{
if(*bedroom_brightness < *bright_last)//调低亮度(下一次设定的亮度小于当前亮度)
{
for(*bright_last; *bedroom_brightness<*bright_last; --*bright_last)
{
pwmWrite(1, *bright_last);//向pwm中写入任意自己想要的值(默认0-1024)
delay(1);
}
printf("亮度变低\n");
}
else if(*bedroom_brightness > *bright_last)//调高亮度(下一次设定的亮度大于当前亮度)
{
for(*bright_last; *bright_last<*bedroom_brightness; ++*bright_last)
{
pwmWrite(1, *bright_last); //数值范围(0-1024)
delay(1);
}
printf("亮度变高\n");
}
*bright_last = *bedroom_brightness;
}
边栏推荐
猜你喜欢
冰蝎V4.0攻击来袭,安全狗产品可全面检测
如何在WordPress中添加特定类别的小工具
用CH341A烧录外挂Flash (W25Q16JV)
UE4 opens doors with overlapping events
龙蜥社区第二届理事大会圆满召开!理事换届选举、4 位特约顾问加入
Walter talked little knowledge | "remote passthrough" that something
Increasing leetcode - a daily topic 1403. The order of the boy sequence (greed)
[Software testing] unittest framework for automated testing
Open-Falcon of operation and maintenance monitoring system
YYGH-13-Customer Service Center
随机推荐
UE4 通过与其它Actor互动开门
AI+PROTAC | dx/tx completes $5 million seed round
Hard power or soft power, which is more important to testers?
运维监控系统之Open-Falcon
burp安装及代理设置
Turn: Charles Handy: Who you are is more important than what you do
论治理与创新,2022 开放原子全球开源峰会 OpenAnolis 分论坛圆满落幕
Burp installation and proxy settings
iMedicalLIS监听程序(2)
UE4 通过重叠事件开启门
用CH341A烧录外挂Flash (W25Q16JV)
Acid (ACID) Base (BASE) Principles for Database Design
阿里本地生活单季营收106亿,大文娱营收72亿,菜鸟营收121亿
pyqt5 + socket 实现客户端A经socket服务器中转后主动向客户端B发送文件
【软件测试】自动化测试之unittest框架
Web3.0 Dapps - the road to the future financial world
2022 High-level installation, maintenance, and removal of exam questions mock exam question bank and online mock exam
IJCAI2022 | DictBert: Pre-trained Language Models with Contrastive Learning for Dictionary Description Knowledge Augmentation
[论文笔记] MapReduce: Simplified Data Processing on Large Clusters
MRTK3开发Hololens应用-手势拖拽、旋转 、缩放物体实现