当前位置:网站首页>【树莓派】树莓派调光
【树莓派】树莓派调光
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;
}
边栏推荐
- 思考(八十八):使用 protobuf 自定义选项,做数据多版本管理
- The second council meeting of the Dragon Lizard Community was successfully held!Director general election, 4 special consultants joined
- The most effective seven performance testing techniques of software testing techniques
- 36-Jenkins-Job Migration
- Use SuperMap iDesktopX data migration tool to migrate ArcGIS data
- 2022.8.4-----leetcode.1403
- 数组常用方法总结
- 大佬们,我注意到mysql cdc connector有参数scan.incremental.sna
- UE4 通过互动(键盘按键)开门
- 【七夕节】浪漫七夕,代码传情。将爱意变成绚烂的立体场景,给她(他)一个惊喜!(送代码)
猜你喜欢

MySql的索引学习和使用;(本人觉得足够详细)

36-Jenkins-Job Migration

This year's Qixi Festival, "love vegetables" are more loving than gifts

引领数字医学高地,中山医院探索打造未来医院“新范式”

After the large pixel panorama is completed, what are the promotion methods?

.NET Application -- Helloworld (C#)

静态方法获取配置文件数据

leetcode-每日一题1403. 非递增顺序的最小子序列(贪心)

Walter talked little knowledge | "remote passthrough" that something

大像素全景制作完成后,推广方式有哪些?
随机推荐
burp安装及代理设置
高项 02 信息系统项目管理基础
21天学习挑战赛(2)图解设备树的使用
如何在WordPress中添加特定类别的小工具
大像素全景制作完成后,推广方式有哪些?
数据库设计的酸(ACID)碱(BASE)原则
Dive into how it works together by simulating Vite
Ffmpeg - sources analysis
Industry Status?Why do Internet companies prefer to spend 20k to recruit people rather than raise their salary to retain old employees~
[Qixi Festival] Romantic Tanabata, code teaser.Turn love into a gorgeous three-dimensional scene and surprise her (him)!(send code)
Static method to get configuration file data
用Unity发布APP到Hololens2无坑教程
Use SuperMap iDesktopX data migration tool to migrate ArcGIS data
Redis key basic commands
YYGH-13-客服中心
Call Alibaba Cloud oss and sms services
UE4 后期处理体积 (角色受到伤害场景颜色变淡案例)
数组常用方法总结
token、jwt、oauth2、session解析
MySql的索引学习和使用;(本人觉得足够详细)