From: eaman Date: Mon, 27 Mar 2017 20:42:06 +0000 (+0200) Subject: functions motor X-Git-Url: http://git.piffa.net/web?a=commitdiff_plain;h=64ea846bb5581bc825b88259427834dc2909caf5;p=rover functions motor --- diff --git a/prototypes/motor/drive/drive.ino b/prototypes/motor/drive/drive.ino new file mode 100644 index 0000000..8c0c8e9 --- /dev/null +++ b/prototypes/motor/drive/drive.ino @@ -0,0 +1,76 @@ +/* L298n motor +Aggiunta + +Guida 2WD composta da 2 motori + +- 2 motori DC +- L298n module +- Batteria > 6v + +*/ + +#include + +void setup() { + abilita(); +} + + +void loop() { +// Avanti + avanti(); + delay(2000); +// Stop + stop(); + delay(1000); + +// TurnSX + turnSX(); + delay(1000); + +// Avanti + avanti(); + delay(2000); +// Stop + stop(); + delay(1000); + + +// TurnDX + turnDX(); + delay(1000); + +// Stop + stop(); + delay(1000); +} + +// Functions +void avanti() { + // Drive ahead: funzione composita + forwardA() ; + forwardB() ; +} + +void indietro() { + // Drive backward: funzione composita + backwardA(); + backwardB(); +} + +void turnDX() { + // Gira a DX + forwardB() ; + backwardA(); +} + +void turnSX() { + // Gira a DX + forwardA() ; + backwardB(); +} + +void stop() { + stopA(); + stopB(); +} diff --git a/prototypes/motor/motor.ino b/prototypes/motor/motor.ino deleted file mode 100644 index e66253c..0000000 --- a/prototypes/motor/motor.ino +++ /dev/null @@ -1,55 +0,0 @@ -/* L298n motors -Aggiunta - -Pilotare 1 motore DC con un modulo l928n - -- 1 motori DC -- L298n module -- Batteria > 6v - -*/ - - -// Configurazione con OUTPUT digitali -// motor one -const int enA = 6; -const int in1 = 7; -const int in2 = 8; -byte speedA = 0; -// motor two -const int enB = 5; -const int in3 = 4; -const int in4 = 3; -byte speedB = 0; - -void setup() { - pinMode(enA, OUTPUT); - pinMode(in1, OUTPUT); - pinMode(in2, OUTPUT); -// pinMode(enB, OUTPUT); -// pinMode(in3, OUTPUT); -// pinMode(in4, OUTPUT); -} - - -void loop() { -// Forward - digitalWrite(in1,LOW); - digitalWrite(in2,HIGH); - digitalWrite(enA,HIGH); - delay(2000); - -// Stop - digitalWrite(enA,LOW); - delay(1000); - -// Backward - digitalWrite(in2,LOW); - digitalWrite(in1,HIGH); - digitalWrite(enA,HIGH); - delay(2000); - -// Stop - digitalWrite(enA,LOW); - delay(1000); -} diff --git a/prototypes/motor/motor_func/motor_func.ino b/prototypes/motor/motor_func/motor_func.ino new file mode 100644 index 0000000..cf7c254 --- /dev/null +++ b/prototypes/motor/motor_func/motor_func.ino @@ -0,0 +1,98 @@ +/* L298n motor +Aggiunta + +Pilotare 2 motore DC con un modulo l928n +Enable in PWM per settare velocita' massima + +- 2 motori DC +- L298n module +- Batteria > 6v + +*/ + + +// 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; + +void setup() { + pinMode(enA, OUTPUT); + pinMode(in1, OUTPUT); + pinMode(in2, OUTPUT); + pinMode(enB, OUTPUT); + pinMode(in3, OUTPUT); + pinMode(in4, OUTPUT); +} + + +void loop() { +// Forward + forwardA(); + forwardB(); + delay(2000); + +// Stop + stopA(); + stopB(); + delay(1000); + +// Backward + backwardA(); + backwardB(); + delay(2000); + +// Stop + stopA(); + stopB(); + delay(1000); +} + +// Functions + +// 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/prototypes/motor/motor_pwm/motor_pwm.ino b/prototypes/motor/motor_pwm/motor_pwm.ino new file mode 100644 index 0000000..718e5ba --- /dev/null +++ b/prototypes/motor/motor_pwm/motor_pwm.ino @@ -0,0 +1,56 @@ +/* L298n motor +Aggiunta + +Pilotare 1 motore DC con un modulo l928n +Enable in PWM per settare velocita' massima + +- 1 motori DC +- L298n module +- Batteria > 6v + +*/ + + +// 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 = 0; + +void setup() { + pinMode(enA, OUTPUT); + pinMode(in1, OUTPUT); + pinMode(in2, OUTPUT); +// pinMode(enB, OUTPUT); +// pinMode(in3, OUTPUT); +// pinMode(in4, OUTPUT); +} + + +void loop() { +// Forward + digitalWrite(in1,LOW); + digitalWrite(in2,HIGH); + analogWrite(enA,speed); + delay(2000); + +// Stop + digitalWrite(enA,LOW); + delay(1000); + +// Backward + digitalWrite(in2,LOW); + digitalWrite(in1,HIGH); + analogWrite(enA,speed); + delay(2000); + +// Stop + digitalWrite(enA,LOW); + delay(1000); +} diff --git a/prototypes/motor/motors/motors.ino b/prototypes/motor/motors/motors.ino new file mode 100644 index 0000000..103eb2d --- /dev/null +++ b/prototypes/motor/motors/motors.ino @@ -0,0 +1,40 @@ +/* L298n motor +Aggiunta + +Pilotare 2 motore DC con un modulo l928n +Enable in PWM per settare velocita' massima + +- 2 motori DC +- L298n module +- Batteria > 6v + +*/ +#include + + +void setup() { + abilita(); +} + + +void loop() { +// Forward + forwardA(); + forwardB(); + delay(2000); + +// Stop + stopA(); + stopB(); + delay(1000); + +// Backward + backwardA(); + backwardB(); + delay(2000); + +// Stop + stopA(); + stopB(); + delay(1000); +} diff --git a/prototypes/motor/single/single.ino b/prototypes/motor/single/single.ino new file mode 100644 index 0000000..47e0c04 --- /dev/null +++ b/prototypes/motor/single/single.ino @@ -0,0 +1,55 @@ +/* L298n motor +Aggiunta + +Pilotare 1 motore DC con un modulo l928n + +- 1 motori DC +- L298n module +- Batteria > 6v + +*/ + + +// Configurazione con OUTPUT digitali +// motor one +const int enA = 6; +const int in1 = 7; +const int in2 = 8; +byte speedA = 0; +// motor two +const int enB = 5; +const int in3 = 4; +const int in4 = 3; +byte speedB = 0; + +void setup() { + pinMode(enA, OUTPUT); + pinMode(in1, OUTPUT); + pinMode(in2, OUTPUT); +// pinMode(enB, OUTPUT); +// pinMode(in3, OUTPUT); +// pinMode(in4, OUTPUT); +} + + +void loop() { +// Forward + digitalWrite(in1,LOW); + digitalWrite(in2,HIGH); + digitalWrite(enA,HIGH); + delay(2000); + +// Stop + digitalWrite(enA,LOW); + delay(1000); + +// Backward + digitalWrite(in2,LOW); + digitalWrite(in1,HIGH); + digitalWrite(enA,HIGH); + delay(2000); + +// Stop + digitalWrite(enA,LOW); + delay(1000); +}