63 lines
1.1 KiB
C++
63 lines
1.1 KiB
C++
#define RED 4
|
|
#define GREEN 3
|
|
#define BLUE 2
|
|
|
|
String comand;
|
|
byte wait;
|
|
int jober;
|
|
int looper;
|
|
int IDarg = 0;
|
|
String ParsedCommand[20];
|
|
|
|
void setup() {
|
|
Serial.begin(9600);
|
|
pinMode(RED, OUTPUT);
|
|
pinMode(GREEN, OUTPUT);
|
|
pinMode(BLUE, OUTPUT);
|
|
}
|
|
|
|
char getCharCommand(){
|
|
if (Serial.available() > 0) {
|
|
char cmdraw = Serial.read();
|
|
if (cmdraw > 0) return cmdraw;
|
|
}
|
|
|
|
}
|
|
|
|
void proc(String* com) {
|
|
if(com == "RGBLR") {
|
|
Serial.println("Введите 1 или 2");
|
|
wait = 1;
|
|
jober = 1;
|
|
}
|
|
}
|
|
|
|
void job() {
|
|
if (Serial.available()>0) {
|
|
char prom = Serial.read();
|
|
if (jober == 1) {
|
|
if (prom == 1) {
|
|
digitalWrite(RED, HIGH);
|
|
} else {
|
|
digitalWrite(RED, LOW);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
void loop() {
|
|
if (wait == 1) { job; }
|
|
while (looper<100) {
|
|
char CharCommand = getCharCommand();
|
|
if (CharCommand != "?") {
|
|
Serial.print(CharCommand);
|
|
ParsedCommand[IDarg] += CharCommand;
|
|
Serial.println(" ");
|
|
proc(ParsedCommand);
|
|
IDarg = 0;
|
|
for (int i = 0;i<=20;i++) {ParsedCommand[i]="";}
|
|
looper++;
|
|
}
|
|
}
|
|
}
|