add setMode and primitive status led

This commit is contained in:
Shannon Sterz 2016-01-20 16:46:11 +01:00
parent 98fb2293e0
commit 060da910cd

View file

@ -1,16 +1,12 @@
#include <RCSwitch.h>
RCSwitch mySwitch = RCSwitch();
uint8_t message[8];
int index = 0;
boolean com = false;
boolean on = false;
void setup()
{
Serial.begin(9600);
mySwitch.enableTransmit(11);
}
void loop()
@ -28,29 +24,33 @@ void loop()
}
void decodeMessage() {
if(com) {
int cmd = message[0];
int pin = message[1] - 97;
int pin = (message[1] - 97 < 0 || message[1] - 97 > 19)? -1 : message[1] - 97 < 0;
if(com) {
uint8_t val[6];
memcpy(val, message + 2, 6);
switch (cmd) {
//case 80: break;
//case 81: break;
case 81: setMode(val[0], pin); break;
//case 82: break;
//case 83: break;
//case 84: break;
//case 85: break;
//case 86: break;
case 87: switchLight(val); break;
case 87: sendRCTristate(val, pin); break;
//case 88: break;
//case 89: break;
default: break;
}
} else if(message[0] == 90) {
} else if(cmd] == 90) {
com = true;
setMode(0, pin);
digitalWrite(pin, HIGH);
Serial.println("Ready!");
} else {
@ -60,9 +60,25 @@ void decodeMessage() {
}
}
void switchLight(uint8_t val[]) {
void setMode(uint8_t val, int pin) {
if(pin == -1) { if(debug) Serial.println("badpin"); return; }
if (val == 0) {
pinMode(pin, OUTPUT);
} else {
pinMode(pin, INPUT);
}
}
void sendRCTristate (uint8_t val[], int pin) {
if(pin == -1) { if(debug) Serial.println("badpin"); return; }
String triStateCode = "";
RCSwitch rc = RCSwitch();
mySwitch.enableTransmit(pin);
for(int i = 0; i < 6; i++)
{