Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- RECEPTOR
- Apaga el LED 13 si recibe el mensaje "Apagar"
- Enciende el LED 13 si recibe el mensaje "Encender"
- */
- #include <VirtualWire.h>
- //Creamos un mensaje
- //La constante VW_MAX_MESSAGE_LEN viene definida en la libreria
- byte message[VW_MAX_MESSAGE_LEN];
- byte messageLength = VW_MAX_MESSAGE_LEN;
- void setup()
- {
- pinMode(13, OUTPUT); //Configuramos el pin 13
- Serial.begin(9600);//Iniciamos el Serial
- Serial.println("Iniciando...");
- vw_setup(2000);
- vw_rx_start();
- }
- void loop()
- {
- if (vw_get_message(message, &messageLength))
- {
- if(comparar("Encender") == 0){
- digitalWrite(13, HIGH);
- Serial.write("LED Encendido\n");
- }
- else if(comparar("Apagar") == 0)
- {
- digitalWrite(13,LOW);
- Serial.write("LED Apagado\n");
- }
- }
- }
- char comparar(char* cadena) {
- //Esta funcion compara el string cadena con el mensaje recibido.
- //Si son iguales, devuelve 1. Si no, devuelve 0.
- for(int i = 0; i<messageLength; i++)
- {
- if(message[i] != cadena[i])
- {
- return 1;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement