Initial commit

master
Emil Miler 5 years ago committed by Lukáš Hozda
commit 46674af3fe

@ -0,0 +1,40 @@
#include <RH_ASK.h>
#include <SPI.h>
#include <stdint.h>
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);
}
}

@ -0,0 +1,32 @@
#include <RH_ASK.h>
#include <SPI.h>
#include <stdint.h>
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);
}