summaryrefslogtreecommitdiff
path: root/debug/motordriver/onemotor
diff options
context:
space:
mode:
authorAbel Tim <abel@main.home>2024-07-03 12:32:55 +0200
committerAbel Tim <abel@main.home>2024-07-03 12:32:55 +0200
commit370fdabd4f8f95b2b9bf1d973d9d974f9491c13d (patch)
treeffa2c48eaf09f84ce80ff51f6b72400a33f34753 /debug/motordriver/onemotor
parent59db64a6e61d8c863f76a4cf8f366b65184192dd (diff)
downloadrobotica-370fdabd4f8f95b2b9bf1d973d9d974f9491c13d.tar.gz
robotica-370fdabd4f8f95b2b9bf1d973d9d974f9491c13d.zip
soft PWM added
Diffstat (limited to 'debug/motordriver/onemotor')
-rw-r--r--debug/motordriver/onemotor/onemotor.ino16
1 files changed, 7 insertions, 9 deletions
diff --git a/debug/motordriver/onemotor/onemotor.ino b/debug/motordriver/onemotor/onemotor.ino
index f3d91e6..33f0c5c 100644
--- a/debug/motordriver/onemotor/onemotor.ino
+++ b/debug/motordriver/onemotor/onemotor.ino
@@ -1,5 +1,3 @@
-#include <Arduino.h>
-
int enA = 1;
int enB = 2;
int pwm1 = 3;
@@ -7,7 +5,7 @@ int pwm2 = 4;
int encoA = 5;
int encoB = 6;
-int speed = 100; // speed 0-100
+int speed = 1; // speed 0-1
double sp = 0.00;
double rpm = 0.00;
@@ -56,17 +54,17 @@ void resetenc(){
}
void move(int sped) {
- sp = abs(sped)*2.55;
- digitalWrite(enA, HIGH);
+ sp = abs(sped)*255;
+ analogWrite(enA, sp);
digitalWrite(enB, LOW);
if (sped < 0) {
Serial.print("back ");
- analogWrite(pwm1, sp);
- analogWrite(pwm2, 0);
+ digitalWrite(pwm1, LOW);
+ digitalWrite(pwm2, HIGH);
} else {
Serial.print("forward ");
- analogWrite(pwm1, 0);
- analogWrite(pwm2, sp);
+ digitalWrite(pwm1, HIGH);
+ digitalWrite(pwm2, LOW);
}
Serial.println(sp);
}