the project is basically this
you have 4 momentary buttons
when you press one of them it does one of four things
button 1
turn stepper 90 degrees, runs pump 1 for 1.5 seconds, delays for 5 seconds, turns stepper -90 degrees
button two
turn stepper 180 degrees, runs pump 2 for 1.5 seconds, delays for 5 seconds, turns stepper -180degrees
button 3
turn stepper -90 degrees, runs pump 3 for 1.5 seconds, delays for 5 seconds, turns stepper 90 degrees
button 4
no turn, run pump four 1.5 seconds, end
i have
ardunio uno
tb6600 motor driver
a hybrid stepper motor
some momentary switches
an external power supply
my code from a tutorial online, it works fine if i dont include button stuff, it just turns foward and back repeatedly over and over
but i add this if/else in and it has
expected unqualified-id before else or if i add brackets it tells me i havent got an IF for the ELSE, ive tried many bracket combos and no idea why it wont see the if, even when it is
{
{ {if {xxxcodexxx}
{
{else {codexxx} }
}
or something similar where it shows me the '{if' is the start and i have 'else}' as the end
ive tried putting it into setup but still struggling to make the button work at all, apart from at one point it would stop the code but even inverting the low/high for the button input it would just then run nonstop again regardles of button
// defines pins numbers
const int stepPin = 5;
const int dirPin = 2;
const int enPin = 8;
const int buttonPin = 9;
int buttonState = 0;
void setup() {
pinMode(buttonPin, INPUT);
Serial.begin(9600);
pinMode(stepPin, OUTPUT);
pinMode(dirPin, OUTPUT);
pinMode(enPin, OUTPUT);
digitalWrite(enPin, LOW);
}
void loop(){
buttonState = digitalRead(buttonPin);
if (buttonState == 1);
{
digitalWrite(dirPin, HIGH);
for (int x = 0; x < 1200; x++) {
digitalWrite(stepPin, HIGH);
delayMicroseconds(500);
digitalWrite(stepPin, LOW);
delayMicroseconds(500);
delay(2000);
}
{
digitalWrite(dirPin, LOW);
for (int x = 0; x < 1200; x++) {
digitalWrite(stepPin, HIGH);
delayMicroseconds(500);
digitalWrite(stepPin, LOW);
delayMicroseconds(500);
delay(2000);
}
}
}
}
else
{ digitalWrite(dirPin, HIGH);
for (int x = 0; x < 400; x++) {
digitalWrite(stepPin, HIGH);
delayMicroseconds(500);
digitalWrite(stepPin, LOW);
delayMicroseconds(500);
delay(2000);
}
ive been on this for ages now ad im struggling hard, i found maybe flag will work? but its all super new to me and i havent got much support from university because of the remote study at the moment.
ive also tried to put the code into setup to run once, but it wont let it write to the board.
also i realise this isnt doing the turn i want but i need to work out how to activate a block of code 1 time using a button before i worry about it turning the right amount.
thanks, Connor