影片一 自動發光
影片二手動發光
自動發光程式碼
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);
digitalWrite(13, HIGH);
delay(200);
digitalWrite(12, HIGH);
delay(200);
digitalWrite(11, HIGH);
delay(200);
digitalWrite(10, HIGH);
delay(200);
digitalWrite(9, HIGH);
delay(200);
digitalWrite(8, HIGH);
delay(200);
digitalWrite(7, HIGH);
delay(200);
digitalWrite(13, LOW);
delay(200);
digitalWrite(12, LOW);
delay(200);
digitalWrite(11, LOW);
delay(200);
digitalWrite(10, LOW);
delay(200);
digitalWrite(9, LOW);
delay(200);
digitalWrite(8, LOW);
delay(200);
digitalWrite(7, LOW);
delay(200);
delay(50);
}
手動發光程式碼
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);
if(sensorValue>=0) digitalWrite(13, HIGH);
if(sensorValue>100 ) digitalWrite(12, HIGH);
if(sensorValue<100) digitalWrite(12, LOW);
if(sensorValue>200) digitalWrite(11, HIGH);
if(sensorValue<200) digitalWrite(11, LOW);
if(sensorValue>300) digitalWrite(10, HIGH);
if(sensorValue<300) digitalWrite(10, LOW);
if(sensorValue>400) digitalWrite(9, HIGH);
if(sensorValue<400) digitalWrite(9, LOW);
if(sensorValue>500) digitalWrite(8, HIGH);
if(sensorValue<500) digitalWrite(8, LOW);
if(sensorValue>600) digitalWrite(7, HIGH);
if(sensorValue<600) digitalWrite(7, LOW);
delay(50);
}
課堂心得
今天上課內容很好玩,因為接電路板用arduion執行出結果,
LED燈可以發光,我們首先試著條件判斷,讓LED燈用手動
方式亮。再來,我們用delay指令,讓LED燈自動的發光,
好妙唷!!
沒有留言:
張貼留言