X-Git-Url: http://git.piffa.net/web?p=sketchbook_andrea;a=blobdiff_plain;f=motors%2Fmotor_2_PWM%2Fmotor_2_PWM.ino;fp=motors%2Fmotor_2_PWM%2Fmotor_2_PWM.ino;h=670e0b002e28c49ad8b90688091a67288d0f6365;hp=0000000000000000000000000000000000000000;hb=ea8d99c7d1bf9824a769c81533fe90e437ccd360;hpb=75928e346c7e5631544b0bea01e2d4ae9a5d749e diff --git a/motors/motor_2_PWM/motor_2_PWM.ino b/motors/motor_2_PWM/motor_2_PWM.ino new file mode 100644 index 0000000..670e0b0 --- /dev/null +++ b/motors/motor_2_PWM/motor_2_PWM.ino @@ -0,0 +1,43 @@ +/* + Simple Motor : Potenziometro + + Motore DC con variazione della velocita' impostata + tramite un potenziometro 10k ohms + + Schema: http://lab.piffa.net/schemi/motor_pot_bb.png + */ + +const int analogInPin = A0; // Pin a cui e' collegato il potenziometro +const int motorPin = 9; + +int potValue = 0; +int motValue = 0; + +void setup() { + pinMode(motorPin, OUTPUT); + Serial.begin(9600); // Debuggin + +} +void loop() { + potValue = analogRead(analogInPin); + motValue = potValue / 4 ; //mappatura 1024 -> 255 + + analogWrite(motorPin,motValue); // Imposta la velocita' del motore + + Serial.print("Pot value = " ); + Serial.print(potValue); + Serial.print("\t Motore velocita' = "); + Serial.println(motValue); + delay(3); // Pausa, aiuta a stabilizzare l'input + +} + +/* Domande + +1. Cosa succede quando il motore riceve poca corrente? +2. Impostare un valore minimo per la partenza del motore, + sotto al quale il motore non parta. +*/ + + +