Ich verwende die Arduino Motor Shield R3
Code:
#define PWM_RECHTS 3
#define BREMSE_LINKS 8
#define BREMSE_RECHTS 9
#define PWM_LINKS 11
#define MOTOR_RECHTS 12
#define MOTOR_LINKS 13
void setup() {
Serial.begin(9600);
pinMode(PWM_RECHTS, OUTPUT);
pinMode(BREMSE_LINKS, OUTPUT);
pinMode(BREMSE_RECHTS, OUTPUT);
pinMode(PWM_LINKS, OUTPUT);
pinMode(MOTOR_RECHTS, OUTPUT);
pinMode(MOTOR_LINKS, OUTPUT);
}
void loop() {
while(Serial.available()){
char getData = Serial.read();
{
if (getData == 'w') {
Vorwaerts();
}
else {
Bremsen();
}
}
}
}
void Vorwaerts() {
digitalWrite(MOTOR_RECHTS, HIGH);
digitalWrite(BREMSE_RECHTS, LOW);
analogWrite(PWM_RECHTS, 255);
digitalWrite(MOTOR_LINKS, HIGH);
digitalWrite(BREMSE_LINKS, LOW);
analogWrite(PWM_LINKS, 255);
}
void Bremsen() {
digitalWrite(BREMSE_RECHTS, HIGH);
analogWrite(PWM_RECHTS, 0);
digitalWrite(BREMSE_LINKS, HIGH);
analogWrite(PWM_LINKS, 0);
}
Lesezeichen