Skip to content

Instantly share code, notes, and snippets.

@Siroyan
Created March 28, 2020 13:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Siroyan/f7826a1c51414de94ef8bf1ac9e85c86 to your computer and use it in GitHub Desktop.
Save Siroyan/f7826a1c51414de94ef8bf1ac9e85c86 to your computer and use it in GitHub Desktop.
#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