Code which runs for 12 hours then turns off for 12 hours and repeats

I am looking to create a watch winder and in order to do this i have to have a code which rotates a stepper for 12 hours and then lays idle for 12 hours. The motors turn at 9.469 rpm for 1 minute then rests for 9.1 minutes and repeats. I am trying to find a way to have this code repeat for 12 hours then stop for 12 hour everyday. Any advice?

Start writing the code, and when you get stuck, post the code and describe the problems you’re having

Does the processor need to do anything else? The delay() function uses an unsigned long for its argument so in theory you could delay for 49 days, so 12 hours should be doable.

But not on an ESP device like the Wemos D1 Mini or NodeMCU. You can’t block loop() for more than a few seconds or it will reboot (Watchdog timer).

The FastLED.h library has a method that you might try. It’s called every_n(). it works like this:

void loop() {
   ....
   EVERY_N_MILLISECONDS( <mseconds> ) { 
     <your timed code here>; 
   }

   EVERY_N_SECONDS( <seconds> ) { 
     <your timed code here>; 
   }
}

The library has classes for “Every_N_Milliseconds”, “Every_N_Seconds”, “Every_N_Minutes”, “Every_N_Hours”, and “Every_N_BSeconds”.

I know, what the heck is a BSecond? According to the comments in the library (lib8tion.h), a BSecond is 1024 millis.

//Add Keypad DATA
#include <Keypad.h>

const byte ROWS = 4; //four rows
const byte COLS = 4; //four columns
//define the cymbols on the buttons of the keypads
char hexaKeys[ROWS][COLS] = {
  {'1','2','3','A'},
  {'4','5','6','B'},
  {'7','8','9','C'},
  {'*','0','#','D'}
};
byte rowPins[ROWS] = {9, 8, 7, 6}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {5, 4, 3, 2}; //connect to the column pinouts of the keypad

//initialize an instance of class NewKeypad
Keypad customKeypad = Keypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS); 


//Add stepper motor DATA
#include <Stepper.h>
const int stepsPerRevolution = 2038;  // change this to fit the number of steps per revolution
// for your motor

// initialize multiple steppers with pins
Stepper myStepper1(stepsPerRevolution, 22, 23, 24, 25);
Stepper myStepper2(stepsPerRevolution, 26, 27, 28, 29);
Stepper myStepper3(stepsPerRevolution, 30, 31, 32, 33);
Stepper myStepper4(stepsPerRevolution, 34, 35, 36, 37);
Stepper myStepper5(stepsPerRevolution, 38, 39, 40, 41);
Stepper myStepper6(stepsPerRevolution, 42, 43, 44, 45);
Stepper myStepper7(stepsPerRevolution, 46, 47, 48, 49);
Stepper myStepper8(stepsPerRevolution, 50, 51, 52, 53);

void setup() {
  // set the speed at correct rpm:
  myStepper1.setSpeed(9.47916);
  myStepper2.setSpeed(9.47916);
  myStepper3.setSpeed(9.47916);
  myStepper4.setSpeed(9.47916);
  myStepper5.setSpeed(9.47916);
  myStepper6.setSpeed(9.47916);
  myStepper7.setSpeed(9.47916);
  myStepper8.setSpeed(9.47916);
  // initialize the serial port:
  Serial.begin(9600);
}

void loop() {
  char customKey = customKeypad.getKey();
  
  if (customKey = 1){
    else if (customKey = A)
    //650 TPD
    myStepper.step(19317);
    delay(570000);
    
    else if (customKey = B)
    //750 TPD
    myStepper.step(19317);
    delay(486000);

    else if (customKey = C)
    //850 TPD
    myStepper.step(19317);
    delay(420000);

    else if (customKey = D)
    //1000 TPD
    myStepper.step(19317);
    delay(348000);

    else if (customKey = #)
    //1950 TPD
    myStepper.step(19317);
    delay(150000);
}

Here is my code I have only done one of the stepper motor controls. Essentially what I am trying to do is link each stepper motor to a number on the keypad and the rotation setting to the letters and # sign. So for example i want stepper motor one on and to run at 650 turns per day i would press 1 then A. I would want this to run continuously until i changed it or turned it off.

 if (customKey = 1){

== for comparison

myStepper1.setSpeed(9.47916)Does setSpeed allow fractional values?

TheMemberFormerlyKnownAsAWOL:

 if (customKey = 1){

== for comparison

myStepper1.setSpeed(9.47916)Does setSpeed allow fractional values?

Should I use micro stepping rather than what i am doing?

I think you’re going to have a ton of “else without previous if” errors.

You’re going to need some of these { }.
And these ’ '.

TheMemberFormerlyKnownAsAWOL:
I think you're going to have a ton of "else without previous if" errors.

You're going to need some of these { }.
And these ' '.

Yeah my code is all sorts of messed up, I can't seem to figure out how to pull info from the keypad to use in my if statements

cthulhu445:
Yeah my code is all sorts of messed up, I can’t seem to figure out how to pull info from the keypad to use in my if statements

No that’s not your problem. Not yet anyways. First you need to learn how to write an if statement in general. Forget the keypad for a bit and just learn the basic syntax, especially the bit about the { and the }. You’re never going to be able to figure out the keypad bit if you don’t know that.