Skip to content

Commit

Permalink
add some arduino system code
Browse files Browse the repository at this point in the history
  • Loading branch information
cbott committed Jan 21, 2017
1 parent c310014 commit c205834
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 0 deletions.
20 changes: 20 additions & 0 deletions CarArduino/CarArduino.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const int SIZE = 10;
const char TERM = 255;

byte x[SIZE];
void setup() {
Serial1.begin(9600);
for(int i=0; i<SIZE; ++i){
x[i] = i;
}
}

void loop() {
for(int i=0; i<SIZE; ++i){
Serial1.write(x[i]);
}
Serial1.write(TERM);
++x[1];
if(x[1] == 255) ++x[1];
delay(200);
}
27 changes: 27 additions & 0 deletions CarTransmitter/CarTransmitter.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//CarTransmitter.ino
const int SIZE = 10;
const char TERM = 255;

void setup() {
Serial.begin(9600); // start serial for output
Serial1.begin(9600);
}

byte x[SIZE];
void loop() {
while(Serial1.available() <= SIZE){ delay(1); }
byte buf[SIZE];
byte chars_read = Serial1.readBytesUntil(TERM, buf, SIZE);

if(chars_read == SIZE){
// Successful read. Copy temporary buffer in to data array
Serial.print("\nReceived:");
for(int i=0; i<SIZE; ++i){
x[i] = buf[i];
Serial.print(x[i], DEC);
Serial.print(" ");
}
}
}


File renamed without changes.

0 comments on commit c205834

Please sign in to comment.