From 64ea846bb5581bc825b88259427834dc2909caf5 Mon Sep 17 00:00:00 2001 From: eaman Date: Mon, 27 Mar 2017 22:42:06 +0200 Subject: [PATCH] functions motor --- prototypes/motor/drive/drive.ino | 76 ++++++++++++++ prototypes/motor/motor_func/motor_func.ino | 98 +++++++++++++++++++ prototypes/motor/motor_pwm/motor_pwm.ino | 56 +++++++++++ prototypes/motor/motors/motors.ino | 40 ++++++++ .../motor/{motor.ino => single/single.ino} | 2 +- 5 files changed, 271 insertions(+), 1 deletion(-) create mode 100644 prototypes/motor/drive/drive.ino create mode 100644 prototypes/motor/motor_func/motor_func.ino create mode 100644 prototypes/motor/motor_pwm/motor_pwm.ino create mode 100644 prototypes/motor/motors/motors.ino rename prototypes/motor/{motor.ino => single/single.ino} (98%) 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_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/motor.ino b/prototypes/motor/single/single.ino similarity index 98% rename from prototypes/motor/motor.ino rename to prototypes/motor/single/single.ino index e66253c..47e0c04 100644 --- a/prototypes/motor/motor.ino +++ b/prototypes/motor/single/single.ino @@ -1,4 +1,4 @@ -/* L298n motors +/* L298n motor Aggiunta Pilotare 1 motore DC con un modulo l928n -- 2.39.2