X-Git-Url: http://git.piffa.net/web?p=sketchbook_andrea;a=blobdiff_plain;f=motors%2Fmotor_3_PWM_minimum%2Fmotor_3_PWM_minimum.ino;fp=motors%2Fmotor_3_PWM_minimum%2Fmotor_3_PWM_minimum.ino;h=55cc0a6c3a37d5b7cb3f8c13a4aa69c3999b64ff;hp=0000000000000000000000000000000000000000;hb=ea8d99c7d1bf9824a769c81533fe90e437ccd360;hpb=75928e346c7e5631544b0bea01e2d4ae9a5d749e diff --git a/motors/motor_3_PWM_minimum/motor_3_PWM_minimum.ino b/motors/motor_3_PWM_minimum/motor_3_PWM_minimum.ino new file mode 100644 index 0000000..55cc0a6 --- /dev/null +++ b/motors/motor_3_PWM_minimum/motor_3_PWM_minimum.ino @@ -0,0 +1,43 @@ +/* + Simple Motor : Potenziometro con minimo + + Motore DC con variazione della velocita' impostata + tramite un potenziometro 10k ohms, + settato un valore minimo sotto il quale il motore + non viene attivato. + + 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; +const int minMotValue = 50 ; // Valore minimo per il motore, + // questo variera' in base ai motori + +void setup() { + pinMode(motorPin, OUTPUT); + Serial.begin(9600); // Debuggin + +} +void loop() { + potValue = analogRead(analogInPin); + motValue = potValue / 4 ; // mappatura 1024 -> 255 + +if (motValue > minMotValue) { // Minimum motor spped check + analogWrite(motorPin,motValue); // Imposta la velocita' del motore +} else { +analogWrite(motorPin,LOW) ; +} + + + Serial.print("Pot value = " ); + Serial.print(potValue); + Serial.print("\t Motore velocita' = "); + Serial.println(motValue); + delay(3); // Pausa, aiuta a stabilizzare l'input + +}