Código:
Emisor:
#include <VirtualWire.h>
//Emisor LED'S
int Bot1 = 8;
int Bot2 = 9;
int Bot3 = 10;
int Bot4 = 11;
int Bot5 = 12;
int pinTX = 4;//Pin designado
para la transmision de datos
void setup(){
pinMode (Bot1,INPUT); //Declaracion de los pines como entrada
pinMode (Bot2,INPUT); //los cuales corresponden a los botones
pinMode (Bot3,INPUT);
pinMode (Bot4,INPUT);
pinMode (Bot5,INPUT);
vw_set_tx_pin(pinTX);
vw_setup(2000);
Serial.begin(9600);
}//setup
void loop(){
delay(500);
int EB1 = digitalRead(Bot1);
int EB2 = digitalRead(Bot2);
int EB3 = digitalRead(Bot3);
int EB4 = digitalRead(Bot4);
int EB5 = digitalRead(Bot5);
char *mensaje = "VACIO";
if (EB1== HIGH)
{
mensaje = "1";
}
if (EB2== HIGH)
{
mensaje = "2";
}
if (EB3== HIGH)
{
mensaje = "3";
}
if (EB4== HIGH)
{
mensaje = "4";
}
if (EB5== HIGH)
{
mensaje = "5";
}
Serial.print("Enviado ");
Serial.println( mensaje );
vw_send( (uint8_t *) mensaje , strlen(mensaje) );
}
Receptor:
#include <VirtualWire.h>
//RECEPTOR
int LED1 = 6;
int LED2 = 7;
int LED3 = 8;
int LED4 = 9;
int LED5 = 10;
int LED6 = 11;
int LED7 = 12;
int pinRX = 4;
void setup(){
pinMode(LED1,OUTPUT);
pinMode(LED2,OUTPUT);
pinMode(LED3,OUTPUT);
pinMode(LED4,OUTPUT);
pinMode(LED5,OUTPUT);
pinMode(LED6,OUTPUT);
pinMode(LED7,OUTPUT);
Serial.begin(9600);
vw_set_rx_pin(pinRX);
vw_setup(2000);
vw_rx_start();
}
void loop(){
uint8_t mensaje[VW_MAX_MESSAGE_LEN];
uint8_t longitud = VW_MAX_MESSAGE_LEN;
if (vw_get_message( mensaje , &longitud ) ){
Serial.print("Recibido ");
Serial.println( mensaje[0] );
if( mensaje[0] == '1' ){
Boton1();
}
else if( mensaje[0] == '2' ){
Boton2();
}
else if( mensaje[0] == '3' ){
Boton3();
}
else if( mensaje[0] == '4' ){
Boton4();
}
else if( mensaje[0] == '5' ){
Boton5();
}
}
}
void
Boton1(){
digitalWrite(LED1, HIGH);
digitalWrite(LED2, HIGH);
digitalWrite(LED3, HIGH);
digitalWrite(LED4, HIGH);
digitalWrite(LED5, HIGH);
digitalWrite(LED6, HIGH);
digitalWrite(LED7, HIGH);
delay(800);
digitalWrite(LED1, LOW);
digitalWrite(LED2, LOW);
digitalWrite(LED3, LOW);
digitalWrite(LED4, LOW);
digitalWrite(LED5, LOW);
digitalWrite(LED6, LOW);
digitalWrite(LED7, LOW);
delay(800);
}
void Boton2(){
digitalWrite(LED1, HIGH);
digitalWrite(LED2, LOW);
digitalWrite(LED3, HIGH);
digitalWrite(LED4, LOW);
digitalWrite(LED5, HIGH);
digitalWrite(LED6, LOW);
digitalWrite(LED7, HIGH);
delay(500);
digitalWrite(LED1, LOW);
digitalWrite(LED2, HIGH);
digitalWrite(LED3, LOW);
digitalWrite(LED4, HIGH);
digitalWrite(LED5, LOW);
digitalWrite(LED6, HIGH);
digitalWrite(LED7, LOW);
delay(500);
digitalWrite(LED1, LOW);
digitalWrite(LED2, LOW);
digitalWrite(LED3, LOW);
digitalWrite(LED4, LOW);
digitalWrite(LED5, LOW);
digitalWrite(LED6, LOW);
digitalWrite(LED7, LOW);
delay(500);
}
void Boton3(){
digitalWrite(LED7, HIGH);
digitalWrite(LED2, LOW);
digitalWrite(LED3, LOW);
digitalWrite(LED4, LOW);
digitalWrite(LED5, LOW);
digitalWrite(LED6, LOW);
digitalWrite(LED1, LOW);
delay(500);
digitalWrite(LED6, HIGH);
digitalWrite(LED2, LOW);
digitalWrite(LED3, LOW);
digitalWrite(LED4, LOW);
digitalWrite(LED5, LOW);
digitalWrite(LED1, LOW);
digitalWrite(LED7, LOW);
delay(500);
digitalWrite(LED5, HIGH);
digitalWrite(LED2, LOW);
digitalWrite(LED3, LOW);
digitalWrite(LED4, LOW);
digitalWrite(LED1, LOW);
digitalWrite(LED6, LOW);
digitalWrite(LED7, LOW);
delay(500);
digitalWrite(LED4, HIGH);
digitalWrite(LED2, LOW);
digitalWrite(LED3, LOW);
digitalWrite(LED1, LOW);
digitalWrite(LED5, LOW);
digitalWrite(LED6, LOW);
digitalWrite(LED7, LOW);
delay(500);
digitalWrite(LED3, HIGH);
digitalWrite(LED2, LOW);
digitalWrite(LED1, LOW);
digitalWrite(LED4, LOW);
digitalWrite(LED5, LOW);
digitalWrite(LED6, LOW);
digitalWrite(LED7, LOW);
delay(500);
digitalWrite(LED2, HIGH);
digitalWrite(LED1, LOW);
digitalWrite(LED3, LOW);
digitalWrite(LED4, LOW);
digitalWrite(LED5, LOW);
digitalWrite(LED6, LOW);
digitalWrite(LED7, LOW);
delay(500);
digitalWrite(LED1, HIGH);
digitalWrite(LED2, LOW);
digitalWrite(LED3, LOW);
digitalWrite(LED4, LOW);
digitalWrite(LED5, LOW);
digitalWrite(LED6, LOW);
digitalWrite(LED7, LOW);
delay(500);
}
void Boton4(){
digitalWrite(LED1, HIGH);
digitalWrite(LED2, LOW);
digitalWrite(LED3, LOW);
digitalWrite(LED4, LOW);
digitalWrite(LED5, LOW);
digitalWrite(LED6, LOW);
digitalWrite(LED7, LOW);
delay(500);
digitalWrite(LED2, HIGH);
digitalWrite(LED1, LOW);
digitalWrite(LED3, LOW);
digitalWrite(LED4, LOW);
digitalWrite(LED5, LOW);
digitalWrite(LED6, LOW);
digitalWrite(LED7, LOW);
delay(500);
digitalWrite(LED3, HIGH);
digitalWrite(LED2, LOW);
digitalWrite(LED1, LOW);
digitalWrite(LED4, LOW);
digitalWrite(LED5, LOW);
digitalWrite(LED6, LOW);
digitalWrite(LED7, LOW);
delay(500);
digitalWrite(LED4, HIGH);
digitalWrite(LED2, LOW);
digitalWrite(LED3, LOW);
digitalWrite(LED1, LOW);
digitalWrite(LED5, LOW);
digitalWrite(LED6, LOW);
digitalWrite(LED7, LOW);
delay(500);
digitalWrite(LED5, HIGH);
digitalWrite(LED2, LOW);
digitalWrite(LED3, LOW);
digitalWrite(LED4, LOW);
digitalWrite(LED1, LOW);
digitalWrite(LED6, LOW);
digitalWrite(LED7, LOW);
delay(500);
digitalWrite(LED6, HIGH);
digitalWrite(LED2, LOW);
digitalWrite(LED3, LOW);
digitalWrite(LED4, LOW);
digitalWrite(LED5, LOW);
digitalWrite(LED1, LOW);
digitalWrite(LED7, LOW);
delay(500);
digitalWrite(LED7, HIGH);
digitalWrite(LED2, LOW);
digitalWrite(LED3, LOW);
digitalWrite(LED4, LOW);
digitalWrite(LED5, LOW);
digitalWrite(LED6, LOW);
digitalWrite(LED1, LOW);
delay(500);
}
void Boton5(){
//Primer LED encendido
digitalWrite(LED1, HIGH);
digitalWrite(LED2, LOW);
digitalWrite(LED3, LOW);
digitalWrite(LED4, LOW);
digitalWrite(LED5, LOW);
digitalWrite(LED6, LOW);
digitalWrite(LED7, LOW);
delay(500);
//Segundo LED encendido
digitalWrite(LED1, LOW);
digitalWrite(LED2, HIGH);
digitalWrite(LED3, LOW);
digitalWrite(LED4, LOW);
digitalWrite(LED5, LOW);
digitalWrite(LED6, LOW);
digitalWrite(LED7, LOW);
delay(500);
//Tercer LED encendido
digitalWrite(LED1, LOW);
digitalWrite(LED2, LOW);
digitalWrite(LED3, HIGH);
digitalWrite(LED4, LOW);
digitalWrite(LED5, LOW);
digitalWrite(LED6, LOW);
digitalWrite(LED7, LOW);
delay(500);
//Cuarto LED encedido
digitalWrite(LED1, LOW);
digitalWrite(LED2, LOW);
digitalWrite(LED3, LOW);
digitalWrite(LED4, HIGH);
digitalWrite(LED5, LOW);
digitalWrite(LED6, LOW);
digitalWrite(LED7, LOW);
delay(500);
//Quinto LED encedido
digitalWrite(LED1, LOW);
digitalWrite(LED2, LOW);
digitalWrite(LED3, LOW);
digitalWrite(LED4, LOW);
digitalWrite(LED5, HIGH);
digitalWrite(LED6, LOW);
digitalWrite(LED7, LOW);
delay(500);
//Sexto LED encendido
digitalWrite(LED1, LOW);
digitalWrite(LED2, LOW);
digitalWrite(LED3, LOW);
digitalWrite(LED4, LOW);
digitalWrite(LED5, LOW);
digitalWrite(LED6, HIGH);
digitalWrite(LED7, LOW);
delay(500);
//Septimo LED encendido
digitalWrite(LED1, LOW);
digitalWrite(LED2, LOW);
digitalWrite(LED3, LOW);
digitalWrite(LED4, LOW);
digitalWrite(LED5, LOW);
digitalWrite(LED6, LOW);
digitalWrite(LED7, HIGH);
delay(500);
digitalWrite(LED6, HIGH);
digitalWrite(LED7, HIGH);
delay(500);
digitalWrite(LED5, HIGH);
digitalWrite(LED6, HIGH);
digitalWrite(LED7, HIGH);
delay(500);
digitalWrite(LED4, HIGH);
digitalWrite(LED5, HIGH);
digitalWrite(LED6, HIGH);
digitalWrite(LED7, HIGH);
delay(500);
digitalWrite(LED3, HIGH);
digitalWrite(LED4, HIGH);
digitalWrite(LED5, HIGH);
digitalWrite(LED6, HIGH);
digitalWrite(LED7, HIGH);
delay(500);
digitalWrite(LED2, HIGH);
digitalWrite(LED3, HIGH);
digitalWrite(LED4, HIGH);
digitalWrite(LED5, HIGH);
digitalWrite(LED6, HIGH);
digitalWrite(LED7, HIGH);
delay(500);
digitalWrite(LED1, HIGH);
digitalWrite(LED2,
HIGH);
digitalWrite(LED3, HIGH);
digitalWrite(LED4, HIGH);
digitalWrite(LED5, HIGH);
digitalWrite(LED6, HIGH);
digitalWrite(LED7, HIGH);
delay(500);
}
Evidencias Fotográficas:
Emisor:
Receptor:
No hay comentarios:
Publicar un comentario