4 Comunicazione I2C tra due schede Arduino.
5 La scheda master ha un bottone come input e
6 comunica con altre schede che monta un LED come output.
7 Il led della seconda si accende quando rileva
8 la pressione del bottone della prima.
10 Questo script implementa il debounce con Millis(),
16 int input = 2; // Questa e' la scheda con un input
17 int statoAttuale; // variable for reading the pin status
18 int ultimoStato; // variable to hold the last button state
19 long ultimoCambio = 0; // Momento in cui e' stato attivato il PIN input
20 long debounceDelay = 100; // Tempo di debounce
22 // the setup routine runs once when you press reset:
24 // initialize the digital pin as an output.
25 pinMode(led, OUTPUT); // Il PIN e' attivato come output
26 pinMode(input, INPUT_PULLUP); // Il PIN e' attivato come output
28 // Serial.begin(9600); // Attiviamo la seriale per debug
29 Wire.begin(); // join i2c bus (address optional for master)
34 statoAttuale = digitalRead(input); // Legge lo stato del bottone
36 if (statoAttuale == LOW && statoAttuale != ultimoStato && millis() - ultimoCambio > debounceDelay ) {
38 Wire.beginTransmission(2); // Invia il messaggio al device slave con id 2
40 Wire.endTransmission(); // stop transmitting
43 ultimoCambio = millis() ; // Registra il tempo attuale
45 ultimoStato = statoAttuale; // save the new state in our variable
50 1. Implementare piu' bottoni per controllare piu' schede
51 2. Implementare un messaggio di feedback dallo slave al master per uk cambio di stato del led
65 1. Vedere i links proposti: .write scrive un byte mentre
66 .print manda un codice ASCII
68 3. No, dato solo il cavo dalla TX alla RX .
69 Provare a fare un script con comunicazione bilaterale
70 4. No perche' non ci sarebbe sincronia tra i segnali,
71 vedere gli esercizi su I2C