Skip to content

Instantly share code, notes, and snippets.

@neosarchizo
Created October 30, 2019 13:03
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 neosarchizo/d3433ae549a0ef54e8e871b5f6b9e3e2 to your computer and use it in GitHub Desktop.
Save neosarchizo/d3433ae549a0ef54e8e871b5f6b9e3e2 to your computer and use it in GitHub Desktop.
[디바이스마트] RS485 테스트
#include <SoftwareSerial.h>
#define R 9
#define G 10
#define B 11
SoftwareSerial mySerial(2, 3);
int pState = HIGH;
byte id = 0;
void setup() {
mySerial.begin(9600);
pinMode(R, OUTPUT);
pinMode(G, OUTPUT);
pinMode(B, OUTPUT);
digitalWrite(R, LOW);
digitalWrite(G, LOW);
digitalWrite(B, LOW);
pinMode(8, INPUT_PULLUP);
}
void loop() {
int state = digitalRead(8);
if (pState == HIGH && state == LOW) {
mySerial.write(id);
digitalWrite(R, LOW);
digitalWrite(G, LOW);
digitalWrite(B, LOW);
switch (id) {
case 0:
digitalWrite(R, HIGH);
break;
case 1:
digitalWrite(G, HIGH);
break;
case 2:
digitalWrite(B, HIGH);
break;
default:
break;
}
}
pState = state;
int d;
while (mySerial.available()) {
d = mySerial.read();
digitalWrite(R, LOW);
digitalWrite(G, LOW);
digitalWrite(B, LOW);
switch (d) {
case 0:
digitalWrite(R, HIGH);
break;
case 1:
digitalWrite(G, HIGH);
break;
case 2:
digitalWrite(B, HIGH);
break;
default:
break;
}
}
delay(10);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment