Hi Jane
thank you for your reply
the followup from CORE is always great.
I am using Arduino IDE for programming the ESP32
I can use the 1306 for most functions but can not get the Scrolling to work
Regards
Ian Rusch
That’s fine, the usual method is to put your code at the bottom of your reply within a pair of triple backquotes (``` ```). Everything between them will be formatted as code for readability.
//Testing bounce switch with ULN2003 stpper driver
// Scrolling OLED working 26/10/2025
// Include the Arduino Stepper.h library:
#include <AccelStepper.h> //Include the AccelStepper library
#include <Bounce2.h>
#include <SPI.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
Adafruit_SSD1306 display(128, 64, &Wire, -1);
const int inputPin = 27; // the number of the push button pin
const int ledPin = 2; // the number of the LED pin
int ledValue = LOW;
// boolean isLighting = false; // define a variable to save the state of LED
// Define the motor pins:
#define MP1 25 // IN1 on the ULN2003
#define MP2 33 // IN2 on the ULN2003
#define MP3 32 // IN3 on the ULN2003
#define MP4 35 // IN4 on the ULN2003
#define MotorInterfaceType 8 // Define the interface type as 8 = 4 wires * step factor (2 for half step)
AccelStepper stepper = AccelStepper(MotorInterfaceType, MP1, MP3, MP2, MP4); //Define the pin sequence (IN1-IN3-IN2-IN4)
const int SPR = 2048;
Bounce bouncer = Bounce(); //Steps per revolution
void setup() {
Serial.begin(115200);
pinMode(inputPin, INPUT); // set push button pin into input mode
pinMode(ledPin, OUTPUT); // set LED pin into output mode
bouncer.attach(inputPin); // bouncer.interval(50); // interval in ms
stepper.setMaxSpeed(1000); //Set the maximum motor speed in steps per second
stepper.setAcceleration(200); //Set the maximum acceleration in steps per second^2
Wire.begin(22, 21); // SDA, SCL
display.begin(SSD1306_SWITCHCAPVCC, 0x3c); // may need to change this
display.setTextSize(1);
display.setTextColor(WHITE);
// Scroll full screen
display.clearDisplay();
display.setCursor(0, 1);
display.setTextSize(1);
display.println("PUSH to START");
display.println("PUSH AGAIN to STOP");
// display.println("scrolling!");
display.display();
display.startscrollright(0x00, 0x07);
}
void loop() {
if (bouncer.update() && bouncer.read() == LOW) {
ledValue = ! ledValue;
digitalWrite(ledPin, ledValue);
Serial.print(" ledValue ");
Serial.println(ledValue);
}
if (ledValue == HIGH){
// stepper.moveTo(5 * SPR); //Set the target motor position 5 looks better than 3 (i.e. turn motor for 3 full revolutions)
// stepper.runToPosition(); // Run the motor to the target position
// delay(1000);
// stepper.moveTo(-5 * SPR); //Same as above: Set the target motor position (i.e. turn motor for 3 full revolutions)
// stepper.runToPosition(); // Run the motor to the target position
// delay(1000);
Motor();
}
if (ledValue == LOW){
}
}
void Motor(){
stepper.moveTo(5 * SPR); //Set the target motor position 5 looks better than 3 (i.e. turn motor for 3 full revolutions)
stepper.runToPosition(); // Run the motor to the target position
delay(1000);
stepper.moveTo(-5 * SPR); //Same as above: Set the target motor position (i.e. turn motor for 3 full revolutions)
stepper.runToPosition(); // Run the motor to the target position
delay(1000);
}