commit 46674af3fe69e861e826c73f684d66e4476bd7cc Author: Emil Miler Date: Fri Jan 3 16:40:58 2020 +0100 Initial commit diff --git a/src/rx.ino b/src/rx.ino new file mode 100644 index 0000000..75424b7 --- /dev/null +++ b/src/rx.ino @@ -0,0 +1,40 @@ +#include +#include +#include + +RH_ASK driver(2000); + +void setup() +{ + Serial.begin(9600); + if (!driver.init()) Serial.println("init failed"); + + pinMode(3, OUTPUT); + pinMode(5, OUTPUT); + pinMode(6, OUTPUT); +} + +void loop() +{ + uint8_t buf[4]; + + if (driver.recv(buf, &4)){ + int buffer = atoi((char*)buf); + int channel = buffer%10; + int value = buffer/10; + + switch(channel){ + case 0: + channel = 3; + break; + case 1: + channel = 5; + break; + case 2: + channel = 6; + break; + } + + analogWrite(channel, value); + } +} diff --git a/src/tx.ino b/src/tx.ino new file mode 100644 index 0000000..299aae4 --- /dev/null +++ b/src/tx.ino @@ -0,0 +1,32 @@ +#include +#include +#include + +RH_ASK driver(2000); + +int lastval[] = {0,0,0}; + +void setup() +{ + Serial.begin(9600); + if (!driver.init()) Serial.println("init failed"); +} + +void loop() +{ + + for(int i=0; i < 3; i++){ + int val = analogRead(i)/4; + + if(val >= lastval[i]+3 || val <= lastval[i]-3){ + char msg[4]; + lastval[i] = val; + sprintf(msg, "%d%d", val, i); + Serial.println(msg); + driver.send((uint8_t *)msg, 4); + driver.waitPacketSent(); + } + } + + delay(8); +}