当前位置:网站首页>Arduino实验一:双色灯实验
Arduino实验一:双色灯实验
2022-07-26 21:48:00 【《博览群书》】
OK,暑假的第一阶段外出学习已经告一段落,在家1周居家和4次核酸也已经完成,外出学习的忙碌和1周的休闲,让我度过了假期的轻松愉快和自由的生活,现在开始第二阶段的学习阶段
今天开始把Arduino的创乐博物联网传感器套装的所有实验一一搬上CSDN的blog,一在记录自己的实验结果,二来和各位老师们一起交流一下,开心的在CSDN玩耍
OK,双色灯实验,我先来解释一下
传感器有3个端口,分别是:
1:G:GREEN(绿色) 接我们Arduino的10管脚
2:R:RED(红色) 接我们Arduino的11管脚
3:-:GND(接地) 接我们Arduino的接地
如图所示:

传感器和Arduino的接线图如下图所示(这里是实验指导书上的图,我自己重新做了实验,视频是中间接了面包板,为了显得更加专业和布线规范,两个图的接线其实是一样的,建议大家也用面包板接线,会更加专业和规范):

下图是我的本次实验的接线图,接线端口是一样的:

好的,那么我们上核心组成部分,也就是代码:
int redPin = 11; //定义红色11管脚
int greenPin=10; //定义绿色10管脚
int val=0; //整型变量val初始为0
void setup() { //两个主要函数体之一setup(),程序开始先运行,且只运行1次
// put your setup code here, to run once:
pinMode(redPin,OUTPUT); //设置11管脚为输出模式
pinMode(greenPin,OUTPUT); //设置10管脚为输出模式
Serial.begin(9600); //串口波特率设置为9600,打开串口时要设置成代码一样的波特率9600
}
void loop() { //主要函数之主函数,循环执行
// put your main code here, to run repeatedly:
for(val=255;val>0;val--) //for循环,val从255,每隔30ms减一,直到减到1,循环结束
{
analogWrite(redPin,val); //11管脚为模拟输出,输出值为val
analogWrite(greenPin,255-val); //10管脚为模拟输出,输出值为255-val
Serial.println(val,DEC); //串口打印val的值(加了时间标签)
delay(30); //延时30ms
}
for(val=0;val<255;val++) //for循环,val每隔30ms加一,从0增加到254,循环结束
{
analogWrite(redPin,val); //11管脚为模拟输出,输出值为val
analogWrite(greenPin,255-val); //10管脚为模拟输出,输出值为255-val
Serial.println(val,DEC); //串口打印val(加了时间标签)
delay(30); //延时30ms
}
}OK,硬件连接给了,软件也给了,那我们就可以直接把程序下载进我们的Arduino板子里跑起来了
就实验结果视频我也放在下面:
第一个视频是双色灯循环变色视频,我们可以看见,根据代码,灯先是红色,慢慢红色变暗,同时绿色变亮,配比的颜色显示,可能有点橘黄,然后变成完全绿色,之后,绿色开始变亮,同时红色开始变暗,中间色也是配比,有点橘黄,最后完全变绿,就这样循环变色
这就是双色灯实验了:
Arduino的双色灯实验视频
第二个视频是串口显示的视频,我也放上来,更加完整和直观:
双色灯实验串口显示
OK,以上就是我的双色灯实验,希望对你有所帮助,我们一起交流,学习,幸福地生活
如果有问题可以私信我,一起交流讨论一下
感谢你的鼓励,我会继续努力的
边栏推荐
- Blog Garden beautification skills summary
- what is qrc in qt
- [horizon sunrise X3 sect trial experience] + unpacking post
- Database notes (from Lao She)
- yolov1
- A chip company fell in round B
- Xiaobai learns MySQL - derived table
- unity 安装失败:operation not permitted, mkdir......
- 同花顺手机炒股开户安全吗?怎么办理开户呢
- Five years after graduation, I changed from information management to software testing engineer, and my monthly salary finally exceeded 12K
猜你喜欢

小白学习MySQL - Derived Table

The trailer of Samsung Galaxy Z foldable product leaked: 'flexibility is better than plane'

yolov1

SQL注入 Less26(过滤空格和注释符,使用不带空格的报错注入)

2018 arXiv preprint | MolGAN: An implicit generative model for small molecular graphs

【地平线旭日X3派试用体验】+开箱帖

Development status of Dao

Matlab solution of the densest stacking and smallest circumscribed square of N circles (two-dimensional, three-dimensional, etc. circle packing problem)

unity 安装失败:operation not permitted, mkdir......

A few pictures help you clarify "China's financial institution system"
随机推荐
Development status of Dao
Protobuf之proto基础语法
纷享销客罗旭对话西门子王海滨:先进制造,要向数字化要效益
SQL injection less26 (filter spaces and comments, and use error injection without spaces)
Y78. Chapter IV Prometheus' monitoring system and practice -- Prometheus' service discovery mechanism (IX)
Matlab solution of the densest stacking and smallest circumscribed square of N circles (two-dimensional, three-dimensional, etc. circle packing problem)
Excel-vba quick start (XI. Common string operations)
[try to hack] firewall (I)
Five years after graduation, I changed from information management to software testing engineer, and my monthly salary finally exceeded 12K
what is qrc in qt
什么是 Base64 ?
yolov1
JSON字符串转化为JSON对象,获取某个key的值,判断某个key是否存在
调试stc8a8k64d4单片机485通信总结
what crlf mean
What you need to know about mobile video compatibility
Concept and classification of processes
【论文阅读】LOGAN:Membership Inference Attacks Against Generative Models
Write golang simple C2 remote control based on grpc
VCS编译、仿真过程