/*ElectroCrea.com
Transmisor Arduino
----------------------------
VCC 5V
GND GND
OUT 12
*/
#include <VirtualWire.h>//Incluimos esta librería
char *controller;
int state = 0;
int flag = 0;
////////////////////////////////////////////////////////////////////VOID SETUP
void setup() {
vw_set_ptt_inverted(true);
vw_set_tx_pin(12);//Pin de Arduino
vw_setup(4000);//Velocidad de la transmisión de datos
Serial.begin(9600);
}
////////////////////////////////////////////////////////////////////VOID LOOP
void loop(){
if(Serial.available() > 0){
state = Serial.read();
flag=0;
}
////////////////////////////ACCION 1
if (state == '1') {//Escribimos 1 en monitor serial
controller= "1" ;//Se envía 1
vw_send((uint8_t *)controller, strlen(controller));
vw_wait_tx(); //Espera a que se envie el mensaje completo
if(flag==0){//Flag evita que el texto se repita infinitamente
Serial.println("LED: Encendido");
flag=1;
}
}
////////////////////////////ACCION 2
else if (state == '2') {//Escribimos 2 en monitor serial
controller= "2" ;
vw_send((uint8_t *)controller, strlen(controller));
vw_wait_tx();
if(flag==0){
Serial.println("LED: Apagado");
flag=1;
}
}
////////////////////////////ACCION 3
else if (state == '3') {//Escribimos 3 en monitor serial
controller= "3" ;
vw_send((uint8_t *)controller, strlen(controller));
vw_wait_tx();
if(flag==0){
Serial.println("LED: Parpadeando");
flag=1;
}
}
}
//Mas información en ElectroCrea.com