Last active
December 20, 2015 00:59
-
-
Save mondaini/6045817 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int channel_pin[] = {2, 4}; | |
static int relayStateA = 0; | |
static int relayStateB = 0; | |
void setup() { | |
// initialize serial communication: | |
Serial.begin(9600); | |
for (int i = 0; i < sizeof(channel_pin); ++i) | |
{ | |
pinMode(channel_pin[i], OUTPUT); | |
} | |
} | |
void loop() { | |
if (Serial.available() > 0) { | |
char inByte = Serial.read(); | |
switch (inByte){ | |
case 'a': | |
{ | |
relayStateA ^= 1; | |
Serial.println(inByte); | |
break; | |
} | |
case 'b': | |
{ | |
relayStateB ^= 1; | |
Serial.println(inByte); | |
break; | |
} | |
default: | |
{ | |
Serial.println("Caractere 'a' para Relay 1 / Caractere 'b' para Relay 2"); | |
} | |
} | |
if (relayStateA){ | |
digitalWrite(channel_pin[0], HIGH); | |
} | |
else{ | |
digitalWrite(channel_pin[0], LOW); | |
} | |
if (relayStateB){ | |
digitalWrite(channel_pin[1], HIGH); | |
} | |
else{ | |
digitalWrite(channel_pin[1], LOW); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment