/*
PWM demo with a logical analyzer
- Connect pin ~11 to a logic analyzer and a multimeter
+ Connect pin ~9 to a logic analyzer and a multimeter
and witness the power of the built-in PWM generator.
Usage: change pausa from 3000 (demostration) to 20 for sampling.
*/
-int sensorPin = A0; // select the input pin for the potentiometer
-int ledPin = 13; // select the pin for the LED
+const int sensorPin = A0; // select the input pin for the potentiometer
+const int ledPin = 13; // select the pin for the LED
int sensorValue = 0; // variable to store the value coming from the sensor
void setup() {
*/
-int sensorPin = A0; // select the input pin for the potentiometer
-int ledPin = 13; // select the pin for the LED
+const int sensorPin = A0; // select the input pin for the potentiometer
+const int ledPin = 13; // select the pin for the LED
int sensorValue = 0; // variable to store the value coming from the sensor
void setup() {
*/
-int pausa = 5 ; // 100 e' Circa 10% del duty cicle @ 1KHz
+int pausa = 3 ; // pausa in millisecondi
int microPausa = 100 ; // 100 e' Circa 10% del duty cicle @ 1KHz
void setup()
digitalWrite(13, HIGH);
delay(pausa);
digitalWrite(13, LOW);
- delay(pausa * 5);
+ delay(pausa * 9);
}
void microBrilla() {
/*
- PWM demo
+ PWM Stati
PWM per un LED: impostare i valori di luminosita' di un LED.
+ 4 stati di luminosita' per un LED collegato a un PIN PWM
*/
-int led = 9 ; // Il pin ~9 e' abilitato al PWM
-byte brightness = 0; // Valore iniziale per il PWM del LED
-int pausa = 5; // Pausa tra uno stato e l'altro
+const int led = 9 ; // Il pin ~9 e' abilitato al PWM
+byte brightness = 255; // Valore iniziale per il PWM del LED
+const int pausa = 2000; // Pausa tra uno stato e l'altro
void setup() {
pinMode(led, OUTPUT); // Il PIN nove va dichiarato come un OUTPUT
}
void loop() {
- analogWrite(led, brightness) ; // spento
+ // Ledd al 100% : 255
+ analogWrite(led, brightness) ;
delay(pausa);
- brightness++ ;
+ // Ledd al 75% : 191
+ analogWrite(led, brightness * 0.75) ;
+ delay(pausa);
+
+ // Ledd al 50% : 127
+ analogWrite(led, brightness * 0.5) ;
+ delay(pausa);
+
+ // Ledd al 25%: 63
+ analogWrite(led, brightness * 0.25 ) ;
+ delay(pausa);
+
+ // Ledd al 0%
+ analogWrite(led, brightness * 0) ;
}