#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <Stepper.h>
const int stepsPerRevolution = 200;
Stepper myStepper1(stepsPerRevolution, 8, 9, 10, 11);
Stepper myStepper2(stepsPerRevolution, 4, 5, 6, 7);
int counter1 = 0; // Counter for stepper motor 1
int counter2 = 0; // Counter for stepper motor 2
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
const int buttonPin = 3; // Pin where the button is connected
int buttonState ; // Current state of the button
int lastButtonState = HIGH; // Previous state of the button
bool paused = false; // Variable to track if the code is paused
void setup() {
Serial.begin(115200);
myStepper1.setSpeed(100);
myStepper2.setSpeed(100);
if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
Serial.println(F("SSD1306 allocation failed"));
for (;;);
}
pinMode(buttonPin, INPUT_PULLUP); // Set button pin as input with pull-up resistor
}
void loop() {
buttonState = digitalRead(buttonPin);
if (buttonState == LOW && lastButtonState == HIGH) {
paused = !paused; // Toggle paused state
delay(50); // Debouncing delay
}
lastButtonState = buttonState;
if (!paused) {
// Step one revolution in one direction
myStepper1.step(-50);
delay(1000);
myStepper1.step(75);
delay(1000);
myStepper1.step(-25);
delay(1000);
counter1 += 1;
myStepper2.step(25);
delay(1000);
myStepper2.step(25);
delay(1000);
myStepper2.step(-50);
delay(1000);
counter2 += 1;
}
display.clearDisplay();
display.setTextSize(2);
display.setTextColor(SSD1306_WHITE);
display.setCursor(0, 0);
display.println("ORBITAL:");
display.println(counter1);
display.println("ANGULAR:");
display.println(counter2);
display.display();
}