30 likes | 233 Views
arduino 程式 範例. setup() 範例. void setup() { // start serial port at 9600 bps: Serial.begin (9600); pinMode (2, OUTPUT ); // LED is on pin 2 }. Loop() 範例. void loop() { // if we get a valid byte, read analog ins: if ( Serial.available () > 0) { // get incoming byte:
E N D
setup() 範例 • void setup() • { • // start serial port at 9600 bps: • Serial.begin(9600); • pinMode(2, OUTPUT); // LED is on pin 2 • }
Loop() 範例 • void loop() • { • // if we get a valid byte, read analog ins: • if (Serial.available() > 0) { • // get incoming byte: • inByte = Serial.read(); • // read ina byte range 0-255: • if (inByte==‘1’) • digitalWrite(2, HIGH); // set the LED on • if (inByte==‘0’) • digitalWrite(2, LOW); // set the LED on} • } • }