参考博客:http://www.cnblogs.com/jikexianfeng/p/6243654.html
参考网站:http://wiki.geek-workshop.com/doku.php?id=arduino:arduino_language_reference
参考文档:http://wiring.org.co/reference/
参考网页:http://www.cnblogs.com/jikexianfeng/p/6031291.html
1 /********************************* 2 代码功能:输出模拟信号,控制RGB灯的颜色 3 使用函数: 4 pinMode(引脚号,模式); 5 analogWrite(引脚号,电压参数); //输出模拟电压 = 5/256*电压参数 6 constrain(输入参数,区间下界,区间上界); //区间函数 7 random(随机种子); //产生一个随机数 8 具体函数用法请参考博主的另一篇文档:《arduino api手册》 9 网址:http://www.cnblogs.com/jikexianfeng/p/6243654.html 10 创作时间:2017*1*4 11 作者邮箱:[email protected] 12 ********************************/ 13 int Redpin = 11; //红 14 int Greenpin = 10; //绿 15 int Bluepin = 9; //蓝 16 17 void setup(){ 18 pinMode(Redpin,OUTPUT); 19 pinMode(Greenpin,OUTPUT); 20 pinMode(Bluepin,OUTPUT); 21 } 22 void loop() 23 { 24 randomSeed(analogRead(0)); 25 for(int x=0; x<256;x++){ 26 27 analogWrite(Redpin,constrain(random(256),0,255)); 28 analogWrite(Greenpin,constrain(random(256),0,255)); 29 analogWrite(Bluepin,constrain(random(256),0,255)); 30 delay(100); 31 } 32 }
时间: 2024-10-14 07:46:51