Skip to content

Instantly share code, notes, and snippets.

@hunandy14
Created January 27, 2016 05:48
Show Gist options
  • Save hunandy14/5123ae3d5a0c730d5fcb to your computer and use it in GitHub Desktop.
Save hunandy14/5123ae3d5a0c730d5fcb to your computer and use it in GitHub Desktop.
#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