Skip to content

Instantly share code, notes, and snippets.

@xively-gists
Created May 13, 2013 16:08
Show Gist options
  • Save xively-gists/5569462 to your computer and use it in GitHub Desktop.
Save xively-gists/5569462 to your computer and use it in GitHub Desktop.
#include <SoftwareSerial.h>
#include <Wire.h>
#include <Adafruit_MCP23017.h>
#include <Adafruit_RGBLCDShield.h>
//lcd setup
Adafruit_RGBLCDShield lcd = Adafruit_RGBLCDShield();
#define BLUE 0x4
#define VIOLET 0x5
#define WHITE 0x7
SoftwareSerial impSerial(9, 10); // RX on 9, TX on 10
char inData[100];
char inChar=-1;
byte index = 0;
String input = "";
String vals[3];
boolean newdata = false;
void setup()
{
// Open the hardware serial port
Serial.begin(19200);
impSerial.begin(19200);
//lcd
lcd.begin(16, 2);
lcd.setBacklight(WHITE);
lcd.setCursor(0, 0);
}
void loop(){
while (impSerial.available() > 0){
inChar = impSerial.read(); // Read a character
inData[index] = inChar; // Store it
index++; // Increment where to write next
inData[index] = '\0'; // Null terminate the string
newdata = true;
}
index = 0;
if(newdata){
int i = 0;
int valdex = 0;
while(inData[i] != '\0') {
if(inData[i] == ','){
vals[valdex] = input;
valdex ++;
input = "";
//i = 0;
}else input.concat(inData[i]);
i++;
}
Serial.println(vals[0]);
Serial.println(vals[1]);
Serial.println(vals[2]);
Serial.println(vals[3]);
String output = "blah";
//printlcd(output);
newdata = false;
input = "";
valdex = 0;
}
}
void printlcd(String preraw){
//check for multiple
int theEnd = preraw.indexOf("F#");
String raw = preraw.substring(0,theEnd + 1);
//chop up
int oneEnd = raw.indexOf("\n");
String lineOne = raw.substring(0,oneEnd);
String lineTwo = raw.substring(oneEnd + 1);
lcd.clear();
lcd.setCursor(0,0);
lcd.print(lineOne);
lcd.setCursor(0,1);
lcd.print(lineTwo);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment