--- /dev/null
+/*
+ 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.
+ */
+
+
+
--- /dev/null
+/*
+ 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
+
+ */
+
+
+
+
+
+
+
/*
Adafruit Arduino - Lesson 3. RGB LED
+
+ RGB LED: rotazione tra tutti i colori.
+
+ Schema: http://lab.piffa.net/schemi/rgb.jpg
+
*/
int redPin = 11;
analogWrite(greenPin, green);
analogWrite(bluePin, blue);
}
+
+
+
+// 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).
-#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
/*
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.
* 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.
+
+
+
+ Schema: http://lab.piffa.net/schemi/rgb.jpg
+
*/
// 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:
--- /dev/null
+/* 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
+}
+