/* Serial In and Timer Combo * ------------ * by Jeff Gray * * Serial switching LED and a Timer Switching LED */ //Pins int serLED = 13; // LED connected to pin 13h int timeLED = 9; int serbyte; int timer = 0; void setup() { pinMode(serLED, OUTPUT); // pin 13 as Serial h status pinMode(timeLED, OUTPUT); // pin 9 as timer blink beginSerial(9600); // initialize serial port } void loop() { timer = millis(); // timer variable set to millis() function if (serialAvailable() ){ // If serial communication is active... serbyte = serialRead(); // read in the serial byte and set it to this variable } printInteger(timer); // send out our timer serially serialWrite(10); // carraige return and line break serialWrite(13); if(serbyte == 'h') // if receive an 'h' { digitalWrite(serLED, HIGH); // turn ON the LED } else { digitalWrite(serLED, LOW); // if not turn it OFF } if((timer / 1000) % 2 == 1) { // if timer is on an odd second, turn on, even turn off digitalWrite(timeLED, HIGH); // turn ON the LED } else { digitalWrite(timeLED, LOW); // if not turn it OFF } }