]> git.piffa.net Git - sketchbook_andrea/blob - motors/motor_2_PWM/motor_2_PWM.ino
670e0b002e28c49ad8b90688091a67288d0f6365
[sketchbook_andrea] / motors / motor_2_PWM / motor_2_PWM.ino
1 /* 
2  Simple Motor : Potenziometro
3  
4  Motore DC con variazione della velocita' impostata 
5  tramite un potenziometro 10k ohms
6  
7  Schema: http://lab.piffa.net/schemi/motor_pot_bb.png
8  */
9
10 const int analogInPin  = A0; // Pin a cui e' collegato il potenziometro
11 const int motorPin     = 9;
12
13 int potValue     = 0;
14 int motValue   = 0;
15
16 void setup() {
17   pinMode(motorPin, OUTPUT);
18   Serial.begin(9600); // Debuggin
19
20 }
21 void loop() {
22   potValue = analogRead(analogInPin); 
23   motValue = potValue / 4 ; //mappatura 1024 -> 255
24
25   analogWrite(motorPin,motValue); // Imposta la velocita' del motore
26
27   Serial.print("Pot value = " );                       
28   Serial.print(potValue);      
29   Serial.print("\t Motore velocita' = ");      
30   Serial.println(motValue); 
31   delay(3); // Pausa, aiuta a stabilizzare l'input
32            
33 }
34
35 /* Domande
36
37 1. Cosa succede quando il motore riceve poca corrente?
38 2. Impostare un valore minimo per la partenza del motore, 
39    sotto al quale il motore non parta.
40 */
41
42
43