hi,
i've been trying controlling wireless 3 pwm led with 3 potentio using rf link kit 433mhz
and still not succes yet.
TX code:
#include <VirtualWire.h>
int pot1 = A1;
int pot2 = A2;
int pot3 = A3;
int sen1 = 0;
int sen2 = 0;
int sen3 = 0;
void setup(){
Serial.begin(9600);
vw_set_ptt_inverted(true); // Required for RX Link Module
vw_setup(2000); // Bits per sec
}
void loop(){
sen1 = analogRead(pot1);
sen2 = analogRead(pot2);
sen3 = analogRead(pot3);
char fade1msg[4];
itoa(sen1,fade1msg,10);
char fade2msg[4];
itoa(sen2,fade2msg,10);
char fade3msg[4];
itoa(sen3,fade3msg,10);
vw_send((uint8_t *)fade1msg, strlen(fade1msg));
vw_send((uint8_t *)fade2msg, strlen(fade2msg));
vw_send((uint8_t *)fade3msg, strlen(fade3msg));
vw_wait_tx();
}
RX code:
#include <VirtualWire.h>
int led1 = 3;
int led2 = 5;
int led3 = 6;
int hitung=0,hasil[3];
int fade1;
char fade1msg[4];
void setup() {
Serial.begin(9600);
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(led3, OUTPUT);
vw_setup(2000);
vw_rx_start();
}
void loop(){
uint8_t buf[VW_MAX_MESSAGE_LEN];
uint8_t buflen = VW_MAX_MESSAGE_LEN;
if (vw_get_message(buf, &buflen))
{
int i;
for (i = 0; i < buflen; i++)
{
fade1msg = char(buf*);*
}
fade1msg[buflen] = '\0';
fade1 = atoi(fade1msg);
hasil[hitung]=fade1;
hitung++;
if(hitung > 2){
analogWrite(led1,hasil[0]);
analogWrite(led2,hasil[1]);
analogWrite(led3,hasil[2]);
vw_wait_rx();
hitung=0; // reset counter
}
}
}
can anybody help me?
thanks