Created
October 5, 2011 19:40
-
-
Save taboularasa/1265448 to your computer and use it in GitHub Desktop.
Flatland Arduino serial test
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
void toggleLed(); | |
String inString = ""; | |
boolean keepReading = false; | |
const int ledPin = 13; | |
const int irTarget = 2; | |
int ledState = LOW; | |
unsigned long previousMillis = 0; | |
long interval = 0; | |
const int player = 'A'; | |
void setup() | |
{ | |
Serial1.begin(9600); | |
Serial.begin(9600); | |
pinMode(ledPin, OUTPUT); | |
pinMode(irTarget, OUTPUT); | |
} | |
void loop() | |
{ | |
// digitalWrite(13, 0); | |
digitalWrite(ledPin, HIGH); | |
digitalWrite(irTarget, HIGH); | |
while(Serial1.available()) | |
{ | |
int inChar = Serial1.read(); | |
if(inChar == player){ | |
keepReading = true; | |
Serial.println("found dollar"); | |
} | |
if (isDigit(inChar) && keepReading == true) { | |
// convert the incoming byte to a char | |
// and add it to the string: | |
inString += (char)inChar; | |
Serial.println("found digit while keepReading was true"); | |
} | |
if(inChar == '\n'){ | |
interval = inString.toInt(); | |
Serial.println(interval); | |
digitalWrite(ledPin, LOW); | |
digitalWrite(irTarget, LOW); | |
delay(interval); | |
inString = ""; | |
keepReading = false; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment