在这个链接的实验基础上改造的http://arduino.cc/en/Tutorial/BarGraph
昨天刚拿到的板子,对硬件还不太熟悉,就上官网查了一下,正好有这个实验,硬件直接照搬,电阻没有220欧姆就用了240欧姆的,貌似没有问题,十个灯,从左到右依次点亮,然后从第十个依次熄灭,反复循环,代码也是在官方实验基础上修改的,做给闺女看的,小家伙还挺感兴趣,O(∩_∩)O~
代码写的很烂,不过能用,O(∩_∩)O~
[mw_shl_code=cpp,true]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);
}
}[/mw_shl_code] |