当前位置:网站首页>【树莓派】树莓派调光
【树莓派】树莓派调光
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;
}
边栏推荐
- 包拉链不可用,但是是被另一个包。
- The most effective seven performance testing techniques of software testing techniques
- ffmpeg pixel format basics
- 银行数据采集,数据补录与指标管理3大问题如何解决?
- On governance and innovation, the 2022 OpenAtom Global Open Source Summit OpenAnolis sub-forum came to a successful conclusion
- 2022 High-level installation, maintenance, and removal of exam questions mock exam question bank and online mock exam
- Detailed and comprehensive postman interface testing practical tutorial
- The sword refers to Offer--find the repeated numbers in the array (three solutions)
- [Paper Notes] MapReduce: Simplified Data Processing on Large Clusters
- cross domain solution
猜你喜欢

2022-08-04T17:50:58.296+0800 ERROR Announcer-3 io.airlift.discovery.client.Announcer appears after successful startup of presto

新人如何入门和学习软件测试?

Developing Hololens encountered The type or namespace name 'HandMeshVertex' could not be found..

阿里本地生活单季营收106亿,大文娱营收72亿,菜鸟营收121亿

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

Based on holding YOLOv5 custom implementation of FacePose YOLO structure interpretation, YOLO data format conversion, YOLO process modification"

Use CH341A to program external Flash (W25Q16JV)

On governance and innovation, the 2022 OpenAtom Global Open Source Summit OpenAnolis sub-forum came to a successful conclusion

冒泡排序与快速排序

The most effective seven performance testing techniques of software testing techniques
随机推荐
用CH341A烧录外挂Flash (W25Q16JV)
leetcode-每日一题1403. 非递增顺序的最小子序列(贪心)
token、jwt、oauth2、session解析
905. Interval selection
MRTK3开发Hololens应用-手势拖拽、旋转 、缩放物体实现
On governance and innovation, the 2022 OpenAtom Global Open Source Summit OpenAnolis sub-forum came to a successful conclusion
Common open source databases under Linux, how many do you know?
Android 面试题——如何徒手写一个非阻塞线程安全队列 ConcurrentLinkedQueue?
Hard power or soft power, which is more important to testers?
今年七夕,「情蔬」比礼物更有爱
结构体初解
905. 区间选点
Solana NFT开发指南
【滤波跟踪】基于matlab无迹卡尔曼滤波惯性导航+DVL组合导航【含Matlab源码 2019期】
【已解决】Unity Coroutinue 协程未有效执行的问题
UE4 第一人称角色模板 添加蹲伏功能
2022高处安装、维护、拆除考试题模拟考试题库及在线模拟考试
Confessing the era of digital transformation, Speed Cloud engraves a new starting point for value
Open-Falcon of operation and maintenance monitoring system
Android Practical Development - Kotlin Tutorial (Introduction - Login Function Implementation 3.3)