Created
January 27, 2016 05:48
-
-
Save hunandy14/5123ae3d5a0c730d5fcb to your computer and use it in GitHub Desktop.
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 BTTX 2 | |
#define BTRX 3 | |
#define Led 13 | |
byte serialA; | |
SoftwareSerial I2CBT(BTTX,BTRX); | |
void CtrlLED(char str[128]); | |
/*================================================*/ | |
void setup(){ | |
Serial.begin(9600); | |
I2CBT.begin(38400); | |
Serial.println("Welcom"); | |
I2CBT.println("Welcom"); | |
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("I2CGet:"); | |
Serial.println(str); | |
I2CBT.print("I2CGet:"); | |
I2CBT.println(str); | |
CtrlLED(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("ScanSerialGet:"); | |
Serial.println(str); | |
I2CBT.print("ScanSerialGet:"); | |
I2CBT.println(str); | |
CtrlLED(str); | |
} | |
} | |
void CtrlLED(char str[128]){ | |
if(strcmp(str,"1") == 0){ | |
Serial.print("LED 13 is ON"); | |
digitalWrite(Led, HIGH); | |
} | |
if(strcmp(str,"0") == 0){ | |
Serial.print("LED 13 is OFF"); | |
digitalWrite(Led, LOW); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment