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()
{
uint8_t buf[4];
uint8_t buf[2];
size_t buf_len = sizeof(buf); // rip
if (driver.recv(buf, &4)){
int buffer = atoi((char*)buf);
int channel = buffer%10;
int value = buffer/10;
if (driver.recv(buf, &buf_len)){
uint8_t value = buf[1];
uint8_t ch = [buf]2;
switch(channel){
case 0:
channel = 3;
break;
case 1:
channel = 5;
break;
case 2:
channel = 6;
break;
}
// 0 -> 3; 1 -> 5; 2 -> 6
ch = (ch ? ++ch + 3 : 3);
analogWrite(channel, value);
analogWrite(ch, value);
}
}

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