]> git.piffa.net Git - sketchbook_andrea/blob - serial/analog_tx_1/analog_tx_1.ino
1f148fb4f8a3841fb1b641184a93a5144be6e766
[sketchbook_andrea] / serial / analog_tx_1 / analog_tx_1.ino
1 /*
2   Analog 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  Schema: http://lab.piffa.net/schemi/analog_io_bb.png
11  */
12
13 // Prima scheda: input
14 int led = 13;  // Debug
15 int input = 2;  // Questa e' la scheda con un input
16 int TX = 3 ; // Pin di trasmissione
17
18 void setup() {                
19   // initialize the digital pin as an output.
20   pinMode(led, OUTPUT);       // Il PIN e' attivato come output per DEBUG
21   pinMode(TX, OUTPUT);       // Il PIN e' attivato come output
22   pinMode(input, INPUT_PULLUP);        // Il PIN e' attivato come output
23 }
24
25 // the loop routine runs over and over again forever:
26 void loop() {
27   if (digitalRead(input) == LOW) { // Verifica se il PIN input e' +5v
28     digitalWrite(led, HIGH); // Debug
29     digitalWrite(TX, HIGH);
30     delay(50);
31   } 
32   else { // Alterativa: se non e' +5v
33     digitalWrite(led, LOW);
34     digitalWrite(TX, LOW);
35     delay(50);
36   }
37 }
38
39
40
41