0% found this document useful (0 votes)
1 views

Include Steppe

This document contains an Arduino sketch for controlling a stepper motor and a 7-segment display. It uses a button to count presses and starts the motor after five presses, while a potentiometer adjusts the motor speed. The display shows the number of button presses and the motor operates only when enabled.

Uploaded by

Ifaa Biddiiqaa
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views

Include Steppe

This document contains an Arduino sketch for controlling a stepper motor and a 7-segment display. It uses a button to count presses and starts the motor after five presses, while a potentiometer adjusts the motor speed. The display shows the number of button presses and the motor operates only when enabled.

Uploaded by

Ifaa Biddiiqaa
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 2

#include <Stepper.

h>

#include <TM1637Display.h> // Library for 7-segment display

#define STEPS 20 // Define steps per revolution

#define BUTTON_PIN 2

#define POT_PIN A0

#define CLK 4 // TM1637 Display Clock Pin

#define DIO 5 // TM1637 Display Data Pin

Stepper stepper(STEPS, 8, 9, 10, 11);

TM1637Display display(CLK, DIO);

int buttonCount = 0; // Counter for button presses

int motorSpeed = 50; // Default speed

bool motorRunning = false; // Motor state

void setup() {

pinMode(BUTTON_PIN, INPUT_PULLUP);

display.setBrightness(0x0F); // Maximum brightness

display.showNumberDec(0); // Display 0 at start

void loop() {

// Read button

if (digitalRead(BUTTON_PIN) == LOW) {
delay(200); // Debounce delay

buttonCount++;

// Display button count on LED display

display.showNumberDec(buttonCount);

if (buttonCount >= 5) { // Start motor after 5 presses

motorRunning = !motorRunning; // Toggle motor state

buttonCount = 0; // Reset counter

while (digitalRead(BUTTON_PIN) == LOW); // Wait for button release

// Read potentiometer value for speed control

int val = analogRead(POT_PIN);

motorSpeed = map(val, 0, 1023, 5, 100);

stepper.setSpeed(motorSpeed);

// Run motor only if enabled

if (motorRunning) {

stepper.step(10); // Move stepper

You might also like