]> git.piffa.net Git - sketchbook_andrea/blob - libraries/common/common.cpp
94657ae6cf967b6404fb5ce9f460299757ad0832
[sketchbook_andrea] / libraries / common / common.cpp
1 /*  Common
2  *
3  *  Oggetti di uso comune
4  */
5
6 #include "Arduino.h"
7 #include "common.h"
8
9
10 //////////////////////
11 // RGB LED
12 // Common anode
13
14 RGBLed::RGBLed(byte pinR, byte pinG, byte pinB) {
15       redPin    = pinR ;
16       greenPin  = pinG ;
17       bluePin   = pinB ;
18
19       // Equvalente del Setup() per inizializzare i PIN
20       pinMode(redPin, OUTPUT);
21       pinMode(greenPin, OUTPUT);
22       pinMode(greenPin, OUTPUT);
23 };
24
25 void RGBLed::Red () {
26 // Accende il LED di rosso
27       analogWrite(redPin,   0);
28       analogWrite(greenPin, 255);
29       analogWrite(bluePin,  255);
30     };
31
32 void RGBLed::Green () {
33 // Accende il LED di verde
34       analogWrite(redPin,   255);
35       analogWrite(greenPin, 0);
36       analogWrite(bluePin,  255);
37     };
38
39 void RGBLed::Blue () {
40 // Accende il LED di blu
41       analogWrite(redPin,   255);
42       analogWrite(greenPin, 255);
43       analogWrite(bluePin,  0);
44     };
45
46 void RGBLed::Magenta () {
47 // Accende il LED di magenta
48       analogWrite(redPin,   0);
49       analogWrite(greenPin, 255);
50       analogWrite(bluePin,  0);
51     };
52
53 void RGBLed::Cyano () {
54 // Accende il LED di Cyano
55       analogWrite(redPin,   255);
56       analogWrite(greenPin, 0);
57       analogWrite(bluePin,  0);
58     };
59
60 void RGBLed::Yellow () {
61 // Accende il LED di giallo
62       analogWrite(redPin,   0);
63       analogWrite(greenPin, 0);
64       analogWrite(bluePin,  255);
65     };
66
67 void RGBLed::White () {
68 // Accende il LED 
69       analogWrite(redPin,   0);
70       analogWrite(greenPin, 0);
71       analogWrite(bluePin,  0);
72     };
73
74 void RGBLed::Off () {
75 // Spegne il LED 
76       analogWrite(redPin,   255);
77       analogWrite(greenPin, 255);
78       analogWrite(bluePin,  255);
79     };
80
81 void RGBLed::SetColor (byte r, byte g, byte b) {
82       // Imposta il colore di un LED RGB
83
84       analogWrite(redPin,   r);
85       analogWrite(greenPin, g);
86       analogWrite(bluePin,  b);
87     };
88
89
90 //////////////////
91 // Funzioni
92
93 void brilla(byte pin) {
94   // Accende e spegne il LED senza un argomento 
95   // per impostare la velocita'.
96   const int velocita = 500;
97
98 pinMode(pin, OUTPUT); 
99   // sequenze di istruzione: accendere e spegnere il LED
100   digitalWrite(pin, HIGH);   // turn the LED on (HIGH is the voltage level)
101   delay(velocita);               // wait for a second
102   digitalWrite(pin, LOW);    // turn the LED off by making the voltage LOW
103   delay(velocita);               // wait for a second
104 };
105
106 void brilla(byte pin, int velocita) {
107   // Accende e spegne il LED accetando un argomento 
108   // per impostare la velocita'.
109
110 pinMode(pin, OUTPUT); 
111   // sequenze di istruzione: accendere e spegnere il LED
112   digitalWrite(pin, HIGH);   // turn the LED on (HIGH is the voltage level)
113   delay(velocita);               // wait for a second
114   digitalWrite(pin, LOW);    // turn the LED off by making the voltage LOW
115   delay(velocita);               // wait for a second
116 };