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