Reduce block size to 8b

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

@ -16,25 +16,16 @@ void setup()
void loop() void loop()
{ {
uint8_t buf[4]; uint8_t buf[2];
size_t buf_len = sizeof(buf); // rip
if (driver.recv(buf, &4)){ if (driver.recv(buf, &buf_len)){
int buffer = atoi((char*)buf); uint8_t value = buf[1];
int channel = buffer%10; uint8_t ch = [buf]2;
int value = buffer/10;
switch(channel){ // 0 -> 3; 1 -> 5; 2 -> 6
case 0: ch = (ch ? ++ch + 3 : 3);
channel = 3;
break;
case 1:
channel = 5;
break;
case 2:
channel = 6;
break;
}
analogWrite(channel, value); analogWrite(ch, value);
} }
} }

@ -4,7 +4,7 @@
RH_ASK driver(2000); RH_ASK driver(2000);
int lastval[] = {0,0,0}; uint8_t lastval[] = {0,0,0};
void setup() void setup()
{ {
@ -14,17 +14,17 @@ void setup()
void loop() void loop()
{ {
for(uint8_t i = 0; i < 3; i++) {
for(int i=0; i < 3; i++){ uint8_t val = (uint8_t)analogRead(i)/4;
int val = analogRead(i)/4;
if(val >= lastval[i]+3 || val <= lastval[i]-3){ if(val >= lastval[i]+3 || val <= lastval[i]-3){
char msg[4]; uint8_t msg[2] = { val, i };
lastval[i] = val;
sprintf(msg, "%d%d", val, i);
Serial.println(msg); Serial.println(msg);
driver.send((uint8_t *)msg, 4); driver.send((uint8_t *)msg, 2);
driver.waitPacketSent(); driver.waitPacketSent();
lastval[i] = val;
} }
} }