Skip to content

Instantly share code, notes, and snippets.

@electronut
Created April 24, 2014 15:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save electronut/11259325 to your computer and use it in GitHub Desktop.
Save electronut/11259325 to your computer and use it in GitHub Desktop.
read serial port and turn leds on/off
// ardu_alert.ino
//
// read serial port and turn leds on/off
//
// Mahesh Venkitachalam
// electronut.in
#include "Arduino.h"
// LED pin numbers (digital)
int pinRed = 4;
int pinGreen = 2;
void setup()
{
// initialize serial comms
Serial.begin(9600);
// set pins
pinMode(pinRed, OUTPUT);
pinMode(pinGreen, OUTPUT);
}
void loop()
{
while(Serial.available() > 0) {
int c = Serial.read();
if (c == '1') {
digitalWrite(pinRed, LOW);
digitalWrite(pinGreen, HIGH);
}
else if (c == '0') {
digitalWrite(pinRed, HIGH);
digitalWrite(pinGreen, LOW);
}
else {
digitalWrite(pinRed, LOW);
digitalWrite(pinGreen, LOW);
}
}
// wait
delay(100);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment