]> git.piffa.net Git - sketchbook_andrea/blobdiff - motors/motor_3_PWM_minimum/motor_3_PWM_minimum.ino
Motori
[sketchbook_andrea] / motors / motor_3_PWM_minimum / motor_3_PWM_minimum.ino
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 (file)
index 0000000..55cc0a6
--- /dev/null
@@ -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
+
+}