/* * * barbot led display * www.nycresistor.com * */ #include #include #define rxPin 2 #define txPin 3 #define ledPin 13 // set up a new serial port SoftwareSerial mySerial = SoftwareSerial(rxPin, txPin); byte pinState = 0; // prototypes int readcom(unsigned char *commandin); int execom(unsigned char *commandin); // initiate serial classes void setup() { // define pin modes for tx, rx, led pins: pinMode(rxPin, INPUT); pinMode(txPin, OUTPUT); pinMode(ledPin, OUTPUT); // set the data rate for the SoftwareSerial port mySerial.begin(9600); } // begin loop void loop() { // listen for new serial coming in: unsigned char commandin[8]; char someChar = mySerial.read(); // if we detect a command on the bus if (someChar == '+') { readcom(commandin); execom(commandin); } } // read command and handle it int readcom(unsigned char *commandin) { char incom; char ack = '='; // read in the full command while(incom != '-') { incom = mySerial.read(); commandin += incom; } // let the ledpin know we're communicating tap(13); // let bus know we got the command mySerial.print(ack); return 0; } int execom(unsigned char *commandin) { char pinStyle; char pinNumin; // Parse the command if ((commandin[0] = 'L') && (commandin[1] = 'E') && (commandin[2] = 'D')) { pinNumin = commandin[4]; pinStyle = commandin[5]; } // Handle Strobe Call if (pinStyle = 'S') { } // Handle High Call if (pinStyle = 'H') { } // Handle Low Call if (pinStyle = 'L') { } return 0; } void tap(int pinNum) { // set the LED pin using the pinState variable: digitalWrite(pinNum, pinState); // if pinState = 0, set it to 1, and vice versa: pinState = !pinState; }