]> git.piffa.net Git - rover/blob - prototypes/servo/rotation_func/rotation_func.ino
Ultra
[rover] / prototypes / servo / rotation_func / rotation_func.ino
1 /* Rotazione
2
3    Rotazione di un servomotore tramite la librerio Servo.h .
4
5 L'utilizzo della libreria Servo rende inutilizzabile analogWrite()
6 sui pin 9 e 10 dato che utilizza i timer associati a questi PIN.
7
8 Power: un servo da 9g puo' arrivare ad impegnare 750mA sotto carico
9 (se viene opposta resistenza al movimento del servo), un  SG90 prende 
10 ~52mA se il movimento e' libero. Quindi in fase di test il servo puo'
11 essere alimentato direttamente da una scheda Arduino (200ma dal PIN 5v)
12 ma per l'uso finale dovra' essere alimentato autonomamente.
13
14
15 Rotazione a SX di 90'
16 Rotazione a DC di 90'
17
18 Schema: https://www.arduino.cc/en/uploads/Tutorial/sweep_bb.png
19         http://microbotlabs.com/images/mearm-uno-servo-1.jpg
20    */
21
22 #include <Servo.h> 
23  
24 Servo myservo;  // create servo object to control a servo 
25                 // a maximum of eight servo objects can be created 
26  
27 // Servo vars
28 int pos = 0;    // variable to store the servo position 
29 const byte servo =9 ;
30 const byte middle = 90; // Centratura servo
31 const int spausa = 30; // Pausa movimenti servo
32 const byte left = 170;
33 const byte right = 10;
34  
35 void setup() 
36
37   myservo.attach(servo);  // attaches the servo on pin 9 to the servo object 
38
39   // Centratura iniziale
40   myservo.write(middle);              // tell servo to go to position in variable 'pos' 
41   delay(2000);
42
43  
44  
45 void loop() 
46
47 // Turn DX
48     turnDX();
49     delay(1000);     
50
51     turnMiddle();
52     delay(1000);     
53
54 // Turn SX
55       turnSX();
56       delay(1000);     
57   
58       turnMiddle();
59       delay(1000);     
60
61
62 // Functions
63
64 void turnDX() {
65     // TurnDX
66     myservo.write(right);
67     delay(spausa);     
68 }
69
70 void turnSX() {
71     // TurnSX
72     myservo.write(left);
73     delay(spausa);     
74 }
75
76 void turnMiddle() {
77     // TurnDX
78     myservo.write(middle);
79     delay(spausa);     
80 }
81