]> git.piffa.net Git - sketchbook_andrea/commitdiff
Common library (semaphore not yet committed)
authoreaman <andrea@piffa.net>
Tue, 18 Oct 2016 00:28:00 +0000 (02:28 +0200)
committereaman <andrea@piffa.net>
Tue, 18 Oct 2016 00:28:00 +0000 (02:28 +0200)
RGB_LED/rgb_5_struct/rgb_5_struct.ino
libraries/common/common.cpp [new file with mode: 0644]
libraries/common/common.h [new file with mode: 0644]
libraries/common/examples/loader/loader.ino [new file with mode: 0644]
libraries/common/keywords.txt [new file with mode: 0644]

index 03e8f7abdb37f7c290d331c47acaf34a0b6d42a4..fa8ef10c561a68c4802029971a35f8a73eee2a08 100644 (file)
@@ -78,4 +78,3 @@ void loop()
   analogWrite(led.blue,led.b);
 }
 */
- */
diff --git a/libraries/common/common.cpp b/libraries/common/common.cpp
new file mode 100644 (file)
index 0000000..94657ae
--- /dev/null
@@ -0,0 +1,116 @@
+/*  Common
+ *
+ *  Oggetti di uso comune
+ */
+
+#include "Arduino.h"
+#include "common.h"
+
+
+//////////////////////
+// RGB LED
+// Common anode
+
+RGBLed::RGBLed(byte pinR, byte pinG, byte pinB) {
+      redPin    = pinR ;
+      greenPin  = pinG ;
+      bluePin   = pinB ;
+
+      // Equvalente del Setup() per inizializzare i PIN
+      pinMode(redPin, OUTPUT);
+      pinMode(greenPin, OUTPUT);
+      pinMode(greenPin, OUTPUT);
+};
+
+void RGBLed::Red () {
+// Accende il LED di rosso
+      analogWrite(redPin,   0);
+      analogWrite(greenPin, 255);
+      analogWrite(bluePin,  255);
+    };
+
+void RGBLed::Green () {
+// Accende il LED di verde
+      analogWrite(redPin,   255);
+      analogWrite(greenPin, 0);
+      analogWrite(bluePin,  255);
+    };
+
+void RGBLed::Blue () {
+// Accende il LED di blu
+      analogWrite(redPin,   255);
+      analogWrite(greenPin, 255);
+      analogWrite(bluePin,  0);
+    };
+
+void RGBLed::Magenta () {
+// Accende il LED di magenta
+      analogWrite(redPin,   0);
+      analogWrite(greenPin, 255);
+      analogWrite(bluePin,  0);
+    };
+
+void RGBLed::Cyano () {
+// Accende il LED di Cyano
+      analogWrite(redPin,   255);
+      analogWrite(greenPin, 0);
+      analogWrite(bluePin,  0);
+    };
+
+void RGBLed::Yellow () {
+// Accende il LED di giallo
+      analogWrite(redPin,   0);
+      analogWrite(greenPin, 0);
+      analogWrite(bluePin,  255);
+    };
+
+void RGBLed::White () {
+// Accende il LED 
+      analogWrite(redPin,   0);
+      analogWrite(greenPin, 0);
+      analogWrite(bluePin,  0);
+    };
+
+void RGBLed::Off () {
+// Spegne il LED 
+      analogWrite(redPin,   255);
+      analogWrite(greenPin, 255);
+      analogWrite(bluePin,  255);
+    };
+
+void RGBLed::SetColor (byte r, byte g, byte b) {
+      // Imposta il colore di un LED RGB
+
+      analogWrite(redPin,   r);
+      analogWrite(greenPin, g);
+      analogWrite(bluePin,  b);
+    };
+
+
+//////////////////
+// Funzioni
+
+void brilla(byte pin) {
+  // Accende e spegne il LED senza un argomento 
+  // per impostare la velocita'.
+  const int velocita = 500;
+
+pinMode(pin, OUTPUT); 
+  // sequenze di istruzione: accendere e spegnere il LED
+  digitalWrite(pin, HIGH);   // turn the LED on (HIGH is the voltage level)
+  delay(velocita);               // wait for a second
+  digitalWrite(pin, LOW);    // turn the LED off by making the voltage LOW
+  delay(velocita);               // wait for a second
+};
+
+void brilla(byte pin, int velocita) {
+  // Accende e spegne il LED accetando un argomento 
+  // per impostare la velocita'.
+
+pinMode(pin, OUTPUT); 
+  // sequenze di istruzione: accendere e spegnere il LED
+  digitalWrite(pin, HIGH);   // turn the LED on (HIGH is the voltage level)
+  delay(velocita);               // wait for a second
+  digitalWrite(pin, LOW);    // turn the LED off by making the voltage LOW
+  delay(velocita);               // wait for a second
+};
diff --git a/libraries/common/common.h b/libraries/common/common.h
new file mode 100644 (file)
index 0000000..71cb19a
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+  Common Class
+
+  Oggetti comuni
+
+*/
+
+#include "Arduino.h"
+#ifndef common_h
+#define common_h
+
+
+class RGBLed {
+  // Classe rappresentativa di un LED RGB
+  
+    byte redPin ;
+    byte greenPin ;
+    byte bluePin ;
+    byte redValue ;
+    byte greenValue ;
+    byte blueValue ;
+
+  public:
+    RGBLed (byte pinR, byte pinG, byte pinB) ;
+       void Red ();
+    void Green ();
+    void Blue ();
+    void Magenta ();
+    void Cyano ();
+    void White ();
+    void Yellow ();
+    void Off ();
+       void SetColor (byte r, byte g, byte b) ;
+};
+
+void brilla(byte pin, int velocita = 500) ;
+
+#endif
diff --git a/libraries/common/examples/loader/loader.ino b/libraries/common/examples/loader/loader.ino
new file mode 100644 (file)
index 0000000..de6c7d7
--- /dev/null
@@ -0,0 +1,25 @@
+/* Esempio
+
+   Come caricare e usare un oggetto e una funzione
+   facente parte della libreria.
+*/
+
+#include <common.h>
+
+void setup() {
+  // I PINs vengono impostati dalla dichiarazione dell'ogetto.
+}
+
+// Instanziamo un LED
+RGBLed led(11, 10, 9); //Istanziamo un oggetto led facente parte
+                       // della classe RGBLed
+
+void loop() {
+  led.Red();
+  delay(1000);
+  led.SetColor(255, 0, 255) ; // Mettiamo il LED in Green
+  delay(1000);
+  led.Off();
+  
+  brilla(13); // Funzione 
+}
diff --git a/libraries/common/keywords.txt b/libraries/common/keywords.txt
new file mode 100644 (file)
index 0000000..3bbb239
--- /dev/null
@@ -0,0 +1,11 @@
+RGBLed         KEYWORD1
+Red                    KEYWORD2        
+Green          KEYWORD2        
+Blue           KEYWORD2        
+Magenta        KEYWORD2                
+Cyano          KEYWORD2        
+White          KEYWORD2        
+Yellow         KEYWORD2        
+Off            KEYWORD2        
+SetColor       KEYWORD2                
+brilla         KEYWORD2