当前位置:网站首页>【树莓派】树莓派调光
【树莓派】树莓派调光
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;
}
边栏推荐
- token、jwt、oauth2、session解析
- IJCAI2022 | DictBert: Pre-trained Language Models with Contrastive Learning for Dictionary Description Knowledge Augmentation
- 用Unity发布APP到Hololens2无坑教程
- Never put off till tomorrow what you can put - house lease management system based on the SSM
- 结构体初解
- The sword refers to Offer--find the repeated numbers in the array (three solutions)
- Industry Status?Why do Internet companies prefer to spend 20k to recruit people rather than raise their salary to retain old employees~
- [Storage] Dawning Storage DS800-G35 ISCSI maps each LUN to the server
- 新人如何入门和学习软件测试?
- 惨遭打脸:字节某部门竟有这么多测试员
猜你喜欢

开发Hololens遇到The type or namespace name ‘HandMeshVertex‘ could not be found..

The most effective seven performance testing techniques of software testing techniques

Detailed and comprehensive postman interface testing practical tutorial

UE4 在游戏运行时更改变量 (通过鼠标滑轮来更改第一人称角色的最大行走速度)
![[GYCTF2020]EasyThinking](/img/40/973411c69d1e4766d22f6a4a7c7c01.png)
[GYCTF2020]EasyThinking

UE4 第一人称角色模板 添加生命值和调试伤害

The second council meeting of the Dragon Lizard Community was successfully held!Director general election, 4 special consultants joined

七夕节代码表白

How to Add Category-Specific Widgets in WordPress

ASP.NET application--Hello World
随机推荐
Growth-based checkerboard corner detection method
Talking about data security governance and privacy computing
905. Interval selection
大像素全景制作完成后,推广方式有哪些?
MRTK3开发Hololens应用-手势拖拽、旋转 、缩放物体实现
Redis key basic commands
You may use special comments to disable some warnings. 报错解决的三种方式
论治理与创新,2022 开放原子全球开源峰会 OpenAnolis 分论坛圆满落幕
UE4 为子弹蓝图添加声音和粒子效果
After the large pixel panorama is completed, what are the promotion methods?
ffmpeg -sources分析
引领数字医学高地,中山医院探索打造未来医院“新范式”
Android Practical Development - Kotlin Tutorial (Introduction - Login Function Implementation 3.3)
冰蝎V4.0攻击来袭,安全狗产品可全面检测
Turn: Charles Handy: Who you are is more important than what you do
On governance and innovation, the 2022 OpenAtom Global Open Source Summit OpenAnolis sub-forum came to a successful conclusion
Use Unity to publish APP to Hololens2 without pit tutorial
How to Add Category-Specific Widgets in WordPress
Increasing leetcode - a daily topic 1403. The order of the boy sequence (greed)
markdown如何换行——md文件