]> git.piffa.net Git - sketchbook_andrea/commitdiff
rgb
authorAndrea Manni <andrea@piffa.net>
Mon, 20 Apr 2015 17:19:33 +0000 (19:19 +0200)
committerAndrea Manni <andrea@piffa.net>
Mon, 20 Apr 2015 17:19:33 +0000 (19:19 +0200)
RGB_LED/rgb_0/rgb_0.ino [new file with mode: 0644]
RGB_LED/rgb_0_soluzione/rgb_0_soluzione.ino [new file with mode: 0644]
RGB_LED/rgb_1_all_color/rgb_1_all_color.ino
RGB_LED/rgb_2_pwm/rgb_2_pwm.ino
RGB_LED/rgb_3_ReadASCIIString/rgb_3_ReadASCIIString.ino
piezo/piezo_5_Knock/piezo_5_Knock.ino [new file with mode: 0644]

diff --git a/RGB_LED/rgb_0/rgb_0.ino b/RGB_LED/rgb_0/rgb_0.ino
new file mode 100644 (file)
index 0000000..ea32ca6
--- /dev/null
@@ -0,0 +1,42 @@
+/*
+    Adafruit Arduino - Lesson 3. RGB LED
+ RGB LED: mpostare i colori per un LED RGB
+ common anode
+
+ Schema: http://lab.piffa.net/schemi/rgb.jpg
+ */
+
+int redPin = 11;
+int greenPin = 10;
+int bluePin = 9;
+
+
+
+void setup()
+{
+  pinMode(redPin, OUTPUT);
+  pinMode(greenPin, OUTPUT);
+  pinMode(bluePin, OUTPUT);
+}
+
+void loop()
+{
+  analogWrite(redPin, 255);
+  analogWrite(greenPin,255);
+  analogWrite(bluePin, 255);
+}
+
+/* Domande:
+ 1. Accendere il LED nei vari colori
+ 2. Come scrivere le istruzioni analog Write in modo da sottrarre i valori?
+ 3. Scrivere una funzione che accetti 3 parametri per impostare i colori
+ 4. Scrivere una funzione che accetti i colori in esadecimale
+    - http://www.yellowpipe.com/yis/tools/hex-to-rgb/color-converter.php
+ 5. Scrivere una funzione che accetti come parametro il nome del colore
+ es "blue" e imposti il LED.
+ */
+
+
+
diff --git a/RGB_LED/rgb_0_soluzione/rgb_0_soluzione.ino b/RGB_LED/rgb_0_soluzione/rgb_0_soluzione.ino
new file mode 100644 (file)
index 0000000..475de32
--- /dev/null
@@ -0,0 +1,66 @@
+/*
+    Adafruit Arduino - Lesson 3. RGB LED
+ RGB LED: mpostare i colori per un LED RGB
+ common anode
+ */
+
+int redPin = 11;
+int greenPin = 10;
+int bluePin = 9;
+
+
+
+void setup()
+{
+  pinMode(redPin, OUTPUT);
+  pinMode(greenPin, OUTPUT);
+  pinMode(bluePin, OUTPUT);
+}
+
+void loop()
+{
+  setColor(0xFF,0x00,0x00) ; // imposta il LED in rosso
+
+  // setName("green") ; 
+}
+
+// Funzioni:
+void setColor(int red, int green, int blue)
+// Imposta i colori di un LED RGB Common Anodote
+// in esadecimale
+{
+  analogWrite(redPin, 255 -red);
+  analogWrite(greenPin, 255 - green);
+  analogWrite(bluePin, 255 - blue);
+}
+
+void setName(String colorName)
+// Imposta i colori di un LED RGB Common Anodote
+// tramite una stringa
+{
+  if (colorName == "red") {
+    analogWrite(redPin, 0 );
+    analogWrite(greenPin, 255 );
+    analogWrite(bluePin, 255 );
+  } 
+  else if (colorName == "green") {
+    analogWrite(redPin, 255 );
+    analogWrite(greenPin, 0 );
+    analogWrite(bluePin, 255 );
+  }
+  // ...
+}
+/* Hints:
+
+1. Per usare un solo valore esadecimale per settare i colori:
+   - http://ardx.org/src/code/CIRC12-code-MB-SPAR.txt
+ */
+
+
+
+
+
+
+
index 29969add229ffc2368a934e61a4c4cb41ba5a7da..546d636e1ca44964aaa6d935ca3134f51c25fd61 100644 (file)
@@ -1,5 +1,10 @@
     /*
     Adafruit Arduino - Lesson 3. RGB LED
     /*
     Adafruit Arduino - Lesson 3. RGB LED
+    
+    RGB LED: rotazione tra tutti i colori.
+
+     Schema: http://lab.piffa.net/schemi/rgb.jpg
+
     */
      
     int redPin = 11;
     */
      
     int redPin = 11;
