Philipp Lopinski - Motor
Motorprogramm - Abstandsmesser
// Das Programm bewirkt, dass kurz bevor der Arduino irgendwo gegenstößt oder herunterfällt, stehen bleibt.
#include <AFMotor.h>
AF_DCMotor motor1(1, MOTOR12_64KHZ);
AF_DCMotor motor2(2, MOTOR12_64KHZ);
#define MOT1 6
#define DIR1 7
#define MOT2 5
#define DIR2 4
#define FORW 1
#define BACK 0
float Ausgleich = 0.9;
int sensor = 10;
void setup() {
pinMode(DIR1, OUTPUT);
pinMode(DIR2, OUTPUT);
pinMode(MOT1, OUTPUT);
pinMode(MOT2, OUTPUT);
pinMode(sensor, INPUT);
forward(20000);
delay(5000);
backward(20000);
delay(5000);
}
void forward(float Speed) {
float Speed1 = Speed*Ausgleich;
digitalWrite(DIR1, FORW);
digitalWrite(DIR2, FORW);
analogWrite(MOT1, Speed);
analogWrite(MOT2, Speed1);
}
void backward(float Speed) {
float Speed2 = Speed*Ausgleich;
digitalWrite(DIR1, BACK);
digitalWrite(DIR2, BACK);
analogWrite(MOT1, Speed);
analogWrite(MOT2, Speed2);
}
void loop() {
if(digitalRead(sensor) == LOW){
motor1.run(RELEASE);
motor2.run(RELEASE);
}
else{
motor1.run(FORWARD);
motor2.run(FORWARD);
}
}