]> git.piffa.net Git - sketchbook_andrea/blob - serial/serial_2_comm_tx_2_input/serial_2_comm_tx_2_input.ino
aa43a760e00d939a7bb0dee504fdc436fbfdc85b
[sketchbook_andrea] / serial / serial_2_comm_tx_2_input / serial_2_comm_tx_2_input.ino
1 /*
2   Serial comm: TX due bottoni
3  
4  Comunicazione seriale tra due schede arduino.
5  La prima scheda ha due bottoni 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 TX deve mandare due segnali diversi.
11  */
12
13 // Prima scheda: input
14 // PIN 1 = TX
15 int led = 13;
16 int input = 2;  // Questa e' la scheda con un input
17 int inputRed = 3;  // Questa e' la scheda con un input
18
19 // the setup routine runs once when you press reset:
20 void setup() {                
21   // initialize the digital pin as an output.
22   pinMode(led, OUTPUT);       // Il PIN e' attivato come output
23   pinMode(input, INPUT);        // Il PIN e' attivato come output
24   
25   Serial.begin(9600); // Attiviamo la seriale
26 }
27
28 // the loop routine runs over and over again forever:
29 void loop() {
30   if (digitalRead(input) == HIGH) { // Verifica se il PIN input e' +5v
31     digitalWrite(led, HIGH);
32     Serial.write(2);
33     delay(50);
34   } 
35   if (digitalRead(inputRed) == HIGH) { // Verifica se il PIN input e' +5v
36     digitalWrite(led, HIGH); 
37     Serial.write(3);
38     delay(50);
39   } 
40   digitalWrite(led, LOW);
41 }
42
43
44