本帖最后由 弘毅 于 2012-12-18 23:29 编辑
昨天拿到的nuo R3版,按照惯例淘宝搞定,45元,昨天半夜用IDE中的blink测试了一下板子,好用。今天承诺闺女做个流水灯,刚拿到硬件,一定不熟悉于是去官网搜了一下,找到了下面这个example(http://arduino.cc/en/Tutorial/BarGraph),于是依葫芦画瓢,接好硬件,没找到220Ω的电阻,就用了240Ω的,不大点事,代码直接把官网的复制过来,修改了一下,最终效果就是从左到右每隔500毫秒点亮一个灯,全部点亮后,从右到左每隔500毫秒依次熄灭,如此循环,闺女(2岁10个月)看了还挺感兴趣,不过没一会儿就拿着杜邦线忘面包板上乱插一气,俺的心哇凉啊,O(∩_∩)O~
-------------------------------------下面是代码-----------------------------
const int ledCount = 10; // the number of LEDs in the bar graph
int ledPins[] = {2, 3, 4, 5, 6, 7,8,9,10,11 }; // an array of pin numbers to which LEDs are attached
void setup()
{
// loop over the pin array and set them all to output:
for (int thisLed = 0; thisLed < ledCount; thisLed++)
{
pinMode(ledPins[thisLed], OUTPUT);
}
}
int ledIndex=0;
boolean flag=true;
void loop()
{
//turn on all pins
for (int i=0;i<ledCount;i++)
{
digitalWrite(ledPins, HIGH);
delay(500);
}
// turn off all pins
for (int i=ledCount-1;i>=0;i--)
{
digitalWrite(ledPins, LOW);
delay(500);
}
}
----------------------------------代码结束---------------------------------------
效果图片:
|