互動技術 ARDUINO 1127 練習
練習一燈泡循序漸進
練習二燈泡不按照規律亮燈
自由發揮創意
燈泡排成 菱形
練習三 程式碼:
int sensorPin = A0; // select the input pin for the potentiometer
int ledPin = 13; // select the pin for the LED
int sensorValue = 0; // variable to store the value coming from the sensor
void setup() {
// declare the ledPin as an OUTPUT:
pinMode(13, OUTPUT);
pinMode(12, OUTPUT);
pinMode(11, OUTPUT);
pinMode(10, OUTPUT);
pinMode(9, OUTPUT);
pinMode(8, OUTPUT);
pinMode(7, OUTPUT);
pinMode(6, OUTPUT);
Serial.begin(9600);
}
void loop() {
// read the value from the sensor:
sensorValue = analogRead(sensorPin);
Serial.println(sensorValue);
// turn the ledPin on
digitalWrite(6, HIGH);
delay(sensorValue);
digitalWrite(7, HIGH);
delay(sensorValue);
digitalWrite(8, HIGH);
delay(sensorValue);
digitalWrite(9, HIGH);
delay(sensorValue);
digitalWrite(10,HIGH);
delay(sensorValue);
digitalWrite(11, HIGH);
delay(sensorValue);
digitalWrite(12,HIGH);
delay(sensorValue);
digitalWrite(13, HIGH);
delay(sensorValue);
digitalWrite(6, LOW);
delay(sensorValue);
digitalWrite(7, LOW);
delay(sensorValue);
digitalWrite(8, LOW);
delay(sensorValue);
digitalWrite(9, LOW);
delay(sensorValue);
digitalWrite(10, LOW);
delay(sensorValue);
digitalWrite(11, LOW);
delay(sensorValue);
digitalWrite(12, LOW);
delay(sensorValue);
digitalWrite(13, LOW);
delay(sensorValue);
digitalWrite(13, HIGH);
digitalWrite(12, HIGH);
digitalWrite(11, HIGH);
digitalWrite(10, HIGH);
delay(sensorValue);
digitalWrite(9, HIGH);
digitalWrite(8, HIGH);
digitalWrite(7, HIGH);
digitalWrite(6, HIGH);
delay(sensorValue);
digitalWrite(6, HIGH);
digitalWrite(7, HIGH);
digitalWrite(8, HIGH);
digitalWrite(9, HIGH);
delay(sensorValue);
digitalWrite(10, HIGH);
digitalWrite(11, HIGH);
digitalWrite(12, HIGH);
digitalWrite(13, HIGH);
delay(sensorValue);
// stop the program for <sensorValue> milliseconds:
delay(sensorValue);
// turn the ledPin off:
digitalWrite(13, LOW);
delay(sensorValue);
digitalWrite(12, LOW);
delay(sensorValue);
digitalWrite(11, LOW);
delay(sensorValue);
digitalWrite(10, LOW);
delay(sensorValue);
digitalWrite(9, LOW);
delay(sensorValue);
digitalWrite(8, LOW);
delay(sensorValue);
digitalWrite(7, LOW);
delay(sensorValue);
digitalWrite(6, LOW);
delay(sensorValue);
}
沒有留言:
張貼留言