From: Andrea Manni Date: Thu, 17 Mar 2016 16:54:49 +0000 (+0100) Subject: analog X-Git-Url: http://git.piffa.net/web?p=sketchbook_andrea;a=commitdiff_plain;h=6eb118d994cdb2299ee4565e4a16b215c54461bc analog --- diff --git a/advanced_projects/led_PWM_logical_analyzer_demo/led_PWM_logical_analyzer_demo.ino b/advanced_projects/led_PWM_logical_analyzer_demo/led_PWM_logical_analyzer_demo.ino index 723a7bf..5416e9c 100644 --- a/advanced_projects/led_PWM_logical_analyzer_demo/led_PWM_logical_analyzer_demo.ino +++ b/advanced_projects/led_PWM_logical_analyzer_demo/led_PWM_logical_analyzer_demo.ino @@ -1,7 +1,7 @@ /* 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. diff --git a/basic/analog_input/analogInput_1/analogInput_1.ino b/basic/analog_input/analogInput_1/analogInput_1.ino index ac477bb..231a9ab 100644 --- a/basic/analog_input/analogInput_1/analogInput_1.ino +++ b/basic/analog_input/analogInput_1/analogInput_1.ino @@ -29,8 +29,8 @@ */ -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() { diff --git a/basic/analog_input/analogInput_2_serial/analogInput_2_serial.ino b/basic/analog_input/analogInput_2_serial/analogInput_2_serial.ino index 2dbb328..fa03276 100644 --- a/basic/analog_input/analogInput_2_serial/analogInput_2_serial.ino +++ b/basic/analog_input/analogInput_2_serial/analogInput_2_serial.ino @@ -27,8 +27,8 @@ */ -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() { diff --git a/basic/pwm/pwm_0_manuale/pwm_0_manuale.ino b/basic/pwm/pwm_0_manuale/pwm_0_manuale.ino index 2170417..b6d6341 100644 --- a/basic/pwm/pwm_0_manuale/pwm_0_manuale.ino +++ b/basic/pwm/pwm_0_manuale/pwm_0_manuale.ino @@ -8,7 +8,7 @@ */ -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() @@ -30,7 +30,7 @@ void brilla() { digitalWrite(13, HIGH); delay(pausa); digitalWrite(13, LOW); - delay(pausa * 5); + delay(pausa * 9); } void microBrilla() { diff --git a/basic/pwm/pwm_0_stati/pwm_0_stati.ino b/basic/pwm/pwm_0_stati/pwm_0_stati.ino index 6a54cac..567d431 100644 --- a/basic/pwm/pwm_0_stati/pwm_0_stati.ino +++ b/basic/pwm/pwm_0_stati/pwm_0_stati.ino @@ -1,21 +1,36 @@ /* - 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) ; }