@@ -43,3 +48,6 @@
     analogWrite(greenPin, green);
     analogWrite(bluePin, blue);
     }
     analogWrite(greenPin, green);
     analogWrite(bluePin, blue);
     }
+    
+    
+
index 95637858d5910c9efb8c61ba9d5ede50b4ebeae1..8e712fc51374cb0ce2fe41ff6b397792ce63647a 100644 (file)
@@ -1,8 +1,17 @@
+// RGB LED PWM transizione
+
+// Transizione di un LED RGB tra rosso - blue -verde
+// tramite PWM
+
 // This is meant for a Common Anodote RGB LED
 // See all those (255 - val). 
 
 // This is meant for a Common Anodote RGB LED
 // See all those (255 - val). 
 
-#define GREEN 9
-#define BLUE 10
+
+// Schema: http://lab.piffa.net/schemi/rgb.jpg
+
+
+#define GREEN 10
+#define BLUE 9
 #define RED 11
 #define delayTime 20
 
 #define RED 11
 #define delayTime 20
 
index 9da6b1e1e2d0febf7f58a894c9ab106e406adbb2..d1c2a3b13cf7d20a90bb76649997cd5ba55b2d3a 100644 (file)
@@ -1,5 +1,7 @@
 /*
   Reading a serial ASCII-encoded string.
 /*
   Reading a serial ASCII-encoded string.
+  
+  Beware: set monitor to NL NewLine only
  
  This sketch demonstrates the Serial parseInt() function.
  It looks for an ASCII string of comma-separated values.
  
  This sketch demonstrates the Serial parseInt() function.
  It looks for an ASCII string of comma-separated values.
  * blue cathode: digital pin 6
  * anode: +5V
  
  * blue cathode: digital pin 6
  * anode: +5V
  
+ Once you have programmed the Arduino, open your Serial minitor. 
+ Make sure you have chosen to send a newline character when sending a message. 
+ Enter values between 0-255 for the lights in the following format : 
+ Red,Green,Blue. 
+
+ Once you have sent the values to the Arduino, 
+ the attached LED will turn the color you specified, 
+ and you will receive the HEX values in the serial monitor. 
  created 13 Apr 2012
  by Tom Igoe
  
  This example code is in the public domain.
  created 13 Apr 2012
  by Tom Igoe
  
  This example code is in the public domain.
+
+
+
+  Schema: http://lab.piffa.net/schemi/rgb.jpg
+
  */
 
 // pins for the LEDs:
  */
 
 // pins for the LEDs:
-const int redPin = 3;
-const int greenPin = 5;
-const int bluePin = 6;
+const int redPin = 11;
+const int greenPin = 10;
+const int bluePin = 9;
 
 void setup() {
   // initialize serial:
 
 void setup() {
   // initialize serial:
diff --git a/piezo/piezo_5_Knock/piezo_5_Knock.ino b/piezo/piezo_5_Knock/piezo_5_Knock.ino
new file mode 100644 (file)
index 0000000..6f8c2c5
--- /dev/null
@@ -0,0 +1,55 @@
+/* Knock Sensor
+  
+   This sketch reads a piezo element to detect a knocking sound. 
+   It reads an analog pin and compares the result to a set threshold. 
+   If the result is greater than the threshold, it writes
+   "knock" to the serial port, and toggles the LED on pin 13.
+  
+   The circuit:
+       * + connection of the piezo attached to analog in 0
+       * - connection of the piezo attached to ground
+       * 1-megohm resistor attached from analog in 0 to ground
+
+   http://www.arduino.cc/en/Tutorial/Knock
+   
+   created 25 Mar 2007
+   by David Cuartielles <http://www.0j0.org>
+   modified 30 Aug 2011
+   by Tom Igoe
+   
+   This example code is in the public domain.
+
+ */
+
+// these constants won't change:
+const int ledPin = 13;      // led connected to digital pin 13
+const int knockSensor = A0; // the piezo is connected to analog pin 0
+const int threshold = 100;  // threshold value to decide when the detected sound is a knock or not
+
+
+// these variables will change:
+int sensorReading = 0;      // variable to store the value read from the sensor pin
+int ledState = LOW;         // variable used to store the last LED status, to toggle the light
+
+void setup() {
+ pinMode(ledPin, OUTPUT); // declare the ledPin as as OUTPUT
+ Serial.begin(9600);       // use the serial port
+}
+
+void loop() {
+  // read the sensor and store it in the variable sensorReading:
+  sensorReading = analogRead(knockSensor);    
+  
+  // if the sensor reading is greater than the threshold:
+  if (sensorReading >= threshold) {
+    // toggle the status of the ledPin:
+    ledState = !ledState;   
+    // update the LED pin itself:        
+    digitalWrite(ledPin, ledState);
+    // send the string "Knock!" back to the computer, followed by newline
+    Serial.println("Knock!");         
+  }
+  delay(100);  // delay to avoid overloading the serial port buffer
+}
+