簡介
工作坊
因為現場變數太大,排四種選項。
教學內容:
材料 50 份
準備工具
備註
週三下午兩點去場勘
當天決定其中一種方案
程式碼
blink.ino
int led 13;
void setup()
{
pinMode(led, OUTPUT); //set digital pin 13 as OUTPUT
}
void loop()
{
digitalWrite(led, HIGH); //digital pin 13 = HIGH
delay(500); //delay 500 mini seconds
digitalWrite(led, LOW);
delay(500);
}
光敏電阻
---------------------------------------------------------------------------------------------------------------------------
int photocellPin = 2; // 光敏電阻 (photocell) 接在 anallog pin 2
int photocellVal = 0; // photocell variable
int ledPin = 13;
void blinkLED(){
//function body
digitalWrite(ledPin, HIGH);
delay(3000);
digitalWrite(ledPin, LOW);
delay(3000);
}
void setup() {
Serial.begin(9600);
}
void loop() {
// 讀取光敏電阻並輸出到 Serial Port
photocellVal = analogRead(photocellPin);
if ( photocellVal < 300 )
{
blinkLED();
}
Serial.println(photocellVal);
delay(100);
}