From: eaman Date: Thu, 30 Mar 2017 15:56:42 +0000 (+0200) Subject: Library barchetta X-Git-Url: http://git.piffa.net/web?a=commitdiff_plain;h=844b3ebfdfaa336494408f921342c04627cba065;p=rover Library barchetta --- diff --git a/libraries/rover/rover.cpp b/libraries/rover/rover.cpp index 363d590..5328a02 100644 --- a/libraries/rover/rover.cpp +++ b/libraries/rover/rover.cpp @@ -13,6 +13,66 @@ 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; +// motor two +const int enB = 5; +const int in3 = 4; +const int in4 = 3; +byte speedB = 255; // Funzioni +void abilita() { +// Abilita i PINs come OUTPUTS + pinMode(enA, OUTPUT); + pinMode(in1, OUTPUT); + pinMode(in2, OUTPUT); + pinMode(enB, OUTPUT); + pinMode(in3, OUTPUT); + pinMode(in4, OUTPUT); +} + + +// MotorB +void forwardA() { + // Avanzamento motore + digitalWrite(in1,LOW); + digitalWrite(in2,HIGH); + analogWrite(enA,speedA); +} + +void backwardA() { + // Reverse motore + digitalWrite(in2,LOW); + digitalWrite(in1,HIGH); + analogWrite(enA,speedA); +} + +void stopA() { + // Stop + digitalWrite(enA,LOW); +} + +// MotorB +void forwardB() { + // Avanzamento motore + digitalWrite(in3,LOW); + digitalWrite(in4,HIGH); + analogWrite(enB,speedB); +} + +void backwardB() { + // Reverse motore + digitalWrite(in4,LOW); + digitalWrite(in3,HIGH); + analogWrite(enB,speedB); +} + +void stopB() { + // Stop + digitalWrite(enB,LOW); +} diff --git a/libraries/rover/rover.h b/libraries/rover/rover.h index acde54f..13e1be3 100644 --- a/libraries/rover/rover.h +++ b/libraries/rover/rover.h @@ -13,41 +13,17 @@ Licenza: GPLv3 #ifndef rover_h #define rover_h -////////////////////// -// OBJ - - -class engine { -// Gestione di un singolo motore -private: - byte enablePIN1; - byte enablePIN2; - byte min; // Minimo per partire - byte val; // 8bit PWM - -public: - Engine (byte PIN1, byte PIN2, byte PINPWM); - void Forward (); - void Backward (); - void SetSpeed (); // imposta un valore preciso per il PWM - -} - -class motors { -// classe composta da due engines -// Composition is better than inheritance here - -public: - motors (engine enginesx, engine enginedx) { - void Forward (); - void Backward (); - void TurnLeft (); - void TurnRight (); - void TurnU (); -} -} -////////////////////// +// Global vars + + // Funzioni +void abilita() ; +void forwardA() ; +void backwardA() ; +void stopA() ; +void forwardB() ; +void backwardB() ; +void stopB() ; #endif