(1)Arduino練習:霹靂燈
(2)程式碼
int sensorPin = A0;
int ledPin = 13;
int sensorValue = 0;
void setup() {
Serial.begin(9600);
pinMode(13, OUTPUT);
pinMode(12, OUTPUT);
pinMode(11, OUTPUT);
pinMode(10, OUTPUT);
pinMode(9, OUTPUT);
pinMode(8, OUTPUT);
pinMode(7, OUTPUT);
}
void loop() {
sensorValue = analogRead(sensorPin);
Serial.println(sensorValue);
for (int i=13; i>=7; i--) {
digitalWrite(i, HIGH);
delay(sensorValue/10);
}
for (int i=13; i>=7; i--) {
digitalWrite(i, LOW);
delay(sensorValue/10);
}
}
沒有留言:
張貼留言