]> git.piffa.net Git - sketchbook_andrea/blob - serial/serial_2_comm_rx_2_led/serial_2_comm_rx_2_led.ino
Serial and eeprom
[sketchbook_andrea] / serial / serial_2_comm_rx_2_led / serial_2_comm_rx_2_led.ino
1 /*
2   Serial comm: RX due output
3  
4  Comunicazione seriale tra due schede arduino.
5  La prima scheda ha due botton1 come input e 
6  comunica con un altra scheda che monta due LED come output.
7  Il led della seconda si accende quando rileva
8  la pressione del bottone della prima.
9  
10  La RX deve distinguere l'input ricevuto.
11  */
12
13 // Seconda scheda: output
14 // PIN 0 = RX
15 int led = 13; // Questa scheda ha spolo l'output
16 int red = 12; // Questa scheda ha spolo l'output
17 int incomingByte ;
18 // the setup routine runs once when you press reset:
19 void setup() {                
20   // initialize the digital pin as an output.
21   pinMode(led, OUTPUT);       // Il PIN e' attivato come output
22   pinMode(red, OUTPUT);       // Il PIN e' attivato come output
23   Serial.begin(9600); // Attiviamo la seriale
24 }
25
26 // the loop routine runs over and over again forever:
27 void loop() {
28   if (Serial.available() > 0) {
29     // read the incoming byte:
30     incomingByte = Serial.read();
31     
32     if (incomingByte == 2) { // Verifica se il PIN input e' +5v
33       digitalWrite(led, HIGH);
34       delay(50);
35       digitalWrite(led, LOW);
36     } 
37     else if (incomingByte == 3) { // Alterativa: se non e' +5v
38       digitalWrite(red, HIGH);
39       delay(50);
40       digitalWrite(red, LOW);
41     }
42   }
43 }
44
45
46