If statement not reading boolean properly

My code below is not working for some reason and I cant figure out what the problem is. I trying to run the openh() function when I press button 1 if the status bool is false. and once it runs it should set the status bool to true and then I can press button 2 and run closeh() if status is true, (and set to false once done). simple stuff. the problem is - I start the program, press button 1, openh() runs, the motor goes through its rotation. When its done I press button 2 and nothing happens. If I press button 0 which reverses the status bool, and then press button 2, closeh() runs. Once closeh() is done i press button 1 and openh() runs. No need to press button 0 after running closeh(). So it runs if I reverse status bool to true manually but it doesn’t run when function openh() sets it to true.

#include <Stepper.h>
#include <IRremote.h>
#include <DS3231.h>

#define Button_1 0xFFA25D
#define Button_2 0xFF629D
#define Button_3 0xFFE21D
#define Button_4 0xFF22DD
#define Button_5 0xFF02FD
#define Button_6 0xFFC23D
#define Button_7 0xFFE01F
#define Button_8 0xFFA857
#define Button_9 0xFF906F
#define Button_0 0xFF9867

int counter;
String now;
bool state=false;
int receiver = 7;
IRrecv irrecv(receiver);
decode_results results;

//constant variables
const int stepsPerRevolution = 200;  // change this to fit the number of steps per revolution

// initialize
Stepper hStepper(stepsPerRevolution, 8, 9, 10, 11);

DS3231  rtc(SDA, SCL);

void setup() {
  // set the speed in rpm:
  // initialize the serial port:


     // The following lines can be uncommented to set the date and time
  //rtc.setDOW(TUESDAY);     // Set Day-of-Week to SUNDAY
  //rtc.setTime(23, 59, 0);     // Set the time to 12:00:00 (24hr format)
  //rtc.setDate(15, 12, 2020);   // Set the date to January 1st, 2014

void loop() {

  if (irrecv.decode(&results)){

    if (results.value == Button_1){
      if (state == false){

    if (results.value == Button_2){
      if (state == true) {

    if (results.value == Button_0){
      else if (state==true){

   now = rtc.getTimeStr();
  if (now==("16:15:00")){

 // Serial.println(rtc.getTimeStr());


int openh(){


for(counter=0; counter <= 100; counter++){
  state = true;   

int closeh(){


for(counter=0; counter <= 100; counter++){

Firstly, you can shorten your code by using ! (logical not) operator.

if (state == false) {
  state = true;
else if (state == true) {
  state = false;

By a single line of code :

state = !state;

Secondly, try changing the below line and similar lines:

if (results.value == Button_0)


if (results.value == (uint32_t)Button_0)

Start by printing each of the variables that you are testing just before the if statements. Are the values what you expect ?

Shouldn’t the resume be the last thing you do, not the first?