]> git.piffa.net Git - rover/commitdiff
Functions per motori
authorAndrea Manni <andrea@piffa.net>
Mon, 3 Apr 2017 09:53:51 +0000 (11:53 +0200)
committerAndrea Manni <andrea@piffa.net>
Mon, 3 Apr 2017 09:53:51 +0000 (11:53 +0200)
libraries/rover/rover.cpp
libraries/rover/rover.h
prototypes/motor/README [new file with mode: 0644]
prototypes/motor/motor_func/motor_func.ino
prototypes/motor/motors/motors.ino

index 5328a02bf8328a8388edabac9e4c724faa7d2e70..1b6c88e16c32d3c86a55c2ed2d9932205a55f2aa 100644 (file)
@@ -37,7 +37,7 @@ void abilita() {
 }
 
 
-// MotorB
+// MotorA
 void forwardA() {
     // Avanzamento motore
     digitalWrite(in1,LOW);
@@ -45,6 +45,13 @@ void forwardA() {
     analogWrite(enA,speedA);
 }
 
+void forwardA(byte speedA) {
+    // Avanzamento motore
+    digitalWrite(in1,LOW);
+    digitalWrite(in2,HIGH);
+    analogWrite(enA,speedA);
+}
+
 void backwardA() {
     // Reverse motore
     digitalWrite(in2,LOW);
@@ -52,6 +59,13 @@ void backwardA() {
     analogWrite(enA,speedA);
 }
 
+void backwardA(byte speedA) {
+    // Reverse motore
+    digitalWrite(in2,LOW);
+    digitalWrite(in1,HIGH);
+    analogWrite(enA,speedA);
+}
+
 void stopA() {
     // Stop
     digitalWrite(enA,LOW);
@@ -65,6 +79,13 @@ void forwardB() {
     analogWrite(enB,speedB);
 }
 
+void forwardB(byte speedB) {
+    // Avanzamento motore
+    digitalWrite(in3,LOW);
+    digitalWrite(in4,HIGH);
+    analogWrite(enB,speedB);
+}
+
 void backwardB() {
     // Reverse motore
     digitalWrite(in4,LOW);
@@ -72,6 +93,13 @@ void backwardB() {
     analogWrite(enB,speedB);
 }
 
+void backwardB(byte speedB) {
+    // Reverse motore
+    digitalWrite(in4,LOW);
+    digitalWrite(in3,HIGH);
+    analogWrite(enB,speedB);
+}
+
 void stopB() {
     // Stop
     digitalWrite(enB,LOW);
index 13e1be3a8b8572719bf65e3ec136a64379b0fa18..7d5da82a795c2f7ddbba35bc394819a5bb5e9c70 100644 (file)
@@ -19,11 +19,15 @@ Licenza:    GPLv3
 // Funzioni
 
 void abilita() ;
-void forwardA() ;
+void forwardA(); // speedA e' dato dalla variabile golabale speedA
+void forwardA(byte speedA); // Overloading
 void backwardA() ;
+void backwardA(byte speedA) ;
 void stopA() ;
 void forwardB() ;
+void forwardB(byte speedB) ;
 void backwardB() ;
+void backwardB(byte speedB) ;
 void stopB() ;
 
 #endif
diff --git a/prototypes/motor/README b/prototypes/motor/README
new file mode 100644 (file)
index 0000000..854e433
--- /dev/null
@@ -0,0 +1,16 @@
+Funzioni
+============
+
+Note a riguardo delle funzioni.
+
+Domande
+---------
+
+La funzione forwardB / forwardA accetta una parametro tramite overloading:
+
+1. Se il parametro non viene passato da dove viene pescato?
+2. Si potrebbe fare la stessa cosa con un valore di default?
+2.1 Con quali differenze?
+
+3 La funzione composita drive pero' non accetta nessun parametro, implementare
+la possibilita' che accetti la velocita' come argomento.
index cf7c25406fec7cb137ffcb2bffee93beb8025099..83a3748e7ed92daf9d2f431dad068e084c6d1362 100644 (file)
@@ -49,6 +49,26 @@ void loop() {
     backwardB();
     delay(2000);
 
+// Stop
+    stopA();
+    stopB();
+    delay(1000);
+
+// Left
+    backwardA();
+    forwardB();
+    delay(2000);
+
+// Stop
+    stopA();
+    stopB();
+    delay(1000);
+
+// right
+    backwardB();
+    forwardA();
+    delay(2000);
+
 // Stop
     stopA();
     stopB();
index 103eb2dd8a6cf76394a9a083b2246d7d02d0627f..e27762cc1b79d9b47faa5ddaba4b509d4f497f56 100644 (file)
@@ -1,5 +1,4 @@
 /* L298n motor
-Aggiunta
 
 Pilotare 2 motore DC con un modulo l928n
 Enable in PWM per settare velocita' massima