Skip to content

Instantly share code, notes, and snippets.

@mondaini
Last active December 20, 2015 00:59
Show Gist options
  • Save mondaini/6045817 to your computer and use it in GitHub Desktop.
Save mondaini/6045817 to your computer and use it in GitHub Desktop.
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