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
*/
/* 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.
+
+ */
delay(3); // Pause, stabilizza la lettura del Pot
}
-/* Domande:
- 1. Rifare questo esercizio utilizzando la funzione map().
-
- */
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
}
// 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()
{
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
}
}