UNIX

Arduino Serial Console (ASCII)

Dec 15th, 2011
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.55 KB | None | 0 0
  1. int ledPin = 13;
  2.  
  3. void setup(){
  4.     //Startup serial at 9600 BAUD
  5.   Serial.begin(9600);
  6.     //Set pin 13 to OUTPUT
  7.   pinMode(ledPin, OUTPUT);
  8. }
  9.  
  10. void loop(){
  11.     /* Read and report data from serial, while the serial console
  12.      * is available, and set the LED on.
  13.      *
  14.      * If the serial console is not available, set the LED low and
  15.      * wait for more input.
  16.      */
  17.   while(Serial.available() > 0){
  18.     Serial.write(Serial.read());
  19.     digitalWrite(ledPin, HIGH);
  20.   } if(Serial.available() == 0){
  21.     digitalWrite(ledPin, LOW);
  22.   }
  23. }
Advertisement
Add Comment
Please, Sign In to add comment