使用Serial Port透過Arduino Uno來控制LED的開關的作業。
Listing. Code
/** * Serial Library: Read 2 - Control LED */ int incomingByte = 0; const int ledPin = 13; void setup() { pinMode( ledPin, OUTPUT ); Serial.begin( 9600 ); Serial.println( "'L' turn on, 'l' turn off" ); } void loop() { if( Serial.available() > 0 ) { incomingByte = Serial.read(); // input 'L' if( incomingByte == 76 ) { Serial.println( "LED on!!" ); digitalWrite( ledPin, HIGH ); } // inpit 'l' if( incomingByte == 108 ) { Serial.println( "LED off!!" ); digitalWrite( ledPin, LOW ); } } }