Last active
April 8, 2016 03:17
-
-
Save hunandy14/0982c0845ade23b8374f to your computer and use it in GitHub Desktop.
RaspberryPi
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> | |
#include <Wire.h> | |
#define UartRX 2 | |
#define UartTX 3 | |
#define Led 13 | |
SoftwareSerial I2CBT(UartRX ,UartTX ); | |
void CtrlLED(char str[128]); | |
/*================================================*/ | |
void setup(){ | |
Serial.begin(9600); | |
I2CBT.begin(38400); | |
Serial.println("Welcom Uart CTRL"); | |
I2CBT.println("Welcom Uart CTRL"); | |
pinMode(Led, OUTPUT); | |
} | |
/*================================================*/ | |
void loop(){ | |
ScanI2cStr(); | |
ScanSerialStr(); | |
} | |
/*================================================*/ | |
void ScanI2cStr(){ | |
if(I2CBT.available()) { | |
int strnum=0; | |
char str[128]=""; | |
memset( str, 0, strlen(str) ); | |
while (I2CBT.available() > 0){ | |
str[strnum++] = I2CBT.read(); | |
delay(3); | |
} | |
Serial.print("UartReturn:"); | |
Serial.println(str); | |
// I2CBT.print("I2CGet:"); | |
// I2CBT.println(str); | |
} | |
} | |
void ScanSerialStr(){ | |
if(Serial.available()) { | |
int strnum=0; | |
char str[128]=""; | |
memset( str, 0, strlen(str) ); | |
while (Serial.available() > 0){ | |
str[strnum++] = Serial.read(); | |
delay(3); | |
} | |
Serial.print("ScanSerialSend:"); | |
Serial.println(str); | |
// I2CBT.print("ScanSerialSend:"); | |
I2CBT.println(str); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment