Single Button (Press to turn on and press again to turn off)

Hello everyone, introduce my name is Zendry and I come from Indonesia :slight_smile:

I managed to set aside money to buy a new automatic watch, I just found out from YouTube there is an item called a "watch winder" that functions to charge the watch automatically. I was very interested for buying one, but I was disappointed to find out the price was quite expensive for me :frowning:

but I didn't give up, I tried to assemble it myself. And I am very happy to know that "Arduino" can help make what I want. But bad news just happened after I bought all the components needed! It must be coding! OMG :o

Then I tried to learn a little about coding, im so confuse! until oneday what I learned and I tried and I copy the code from Youtube video was successfully. Oh GOD, i was so happy.. But I still feel like something is missing (and I pondered for a while), Bruhh.. Where is the button! :fearful:

I think it will be very cool if there is a button which "if pressed will turn on" and "if pressed again it will off". Guys, only you can please help me. Please :sob:

//Data Awal
#include <Stepper.h>

// Jumlah Langkah per Rotasi Motor 
const float STEPS_PER_REV = 32; 

// Jumlah Langkah yang di Butuhkan
int StepsRequired;

// Pin yang digunakan 8,9,10,11 
// Terhubung ke Driver Motor In1, In2, In3, In4 
// Urutan Pin 8-10-9-11 Pada Setiap Langkah

Stepper steppermotor(STEPS_PER_REV, 8, 10, 9, 11);

void setup()
{
// Pin stepper Sebagai Output
}

void loop()
{
 \
  // 5 Rotasi ke Kanan (1 Rotasi Adalah 2050)
  steppermotor.setSpeed(500);    
  StepsRequired  =  10250;
  steppermotor.step(StepsRequired);
  delay(2000);
  
  // 5 Rotasi ke Kiri (1 Rotasi Adalah 2050)
  steppermotor.setSpeed(500);    
  StepsRequired  =  - 10250;
  steppermotor.step(StepsRequired);
  delay(2000);

  // 5 Rotasi ke Kanan (1 Rotasi Adalah 2050)
  steppermotor.setSpeed(500);    
  StepsRequired  =  10250;
  steppermotor.step(StepsRequired);
  delay(2000);

  // 5 Rotasi ke Kiri (1 Rotasi Adalah 2050)
  steppermotor.setSpeed(500);    
  StepsRequired  =  - 10250;
  steppermotor.step(StepsRequired);
  
  // Ulangi Dalam 1 Jam
  delay(3600000);

}

Look at the StateChangeDetection example in the IDE and adapt it to alternate between on and off with each button press

Get a push-on, push-off switch. No Arduino or programming involved.

Paul

Exactly what you need here: Button Toggle LED tutorial