]> git.piffa.net Git - sketchbook_andrea/commitdiff
Cleanup Motori
authorAndrea Manni <andrea@piffa.net>
Thu, 20 Apr 2017 15:49:59 +0000 (17:49 +0200)
committerAndrea Manni <andrea@piffa.net>
Thu, 20 Apr 2017 15:49:59 +0000 (17:49 +0200)
basic/blinks/blink_7_diode/blink_7_diode.ino
motors/motor_2_PWM_soluzione/motor_2_PWM_soluzione.ino
motors/servo/Knob_2/Knob_2.ino
motors/servo/Sweep_1/Sweep_1.ino

index 6ec05199614ed09f4bd34590d26199c3bf00d40b..03b271066c2fcc037a944925fbd841df8f970e13 100644 (file)
  
  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.
+ */
index e585201266aa0116f7624051b2086c270cc73b97..15eece5852eb988d6a83348491f367b7f5799456 100644 (file)
@@ -39,7 +39,3 @@ void loop() {
   delay(3); // Pause, stabilizza la lettura del Pot           
 }
 
-/* Domande:
-   1. Rifare questo esercizio utilizzando la funzione map().
-
-   */
index 50fa832637e42ad0a1e9aab794ec3d8a09ec66fa..c50275fff7c15c885cbcb87060730857b77d4a04 100644 (file)
@@ -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 
 } 
index dd9136451d0ff3d94ec23cfc443302e66ce23a15..cd2e2471825e61e6e4a0edab1b33d11360812921 100644 (file)
@@ -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 
   } 
 }