Hi, I will produce a linear DC drive. (Wire spacing on reel)
I want to control the direction of rotation left and right with two buttons.
When the switch is closed, (change direction).
Motorbutton: start, stop
I have the code with the library in the attachment, but somehow the end buttons don't work (when I switch them to GND)
Bounce2 Library: GitHub - thomasfredericks/Bounce2: Debouncing library for Arduino and Wiring
Can I ask for the correct code if the error is somewhere in the code?
Somehow I can't get the codes right
Thank you very much
code:
// Detect the falling edge
// Include the Bounce2 library found here :
// GitHub - thomasfredericks/Bounce2: Debouncing library for Arduino and Wiring
#include <Bounce2.h>
const int motorbutton = 7;
const int switchp = 5;
const int switchc = 3;
// Instantiate a Bounce object :
Bounce debouncer = Bounce();
void setup() {
Serial.begin(9600);
// Setup the button with an internal pull-up :
pinMode(motorbutton,INPUT_PULLUP);
// After setting up the button, setup the Bounce instance :
debouncer.attach(motorbutton);
debouncer.interval(500);
pinMode(10, OUTPUT);
pinMode(11, OUTPUT);
}
void loop() {
// Update the Bounce instance :
debouncer.update();
// Call code if Bounce fell (transition from HIGH to LOW) :
if ( debouncer.fell() ) {
Serial.println("Motor Button just pressed");
if (digitalRead(switchp)) //if this is not the intended direction for 'swichp' change to 'switchc'
motorclockwise();
else
motoranticlockwise();
delay(100);
}
//stop motor is reached limit
if(digitalRead(switchp)|digitalRead(switchc)){
digitalWrite(10, LOW);
digitalWrite(11, LOW);
}
}
void motorclockwise() {
digitalWrite(10, HIGH);
digitalWrite(11, LOW);
}
void motoranticlockwise() {
digitalWrite(10, LOW);
digitalWrite(11, HIGH);
}