当前位置:网站首页>【树莓派】树莓派调光
【树莓派】树莓派调光
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;
}
边栏推荐
- 2022-08-04T17:50:58.296+0800 ERROR Announcer-3 io.airlift.discovery.client.Announcer appears after successful startup of presto
- ffmpeg enumeration decoders, encoders analysis
- The most effective seven performance testing techniques of software testing techniques
- Detailed and comprehensive postman interface testing practical tutorial
- UE4 后期处理体积 (角色受到伤害场景颜色变淡案例)
- MRTK3开发Hololens应用-手势拖拽、旋转 、缩放物体实现
- Why did they choose to fall in love with AI?
- 数学-求和符号的性质
- MySql的索引学习和使用;(本人觉得足够详细)
- Android实战开发-Kotlin教程(入门篇-登录功能实现 3.3)
猜你喜欢

今年七夕,「情蔬」比礼物更有爱

token、jwt、oauth2、session解析

用Unity发布APP到Hololens2无坑教程

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

UE4 opens doors with overlapping events

presto启动成功后出现2022-08-04T17:50:58.296+0800 ERROR Announcer-3 io.airlift.discovery.client.Announcer

Ice Scorpion V4.0 attack, security dog products can be fully detected

ASP.NET应用程序--Hello World

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

基于生长的棋盘格角点检测方法
随机推荐
Web3.0 Dapps——通往未来金融世界的道路
YYGH-13-客服中心
沃谈小知识 |“远程透传”那点事儿
包拉链不可用,但是是被另一个包。
Solana NFT开发指南
sql怎么找字段里所有数据为空的字段
今年七夕,「情蔬」比礼物更有爱
MySql的索引学习和使用;(本人觉得足够详细)
Leading the highland of digital medicine, Zhongshan Hospital explores to create a "new paradigm" for future hospitals
Kubernetes 网络入门
The sword refers to Offer--find the repeated numbers in the array (three solutions)
token、jwt、oauth2、session解析
YYGH-13-Customer Service Center
rpc-remote procedure call demo
Burp installation and proxy settings
【已解决】Unity Coroutinue 协程未有效执行的问题
AI+PROTAC | dx/tx completes $5 million seed round
Queue Topic: Recent Requests
rpc-remote procedure call demo
Dynamic management of massive service instances