Last active
August 29, 2015 14:22
-
-
Save alkalinecoffee/08cc93516b150ff6bf70 to your computer and use it in GitHub Desktop.
arduino rf read
This file contains hidden or 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
//bool DEBUG = true; | |
bool DEBUG = false; | |
int chans[] = {9, 10, 11, 12}; | |
int relays[] = {5, 6, 7, 8}; | |
int relay; | |
int chan; | |
int chan_status; | |
int relay_status; | |
int power; | |
int debug = 8; | |
void setup() { | |
for (int i = 0; i <= 3; i++) { | |
pinMode(chans[i], INPUT); | |
pinMode(relays[i], OUTPUT); | |
digitalWrite(relays[i], LOW); | |
} | |
pinMode(debug, INPUT); | |
Serial.begin(9600); | |
} | |
void loop() { | |
// for (int i = 0; i <= 3; i++) { | |
for (int i = 0; i < 1; i++) { | |
relay = relays[i]; | |
chan = chans[i]; | |
chan_status = digitalRead(chan); | |
relay_status = digitalRead(relay); | |
power = analogRead(debug); | |
log("Chan" + String(chan) + ": " + String(chan_status) + " (PWM " + String(power) + ")"); | |
if (chan_status == HIGH && relay_status == LOW) { | |
log("Turning on relay" + String(relay)); | |
digitalWrite(relay, HIGH); | |
} else if (chan_status == LOW && relay_status == HIGH) { | |
log("Turning off relay" + String(relay)); | |
digitalWrite(relay, LOW); | |
} | |
} | |
log("-----------"); | |
delay(400); | |
} | |
void log(String msg) { | |
if (DEBUG == false) { return; } | |
Serial.println(msg); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment