Skip to content

Instantly share code, notes, and snippets.

@arduinoboard
Created March 22, 2012 18:44
Show Gist options
  • Save arduinoboard/2161569 to your computer and use it in GitHub Desktop.
Save arduinoboard/2161569 to your computer and use it in GitHub Desktop.
The file that is currently on an Arduino Uno with a serial number of 64935343333351504212
// redpark cable example for Rsc_Demo that comes with redpark cable
// written by: Jimmy Chion | IDEO | 2012
//
// hardware:
// redpark cable (19-pin iOS connector to RS-232 Serial) http://www.redpark.com/c2db9.html
// RS232 shifter (to UART): http://www.sparkfun.com/products/449
// Note: Don't forget that TX->RX and RX->TX
//
#define MAX_CHAR_TO_RX 30
#define TERMINATING_CHAR 10
char bufferArray[MAX_CHAR_TO_RX];
//-- initialization
//------------------------------------------------------------------
void setup() {
Serial.begin(9600); //increase the baud rate if possible
}
//-- the loop
//------------------------------------------------------------------
void loop() {
if(Serial.available() > 0) { //-- if there's something to read (num of bytes in buffer > 0)
int incomingBytes = Serial.readBytesUntil(TERMINATING_CHAR, bufferArray, MAX_CHAR_TO_RX); //-- read it
//-- do something with that message
//-- in this example, I'm going to send it back to the iOS device in all caps
String msg = String(bufferArray); //-- convert it to a String obj
msg.toUpperCase(); //-- convert to upper case
msg.trim(); //-- take out all the trailing whitespace
if(msg.equalsIgnoreCase("hi")) { //--example of reacting
Serial.println("Hello World!");
}
Serial.print("in CAPS: "); // -- use Serial.write() if you want to write bytes instead
Serial.println(msg);
flushBuffer(); //-- flush it
}
}
//-- flush out the buffers
//------------------------------------------------------------------
void flushBuffer() {
Serial.flush(); //-- flush the outgoing buffer
for (int i = 0; i < MAX_CHAR_TO_RX; i++) { //-- flush the buffer array
bufferArray[i] = NULL;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment