]> git.piffa.net Git - sketchbook_andrea/blobdiff - motors/motor_2_PWM/motor_2_PWM.ino
Motori
[sketchbook_andrea] / motors / motor_2_PWM / motor_2_PWM.ino
diff --git a/motors/motor_2_PWM/motor_2_PWM.ino b/motors/motor_2_PWM/motor_2_PWM.ino
new file mode 100644 (file)
index 0000000..670e0b0
--- /dev/null
@@ -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.
+*/
+
+
+