Created
January 27, 2013 16:25
-
-
Save anonymous/4649085 to your computer and use it in GitHub Desktop.
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
/* | |
* Serial Port Monitor | |
* | |
* | |
*/ | |
//Setup Output | |
int ledPin_3 = 13; | |
//Setup message bytes | |
byte inputByte_0; | |
byte inputByte_1; | |
byte inputByte_2; | |
byte inputByte_3; | |
byte inputByte_4; | |
//Setup | |
void setup() { | |
pinMode(ledPin_3, OUTPUT); | |
Serial.begin(9600); | |
digitalWrite(ledPin_3, HIGH);// | |
delay(250);// | |
digitalWrite(ledPin_3, LOW);// | |
delay(250);// | |
} | |
//Main Loop | |
void loop() { | |
//Read Buffer | |
if (Serial.available() == 5) | |
{ | |
//Read buffer | |
inputByte_0 = Serial.read(); | |
delay(100); | |
inputByte_1 = Serial.read(); | |
delay(100); | |
inputByte_2 = Serial.read(); | |
delay(100); | |
inputByte_3 = Serial.read(); | |
delay(100); | |
inputByte_4 = Serial.read(); | |
} | |
//Check for start of Message | |
if(inputByte_0 == 16) | |
{ | |
//Detect Command type | |
switch (inputByte_1) | |
{ | |
case 127: | |
//Set PIN and value | |
switch (inputByte_2) | |
{ | |
case 4: | |
if(inputByte_3 == 255) | |
{ | |
digitalWrite(ledPin_3, HIGH); | |
break; | |
} | |
else | |
{ | |
digitalWrite(ledPin_3, LOW); | |
break; | |
} | |
break; | |
} | |
break; | |
case 128: | |
//Say hello | |
Serial.print("HELLO FROM ARDUINO"); | |
break; | |
} | |
//Clear Message bytes | |
inputByte_0 = 0; | |
inputByte_1 = 0; | |
inputByte_2 = 0; | |
inputByte_3 = 0; | |
inputByte_4 = 0; | |
//Let the PC know we are ready for more data | |
Serial.print("-READY TO RECEIVE"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment