From 0f2b25b24227786fa280dc7ae8a6db2cbfcaaa1b Mon Sep 17 00:00:00 2001 From: Andrea Manni Date: Wed, 5 Apr 2017 18:16:33 +0200 Subject: [PATCH] Servo rotation now is progressive --- libraries/rover/library.properties | 2 +- libraries/rover/rover.cpp | 33 ++++++++++++++++++++++-------- 2 files changed, 25 insertions(+), 10 deletions(-) diff --git a/libraries/rover/library.properties b/libraries/rover/library.properties index a5641e8..9af0ea1 100644 --- a/libraries/rover/library.properties +++ b/libraries/rover/library.properties @@ -4,6 +4,6 @@ author=Andrea Manni maintainer=Andrea Manni sentence=Funzioni specifiche per rover paragraph=Funzioni da richiamare negli sketch per rover -category=Robots +category=Device Control url=https://piffa.net architectures=* diff --git a/libraries/rover/rover.cpp b/libraries/rover/rover.cpp index d95fe06..b02e8cb 100644 --- a/libraries/rover/rover.cpp +++ b/libraries/rover/rover.cpp @@ -1,5 +1,5 @@ /* - Rover + Rover Autore: Andrea Manni @@ -26,10 +26,12 @@ const int in4 = 3; byte speedB = 255; // Servo vars -int pos = 0; // variable to store the servo position +int pos = 0; // variable to store the servo position const byte servoPIN =9 ; const byte middle = 90; // Centratura servo -const int spausa = 30; // Pausa movimenti servo +const int spausa = 10; // Pausa movimenti servo +const byte sx = 10; // Min SX +const byte dx = 170; // Maz DX Servo myservo; // Non c'e' bisogno di extern se e' dichiarato in questo scope //////////////////////// @@ -121,15 +123,28 @@ void stopB() { // Servo void turnDX() { // TurnDX - myservo.write(170); + while (pos < dx) { + myservo.write(pos++); + delay(spausa); + } } - + void turnSX() { // TurnSX - myservo.write(10); + while (pos > sx) { + myservo.write(pos--); + delay(spausa); + } } -void turnMiddle() { - // TurnDX - myservo.write(middle); +void turnMiddle() { + // Middle + while (pos > middle) { + myservo.write(pos--); + delay(spausa); + } + while (pos < middle) { + myservo.write(pos++); + delay(spausa); + } } -- 2.39.2