Skip to content

Instantly share code, notes, and snippets.

@okhiroyuki
Last active January 11, 2020 08:28
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 okhiroyuki/a9aa4660f1ccabdad11f0277c38c0a30 to your computer and use it in GitHub Desktop.
Save okhiroyuki/a9aa4660f1ccabdad11f0277c38c0a30 to your computer and use it in GitHub Desktop.
redmobile serial node sample
#define LED 13
void setup() {
Serial.begin(9600);
pinMode(LED, OUTPUT);
}
void loop() {
if (Serial.available() > 0) {
uint8_t i = (uint8_t)Serial.read();
if(i == 0x41){
digitalWrite(LED, LOW);
}else if(i == 0x42){
digitalWrite(LED, HIGH);
}
Serial.println(i);
}
}
#define POT A0
#define LED 13
unsigned long previousMillis;
int interval = 50;
void setup() {
Serial.begin(9600);
pinMode(POT, INPUT);
pinMode(LED, OUTPUT);
}
void loop() {
if (Serial.available() > 0) {
char i = Serial.read();
switch (i) {
case '0':
digitalWrite(LED, LOW);
break;
case '1':
digitalWrite(LED, HIGH);
break;
}
}
if (millis() - previousMillis >= interval) {
previousMillis = millis();
int value = analogRead(POT);
Serial.println(value);
}
}
[
{
"id": "30fba80b.e79768",
"type": "serial-open",
"z": "c933e99f.c2c4c8",
"name": "",
"baudRate": "9600",
"dataBits": "8",
"stopBits": "1",
"parity": "odd",
"dtr": false,
"rts": false,
"x": 510,
"y": 160,
"wires": [
[
"803c897b.231d98"
]
]
},
{
"id": "f654d49.4930d28",
"type": "serial-close",
"z": "c933e99f.c2c4c8",
"name": "",
"x": 510,
"y": 260,
"wires": [
[
"803c897b.231d98"
]
]
},
{
"id": "1f77f242.b2999e",
"type": "serial-write",
"z": "c933e99f.c2c4c8",
"name": "",
"data": "0",
"x": 510,
"y": 360,
"wires": [
[
"803c897b.231d98"
]
]
},
{
"id": "b8b70b51.92c198",
"type": "serial-read",
"z": "c933e99f.c2c4c8",
"name": "",
"x": 510,
"y": 540,
"wires": [
[
"803c897b.231d98"
]
]
},
{
"id": "eda48894.daa008",
"type": "inject",
"z": "c933e99f.c2c4c8",
"name": "",
"topic": "",
"payload": "",
"payloadType": "date",
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"x": 220,
"y": 160,
"wires": [
[
"30fba80b.e79768"
]
]
},
{
"id": "8e23fbb6.d28188",
"type": "inject",
"z": "c933e99f.c2c4c8",
"name": "",
"topic": "",
"payload": "",
"payloadType": "date",
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"x": 220,
"y": 260,
"wires": [
[
"f654d49.4930d28"
]
]
},
{
"id": "ac35fd9f.b948b",
"type": "inject",
"z": "c933e99f.c2c4c8",
"name": "",
"topic": "",
"payload": "",
"payloadType": "date",
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"x": 220,
"y": 360,
"wires": [
[
"1f77f242.b2999e"
]
]
},
{
"id": "803c897b.231d98",
"type": "debug",
"z": "c933e99f.c2c4c8",
"name": "",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "false",
"x": 830,
"y": 380,
"wires": []
},
{
"id": "bc94495c.238b58",
"type": "serial-write",
"z": "c933e99f.c2c4c8",
"name": "",
"data": "",
"x": 510,
"y": 460,
"wires": [
[
"803c897b.231d98"
]
]
},
{
"id": "a70ba337.9fef3",
"type": "inject",
"z": "c933e99f.c2c4c8",
"name": "",
"topic": "",
"payload": "{\"payload\":\"1\"}",
"payloadType": "json",
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"x": 220,
"y": 440,
"wires": [
[
"bc94495c.238b58"
]
]
}
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment