Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void setup() {
- Serial.begin(115200);
- pinMode(13, OUTPUT);
- }
- String command;
- void loop() {
- if (Serial.available()) {
- char c = Serial.read();
- if (c == '\n') {
- parseCommand(command);
- command = "";
- }
- else {
- command += c;
- }
- }
- }
- void parseCommand(String com) {
- String part1;
- String part2;
- //PINON 13
- part1 = com.substring(0, com.indexOf(" "));
- part2 = com.substring(com.indexOf(" ") + 1);
- if (part1.equalsIgnoreCase("pinon")) {
- int pin = part2.toInt();
- digitalWrite(pin, HIGH);
- } else if (part1.equalsIgnoreCase("pinoff")) {
- int pin = part2.toInt();
- digitalWrite(pin, LOW);
- } else {
- Serial.println("Command Not Found");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement