http://ming-shian.blogspot.tw/2013/05/ardunioled_5.html
二、接線圖
三、程式碼
const int analogPin = A0; // the pin that the potentiometer is attached to const int ledCount = 5; // the number of LEDs int ledPins[] = { 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); } } void loop() { // read the potentiometer: // int sensorReading = analogRead(analogPin); // map the result to a range from 0 to the number of LEDs: //int ledLevel = map(sensorReading, 0, 1023, 0, ledCount); // loop over the LED array: for (int thisLed = 0; thisLed < ledCount; thisLed++) { digitalWrite(ledPins[thisLed], HIGH); delay(100); digitalWrite(ledPins[thisLed], LOW); } for (int thisLed = ledCount-1; thisLed >= 0; thisLed--) { digitalWrite(ledPins[thisLed], HIGH); delay(100); digitalWrite(ledPins[thisLed], LOW); if (thisLed ==0){ digitalWrite(ledPins[thisLed], HIGH ); delay(100); } } }四、作業練習:
如何利用可變電阻來調整霹靂燈速?
沒有留言:
張貼留言