#define VERT_PIN A0
#define HORZ_PIN A1
#define SEL_PIN 2
// Stepper motor on Wokwi!
#include <Stepper.h>
const int stepsPerRevolution = 200; // change this to fit the number of steps per revolution
// for your motor
// initialize the stepper library on pins 8 through 11:
Stepper myStepper(stepsPerRevolution, 8, 9, 10, 11);
Stepper myStepper2(stepsPerRevolution, 7, 6, 5, 4);
void setup() {
// put your setup code here, to run once:
pinMode(VERT_PIN, INPUT);
pinMode(HORZ_PIN, INPUT);
pinMode(SEL_PIN, INPUT_PULLUP);
Serial.begin(115200);
// set the speed at 60 rpm:
myStepper.setSpeed(60);
myStepper2.setSpeed(60);
// initialize the serial port:
}
void loop() {
// put your main code here, to run repeatedly:
int vert = analogRead(VERT_PIN);
int horz = analogRead(HORZ_PIN);
bool selPressed = digitalRead(SEL_PIN) == LOW;
Serial.print(vert);
Serial.print(horz);
Serial.println();
if (vert == 0) {
myStepper.step(-1);
myStepper2.step(1);
}
if (vert == 1023) {
myStepper.step(1);
myStepper2.step(-1);
}
if (horz == 0) {
myStepper.step(-1);
myStepper2.step(1);
}
if (horz == 1023) {
myStepper.step(-1);
myStepper2.step(1);
}
// horz goes from 0 (right) to 1023 (left)
// vert goes from 0 (bottom) to 1023 (top)
// selPressed is true is the joystick is pressed
}