The only thing it really needs to do is "go x steps when button y on the gui is pressed"
So, instead of pressing my physical button on digital pin 2 like i've got it in my code now, i want a virtual button to be pressed.
I just need a point where or how to start, so i can dive in deeper. Any suggestions?
// Include the Stepper Library
#include <Stepper.h>
// Map our pins to constants to make things easier to keep track of
const int pwmA = 3;
const int pwmB = 11;
const int brakeA = 9;
const int brakeB = 8;
const int dirA = 12;
const int dirB = 13;
const int buttonPin = 2;
// The amount of steps for a full revolution of your motor.
// 360 / stepAngle
const int STEPS = 200;
int buttonState = 0;
// Initialize the Stepper class
Stepper myStepper(STEPS, dirA, dirB);
void setup() {
// Set the RPM of the motor
myStepper.setSpeed(40);
// Turn on pulse width modulation
pinMode(pwmA, OUTPUT);
digitalWrite(pwmA, HIGH);
pinMode(pwmB, OUTPUT);
digitalWrite(pwmB, HIGH);
// Turn off the brakes
pinMode(brakeA, OUTPUT);
digitalWrite(brakeA, LOW);
pinMode(brakeB, OUTPUT);
digitalWrite(brakeB, LOW);
// Log some shit
Serial.begin(9600);
pinMode(buttonPin, INPUT);
}
void loop() {
// Move the motor X amount of steps
//myStepper.step(STEPS);
//serial.println(STEPS);
// Pause
// delay(2000);
// Move the motor X amount of steps the other way
buttonState = digitalRead(buttonPin);
if (buttonState == HIGH) {
myStepper.step(-STEPS);
Serial.println(-STEPS);
}
else {
// Pause
delay(0100);
}
}