From bb56af759cd0aac42aed4e6666ef2e4ffc7c9ef7 Mon Sep 17 00:00:00 2001 From: Andrea Manni Date: Mon, 3 Apr 2017 14:09:07 +0200 Subject: [PATCH] Primo oggetto per drive, con un solo metodo --- libraries/rover/library.properties | 1 - libraries/rover/rover.cpp | 43 +++++++++++++++++++++++------- libraries/rover/rover.h | 36 ++++++++++++++++++++++++- 3 files changed, 69 insertions(+), 11 deletions(-) diff --git a/libraries/rover/library.properties b/libraries/rover/library.properties index a5641e8..9034bd6 100644 --- a/libraries/rover/library.properties +++ b/libraries/rover/library.properties @@ -4,6 +4,5 @@ author=Andrea Manni maintainer=Andrea Manni sentence=Funzioni specifiche per rover paragraph=Funzioni da richiamare negli sketch per rover -category=Robots url=https://piffa.net architectures=* diff --git a/libraries/rover/rover.cpp b/libraries/rover/rover.cpp index 1b6c88e..b208728 100644 --- a/libraries/rover/rover.cpp +++ b/libraries/rover/rover.cpp @@ -13,17 +13,42 @@ Licenza: GPLv3 #define dEBUG -// Configurazione con OUTPUT digitali // motor one -const int enA = 6; -const int in1 = 7; -const int in2 = 8; -byte speedA = 255; +extern int enA = 6; +extern int in1 = 7; +extern int in2 = 8; +extern byte speedA = 255; // motor two -const int enB = 5; -const int in3 = 4; -const int in4 = 3; -byte speedB = 255; +extern int enB = 5; +extern int in3 = 4; +extern int in4 = 3; +extern byte speedB = 255; + +// Oggetti +car::car () { +// Abilita i PINs come OUTPUTS + pinMode(_enA, OUTPUT); + pinMode(_in1, OUTPUT); + pinMode(_in2, OUTPUT); + pinMode(_enB, OUTPUT); + pinMode(_in3, OUTPUT); + pinMode(_in4, OUTPUT); + velA = speedA; + velB = speedB; +} + +void car::avanti () { +// Motor A + digitalWrite(_in1,LOW); + digitalWrite(_in2,HIGH); + analogWrite(_enA,velA); +// Motor B + digitalWrite(_in3,LOW); + digitalWrite(_in4,HIGH); + analogWrite(_enB,velB); +} + + // Funzioni void abilita() { diff --git a/libraries/rover/rover.h b/libraries/rover/rover.h index 7d5da82..5446359 100644 --- a/libraries/rover/rover.h +++ b/libraries/rover/rover.h @@ -1,5 +1,5 @@ /* - Rover + Rover Autore: Andrea Manni @@ -14,6 +14,14 @@ Licenza: GPLv3 #define rover_h // Global vars +extern int enA ; +extern int in1 ; +extern int in2 ; +extern byte speedA ; +// motor two +extern int enB ; +extern int in3 ; +extern int in4 ; // Funzioni @@ -30,4 +38,30 @@ void backwardB() ; void backwardB(byte speedB) ; void stopB() ; +// Objects: + + +class car { +// Lettura delle variabili globali (per poter tenere un file +// di configurazione con tutti i PIN) +// motor one + const int _enA = enA ; + const int _in1 = in1 ; + const int _in2 = in2 ; +// motor two + const int _enB = enB ; + const int _in3 = in3 ; + const int _in4 = in4 ; + +public: + car () ; + byte velA ; + byte velB ; + void avanti (); + void indietro (); + void stop (); + void giraSX (); + void giraDX (); + void setSpeed (); +}; #endif -- 2.39.2