From fd843739e632cc71f079bdf3c94d9d5f8e9a3b13 Mon Sep 17 00:00:00 2001 From: Andrea Manni Date: Thu, 20 Apr 2017 17:49:59 +0200 Subject: [PATCH] Cleanup Motori --- basic/blinks/blink_7_diode/blink_7_diode.ino | 49 ++----------------- .../motor_2_PWM_soluzione.ino | 4 -- motors/servo/Knob_2/Knob_2.ino | 3 +- motors/servo/Sweep_1/Sweep_1.ino | 9 ++-- 4 files changed, 12 insertions(+), 53 deletions(-) diff --git a/basic/blinks/blink_7_diode/blink_7_diode.ino b/basic/blinks/blink_7_diode/blink_7_diode.ino index 6ec0519..03b2710 100644 --- a/basic/blinks/blink_7_diode/blink_7_diode.ino +++ b/basic/blinks/blink_7_diode/blink_7_diode.ino @@ -11,14 +11,13 @@ Sostanzialmente e' un circuito a corrente alternata. - Schema: http://lab.piffa.net/schemi/diodi_bb.png Ricordarsi di usare una resistenza da ~320ohms per i LED. Resistenza = (Voltaggio_Arduino - Forward_voltage_LED) / (ampere utilizzati) R = (5v-1.8v) / 0.010a R =320ohms - This example code is in the public domain. + Schema: http://lab.piffa.net/schemi/diodi_bb.png */ @@ -47,46 +46,6 @@ void loop() { /* Domande * - 1. Quanti stati sono disponibili per i LED ? - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Risposte: - 1. Quattro combinazione tra cui 3 stati differenti. - */ + 1. Aggiungere uno stato in cui entrambi i LED sono spenti. + + */ diff --git a/motors/motor_2_PWM_soluzione/motor_2_PWM_soluzione.ino b/motors/motor_2_PWM_soluzione/motor_2_PWM_soluzione.ino index e585201..15eece5 100644 --- a/motors/motor_2_PWM_soluzione/motor_2_PWM_soluzione.ino +++ b/motors/motor_2_PWM_soluzione/motor_2_PWM_soluzione.ino @@ -39,7 +39,3 @@ void loop() { delay(3); // Pause, stabilizza la lettura del Pot } -/* Domande: - 1. Rifare questo esercizio utilizzando la funzione map(). - - */ diff --git a/motors/servo/Knob_2/Knob_2.ino b/motors/servo/Knob_2/Knob_2.ino index 50fa832..c50275f 100644 --- a/motors/servo/Knob_2/Knob_2.ino +++ b/motors/servo/Knob_2/Knob_2.ino @@ -32,7 +32,8 @@ void setup() void loop() { val = analogRead(potpin); // reads the value of the potentiometer (value between 0 and 1023) - val = map(val, 0, 1023, 0, 179); // scale it to use it with the servo (value between 0 and 180) + constrain(val,0,1023); + val = map(val, 0, 1023, 10, 170); // scale it to use it with the servo (value between 10 and 170) myservo.write(val); // sets the servo position according to the scaled value delay(15); // waits for the servo to get there } diff --git a/motors/servo/Sweep_1/Sweep_1.ino b/motors/servo/Sweep_1/Sweep_1.ino index dd91364..cd2e247 100644 --- a/motors/servo/Sweep_1/Sweep_1.ino +++ b/motors/servo/Sweep_1/Sweep_1.ino @@ -21,6 +21,9 @@ Servo myservo; // create servo object to control a servo // a maximum of eight servo objects can be created int pos = 0; // variable to store the servo position +const byte min = 10; // Ai servo economici non piace arrivare agli estremi ;) +const byte max = 170; +const int pausa = 15; void setup() { @@ -30,14 +33,14 @@ void setup() void loop() { - for (pos = 0; pos < 180; pos += 1) // goes from 0 degrees to 180 degrees + for (pos = min; pos < max; pos += 1) // goes from 0 degrees to 180 degrees { // in steps of 1 degree myservo.write(pos); // tell servo to go to position in variable 'pos' delay(15); // waits 15ms for the servo to reach the position } - for (pos = 180; pos >= 1; pos -= 1) // goes from 180 degrees to 0 degrees + for (pos = max; pos >= min; pos -= 1) // goes from 180 degrees to 0 degrees { myservo.write(pos); // tell servo to go to position in variable 'pos' - delay(15); // waits 15ms for the servo to reach the position + delay(pausa); // waits 15ms for the servo to reach the position } } -- 2.39.2