Sequencing the code to loop but check input

Hello

I've tried the blink sketch and it works ...yeah!!!!

I then tried tinkering for about three days but can't seem to follow the logic.

The cycle I am trying to build will require the following setup.

Sensing Switch (to activate the sketch) reed switch 1 for motor position forward stop reed switch 2 for motor position reverse stop led out A (optocoupler to drive a H bridge A/B) led out B (optocoupler to drive a H bridge C/D) led out C (optocoupler to drive led cluster) led out D (optocoupler to drive sound circuit)

1 - wait for an input via a switch (if no keep checking)

If yes then do the following

Activate output (led A) - to drive a "H" bridge to drive a motor clockwise Activate output (led C) - to light an led cluster Check motor has driven to stop position (reed switch in 1) if yes Deactivate output A (H bridge FWD) Activate output (led D) - to drive a sound circuit wait 10 seconds Deactivate output (led D) - sound circuit Deactivate output (led C) - led cluster Activate output (led B) - to drive a "H" bridge to drive a motor anti-clockwise Check motor has driven to stop position (reed switch in 2) if yes Deactivate output B (H bridge REV) wait 20 seconds

then go back to checking via sensing switch to start cycle again, whenever sensing switch is triggered.

Really hope someone can help as I am enjoying the arduino nano but really need help with C++

Cheers Guys (and Girls in a political world - sorry)

//Depending on which pins you connect each device, the definitions below will need to change
//I've also made some assumptions on whether HIGH or LOW represents a switch pressed or an output active
const int SensingSwitch = 2; //sensing switch is on pin 2
const int ReedSwitch1 = 3; //motor position forward stop on pin 3
const int ReedSwitch2 = 4; //motor position reverse stop on pin 4
const int LEDOutA = 5; //(optocoupler to drive a H bridge A/B) 
const int LEDOutB = 6; //(optocoupler to drive a H bridge C/D)
const int LEDOutC = 7; //(optocoupler to drive led cluster)
const int LEDOutD = 8; //(optocoupler to drive sound circuit)

void setup() {
  // put your setup code here, to run once:
  //set all the appropriate input and output pins
  pinMode(SensingSwitch, INPUT_PULLUP);
  pinMode(ReedSwitch1, INPUT_PULLUP);
  pinMode(ReedSwitch2, INPUT_PULLUP);
  pinMode(LEDOutA, OUTPUT);
  pinMode(LEDOutB, OUTPUT);
  pinMode(LEDOutC, OUTPUT);
  pinMode(LEDOutD, OUTPUT);
}


void loop() {
  // put your main code here, to run repeatedly:
  
  //1 - wait for an input via a switch (if no keep checking)
  while(digitalRead(SensingSwitch) == HIGH) {
    //do nothing
  }
  //Yes the switch is pressed (LOW) then do the following
  //Activate output (led A) - to drive a "H" bridge to drive a motor clockwise
  digitalWrite(LEDOutA, HIGH);
  //Activate output (led C) - to light an led cluster
  digitalWrite(LEDOutC, HIGH);
  //Check motor has driven to stop position (reed switch in 1) 
  while(digitalRead(ReedSwitch1) == HIGH) {
    //waiting for the switch to become LOW. Will wait 'forever' if the switch is never hit by the mechanism
  }
  //Deactivate output A (H bridge FWD)
  digitalWrite(LEDOutA, LOW);
  //Activate output (led D) - to drive a sound circuit
  digitalWrite(LEDOutD, HIGH);
  //wait 10 seconds
  delay(10000); //note that the sketch cannot read inputs or change outputs during a delay so this may not be what you want here
  //Deactivate output (led D) - sound circuit
  digitalWrite(LEDOutD, LOW);
  //Deactivate output (led C) - led cluster
  digitalWrite(LEDOutC, LOW);
  //Activate  output (led B) - to drive a "H" bridge to drive a motor anti-clockwise
  digitalWrite(LEDOutB, HIGH);
  //Check motor has driven to stop position (reed switch in 2) 
  while(digitalRead(ReedSwitch2) == HIGH) {
    //waiting for switch to become LOW
  }
  //Deactivate output B (H bridge REV)
  digitalWrite(LEDOutB, LOW);
  
  //wait 20 seconds
  delay(20000);
  //this delay prevents the action from restarting until 20 seconds has passed. 
  //it doesn't even look at the sensing switch, so anything sensed during this 20 seconds is ignored
  //This probably isn't what you want.  
}

thank you so much for such a prompt reply.

I shall read through your sketch and try to learn from it.

I really appreciate the time you took to do this.

I shall let you know the outcome shortly, although, probably not tonight.

Thank you so so much.