Last active
December 21, 2015 19:59
-
-
Save treeherder/6358375 to your computer and use it in GitHub Desktop.
serial buffer device for arduino
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <SoftwareSerial.h> | |
SoftwareSerial serial_device(7, 8); | |
unsigned char buff[512]; /* buffer */ | |
int index=0; | |
void setup() | |
{ | |
serial_device.begin(19200); /* baud rate */ | |
Serial.begin(19200); /* works better when they match*/ | |
} | |
void loop() | |
{ | |
if (serial_device.available()) /* wait for data */ | |
{ | |
while(serial_device.available()) | |
{ | |
buff[index++]=serial_device.read(); /* writing data into buff*/ | |
if(index == 64)break; | |
} | |
Serial.write(buff,index); /*tx*/ | |
clr_buff_arr(); /*zero buffer array and index*/ | |
index = 0; | |
} | |
if (Serial.available()) /*wait*/ | |
serial_device.write(Serial.read()); /* rx*/ | |
} | |
void clr_buff_arr() | |
{ | |
for (int i=0; i<index;i++) | |
{ buff[i]=NULL;} /* clear each index */ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment