Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Added serial data parsing o arduino code

  • Loading branch information...
commit 1a654ade775042df1b2dfb47e0ec70c3344d4bff 1 parent 0c3055a
Johan Bichel Lindegaard mrbichel authored

Showing 1 changed file with 33 additions and 4 deletions. Show diff stats Hide diff stats

  1. +33 4 arduino/chaos_flowcontrol/chaos_flowcontrol.ino
37 arduino/chaos_flowcontrol/chaos_flowcontrol.ino
@@ -41,9 +41,13 @@ void setup() {
41 41 airRegulatorPins[2] = 3;
42 42 }
43 43
  44 +char inData[80];
  45 +char parsedData[80];
  46 +byte index = 0;
  47 +
44 48 void loop() {
45 49
46   - // send data only when you receive data:
  50 + // send data only when yoSu receive data:
47 51 if (!Serial.available()) {
48 52 // no data
49 53 if (state == 2) {
@@ -65,12 +69,37 @@ void loop() {
65 69 // say what you got:
66 70 Serial.print("I received: ");
67 71 Serial.println(incomingByte, DEC);
  72 +
  73 + while(Serial.available() > 0) {
  74 + char aChar = Serial.read();
  75 + if(aChar == '\n') {
  76 + // End of record detected. Time to parse
  77 +
  78 + char *p = inData; //assign the string to *p
  79 + char *str; //intialize str
  80 + int counter = 0; //initialise the counter
  81 +
  82 + // data format is channel number int; air pressure float 0-1, water pressure float 0-1, air open bool, water open bool,
  83 + while ((str = strtok_r(p, ";", &p)) != "\0") // delimiter is the comma. NULL is the terminator
  84 + {
  85 + parsedData[counter] = *str; //use the counter as an index to add each value to the array
  86 + counter++; //increment the counter
  87 +
  88 + p = NULL;
  89 + }
  90 +
  91 + index = 0;
  92 + inData[index] = NULL;
  93 + } else {
  94 + inData[index] = aChar;
  95 + index++;
  96 + inData[index] = '\0'; // Keep the string NULL terminated
  97 + }
  98 + }
68 99 }
69 100
70 101 if (state=0) {
71   -
72   - //auto control here
73   -
  102 + //auto control here
74 103 }
75 104
76 105 }

0 comments on commit 1a654ad

Please sign in to comment.
Something went wrong with that request. Please try again.