/* TITULO: Comunicación serie entre dos Arduinos - Emisor_serie_TX
DESCRIPCIÓN DEL PROGRAMA
EL programa envía una cadena de caracteres
"LED1ON_" al presionar el interruptor on o
"LED1OFF_" al presionar el interruptor Off,
por el puerto serie por defaul.
ESQUEMA DE CONEXION
+-----+
+----[PWR]-------------------| USB |--+
| +-----+ |
| GND/RST2 [ ][ ] |
| MOSI2/SCK2 [ ][ ] A5/SCL[ ] |
| 5V/MISO2 [ ][ ] A4/SDA[ ] |
| AREF[ ] |
| GND[ ] |
| [ ]N/C SCK/13[ ] |
| [ ]IOREF MISO/12[ ] |
| [ ]RST MOSI/11[ ]~|
| [ ]3V3 +---+ 10[ ]~|
| [ ]5v -| A |- 9[ ]~| Push Off
| [ ]GND -| R |- 8[ ] | Push On
| [ ]GND -| D |- |
| [ ]Vin -| U |- 7[ ] |
| -| I |- 6[ ]~|
| [ ]A0 -| N |- 5[ ]~|
| [ ]A1 -| O |- 4[ ] |
| [ ]A2 +---+ INT1/3[ ]~|
| [ ]A3 INT0/2[ ] |
| [ ]A4/SDA RST SCK MISO TX>1[ ] | Pin RX del "Arduino Receptor"
| [ ]A5/SCL [ ] [ ] [ ] RX<0[ ] |
| [ ] [ ] [ ] |
| UNO_R3 GND MOSI 5V ____________/
\_______________________/
NOTAS:
- Las masas de los dos Arduinos tienen que estar unidas entre sí.
- La libreria GFButton.h nos ayuda a aliminar el ruido de rebote
al presinar el interruptor pulsador (push)
*/
#include <GFButton.h>
int pinBotonON = 8;
int pinBotonOFF = 9;
GFButton boton1(pinBotonON);
GFButton boton2(pinBotonOFF);
void setup() {
pinMode(pinBotonON, INPUT);
pinMode(pinBotonOFF, INPUT);
boton1.setPressHandler(botonON_pulsado);
boton2.setPressHandler(botonOFF_pulsado);
Serial.begin(9600);
}
void loop() {
boton1.process();
boton2.process();
}
void botonON_pulsado(GFButton & btn){
Serial.print("LED1ON_");
}
void botonOFF_pulsado(GFButton & btn){
Serial.print("LED1OFF_");
}