Arduino 板
首先,來[寫]一個簡單的arduino程式:
可以利用 delay() 調整不同頻率。
再來看一個[改寫版]:
現在,實際接上一個LED:
再使用[開關]控制 LED是否要亮起來:
- void setup(){
- // declare the LED pins as outputs
- pinMode(3,OUTPUT);
- // declare the switch pin as an input
- pinMode(2,INPUT);
- }
- void loop(){
- // read the value of the switch
- // digitalRead() checks to see if there is voltage
- // on the pin or not
- switchstate = digitalRead(2);
- // if the button is not pressed
- // blink the red LEDs
- if (switchstate == LOW) {
- digitalWrite(3, LOW); // turn the green LED on pin 3 off
- }
- // this else is part of the above if() statement.
- // if the switch is not LOW (the button is pressed)
- // the code below will run
- else {
- digitalWrite(3, HIGH); // turn the red LED on pin 5 on
- // wait for a quarter second before changing the light
- delay(250);
- }
- }
沒有留言:
張貼留言