步骤1:您需要的内容。
您将需要:
6个LED(可能还有更多)。
跳线
面包板和/或原型板
第2步:编程。
使用以下代码对Arduino进行编程。
//feel free to make changes
//do not connect led‘s in sequential order
//make sure all led’s are connected to a resistor if applicable
//this project was made and tested using only one wire and arduino‘s pin 13 resistor and LED
//note: pin 5 and 6 act weird in the beginning - an arduino bug
byte led1 = 3;
byte led2 = 5;
byte led3 = 6;
byte led4 = 9;
byte led5 = 10;
byte led6 = 11;
int x = 0;
int y = 0;
int steps = 1; //change if needed, defines the steps between 0 and 255, a lower number is smoother
//make sure the variable “steps” is a factor of 255; any of the below numbers
//factors of 255 are : 1,3,5,15,17,51,85,255
//sorry for a lot of notes, but remember to change variable “delaytime” according to variable “steps”
//delay is in milliseconds for below
int delaytime = 10; //change if needed, delay between increments of PWM
//850 milliseconds is on-off/off-on time, in 17 step increments of brightness
int delaytime2 = 1000; //change if needed, delay between switching of leds
void setup (){
pinMode (led1, OUTPUT);
pinMode (led2, OUTPUT);
pinMode (led3, OUTPUT);
pinMode (led4, OUTPUT);
pinMode (led5, OUTPUT);
pinMode (led6, OUTPUT);
do {
x = x + steps;
analogWrite (led1, x);
analogWrite (led2, x);
delay (delaytime);
}
while (x != 255);
}
void loop (){
y = 0;
x = 255;
delay (delaytime);
do{
y = y + steps;
x = x - steps;
analogWrite (led3, y);
analogWrite (led1, x);
delay (delaytime);
}
while (y != 255 && x != 0);
delay (delaytime2);
y = 0;
x = 255;
do{
y = y + steps;
x = x - steps;
analogWrite (led4, y);
analogWrite (led2, x);
delay (delaytime);
}
while (y != 255 && x != 0);
delay (delaytime2);
y = 0;
x = 255;
do{
y = y + steps;
x = x - steps;
analogWrite (led5, y);
analogWrite (led3, x);
delay (delaytime);
}
while (y != 255 && x != 0);
delay (delaytime2);
y = 0;
x = 255;
do{
y = y + steps;
x = x - steps;
analogWrite (led6, y);
analogWrite (led4, x);
delay (delaytime);
}
while (y != 255 && x != 0);
delay (delaytime2);
y = 0;
x = 255;
do{
y = y + steps;
x = x - steps;
analogWrite (led1, y);
analogWrite (led5, x);
delay (delaytime);
}
while (y != 255 && x != 0);
delay (delaytime2);
y = 0;
x = 255;
do{
y = y + steps;
x = x - steps;
analogWrite (led2, y);
analogWrite (led6, x);
delay (delaytime);
}
while (y != 255 && x != 0);
delay (delaytime2);
}
第3步:电路。
每个LED并将其连接到面包板的接地导轨。将正极引线连接到Arduino的引脚3、5、6、9、10、11。
步骤4:渐隐!
现在,LED应该以伪随机的方式褪色。您已完成,但对于印象深刻的人,请单击“下一步”。
步骤5:下沉和采购。
这是我如何教授下沉和源的方法。
下沉是指从输出引脚到地。所谓采购,是指从正极到输出引脚。
这样想。电源可以从LED流向源极。在下沉时,电源来自引脚。电源始终由引脚提供,因此,当引脚变为高电平时,电流会“通过” LED到达引脚,从而将其关闭。
对于大多数人来说,他们应该说:“这有什么区别? “
对一个随机的人moi来说,它的意思是:“我可以反转信号,从而产生更大的随机性!”
请记住,避免使用电阻器(有生命危险)从3.3伏特为其供电。 p》
第6步:这样做。..
现在取第3针作为源。
取第6针作为源。
取第9针作为源。
然后取第11针作为源。
将其余的留在原处。
第7步:确实完成。
现在,可以实现随机效果(让我恶作剧的时间)(借口) -moi 。.. BWA-HA-HAHA-HA!)点击完成。
-
led
+关注
关注
240文章
23130浏览量
658351 -
Arduino
+关注
关注
187文章
6463浏览量
186621
发布评论请先 登录
相关推荐
评论