Created
March 28, 2020 13:49
-
-
Save Siroyan/f7826a1c51414de94ef8bf1ac9e85c86 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 <Arduino.h> | |
#include <SoftwareSerial.h> | |
#define LEDPIN 5 | |
SoftwareSerial imbleSerial(2, 3); | |
void setup() { | |
Serial.begin(115200); | |
pinMode(LEDPIN, OUTPUT); | |
imbleSerial.begin(19200); | |
} | |
void loop() { | |
while(imbleSerial.available()){ | |
String receivedData = imbleSerial.readString(); | |
int indexOfColon = receivedData.indexOf(':'); | |
if(indexOfColon){ | |
/* コマンドを受信 */ | |
String receivedCommand = receivedData.substring(indexOfColon + 1, indexOfColon + 3); | |
switch (receivedCommand.toInt()){ | |
case 1: | |
digitalWrite(LEDPIN, HIGH); | |
break; | |
case 2: | |
digitalWrite(LEDPIN, LOW); | |
break; | |
default: | |
break; | |
} | |
Serial.println(receivedCommand); | |
}else{ | |
Serial.println("err invalid message"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment