Created
April 24, 2014 15:42
-
-
Save electronut/11259325 to your computer and use it in GitHub Desktop.
read serial port and turn leds on/off
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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