Trying to get an interrupt to trigger a change in the code

Hi All

I am having trouble getting the code to react to the HIGH or LOW interrupt I'm telling it to look for.
I can see the voltage change on a mulitmeter but the code just continues running.
Hopefully I've added enough info to code of what I am trying to do for it to make sense
Any help would be good.
Thanks in advance.

//This project is designed to run a cooking cycle on an oven with a touch screen.
//Solenoids are fitted to a bracked mounted infront of the touch screen replicating a users finger making presses.
//Three presses should be made, going through each stage of the cookbook till the recipe is selected.
//The oven will then request user input to start the cook cycle. I have chosen to switch the door circuit open and closed triggering the cook to start.
//A relay has been wired to the 0V and 230V on the HV MAG transformer to trigger a relay to close, the close here creates the circuit for the 5V to be read by the uWSignal.
//Whilst uWSignal is reading HIGH, ButtonPress and DoorOpenClose should be LOW.
//Once the cooking has finished the/MAGs are off, the DoorOpenClose should be the next thing to trigger.
// Process should be
// "Button press X 3"
// "DoorOpenClose X1"
// cook started
// "uWSignal digitalRead == HIGH"
// End of cook
// "uWSignal digitalRead == LOW"
// "DoorOpenClose X1"

//IO
int ButtonPress = 13; // solinoid on relay CH1
int DoorOpenClose = 11; //open door relay CH2
int uWSignal = 2; //Read cooking
int SenduWSignal = 7; //5v signal to relay

void setup(){

{
//IO Modes
pinMode(uWSignal, INPUT); //Reads a signal from HV transformers when mags are switched on. Signal (SenduWSignal) closes the relay sending 5V to uWSignal

pinMode(ButtonPress, OUTPUT); //CH1 on relay controling the switching of a solenoid making "presses"

pinMode(DoorOpenClose, OUTPUT); //CH2 on relay. opening and closing the door safety circuit this triggers the start of the Mags/cooking.

pinMode (SenduWSignal, OUTPUT);//5volts going to the relay creating the 5V read for uWSignal.
}
{

Serial.begin(9600);
}
}

void loop()
{
{
//Solenoid making presses
digitalWrite(ButtonPress, HIGH); // Makes a press.
delay(500); // wait for a second
digitalWrite(ButtonPress, LOW); // waiting
delay(500); // wait for a second
}

{
digitalWrite(ButtonPress, HIGH); // Makes a press
delay(500); // wait for a second
digitalWrite(ButtonPress, LOW); // wating
delay(500); // wait for a second
}

{
digitalWrite(ButtonPress, HIGH); // Makes a press
delay(500); // wait for a second
digitalWrite(ButtonPress, LOW); // waiting
delay(500); // wait for a second
//Oven waiting for user input
}

{

//START THE COOK CYCLE - DOOR OPEN/close
digitalWrite(DoorOpenClose, HIGH); // open the door
delay(2000); // wait
digitalWrite(DoorOpenClose, LOW); // close the door
delay(2000); // wait
//Oven cooking
}

{
//End of cook door open/close
digitalWrite(DoorOpenClose, HIGH); // Open the door
delay(2000); // wait
digitalWrite(DoorOpenClose, LOW); // Close the door
delay(2000); // wait
}

//When the cook starts the signal from the transformers should be read writing all outputs to low untill the cook has finished.
//the end of cook door open/close should be the next thing to trigger.
{
digitalRead (uWSignal);
if(uWSignal == HIGH){
digitalWrite(DoorOpenClose, LOW);
delay(250);
digitalWrite(ButtonPress, LOW);
delay(250);
}
else{
}
}

//below is serial printing the status of the inputs/outputs.
{
if(uWSignal == CHANGE) {
Serial.print ("\nuWSignal Status = 1");
}

else {
}
}

{

if(ButtonPress == CHANGE) {
Serial.print("\nButtonPress Status = 1");
}
else {
}
}

{

if(DoorOpenClose == CHANGE) {
Serial.print ("\nDoorOpenClose Status = 1");
}
else {
}
}

}

I see no interrupts in your sketch

int uWSignal = 2;  //Read cooking
    digitalRead (uWSignal);  //reads the state of uWSignal then throws it away
    if (uWSignal == HIGH)  //uWSignal has a value of 2 so it will always be HIGH

Please follow the advice on posting code given in Read this before posting a programming question

In particular note the advice to Auto format code in the IDE and to use code tags when posting code here as it prevents some combinations of characters in code being interpreted as HTML commands such as italics, bold or a smiley character, all of which render the code useless

If the code exceeds the 9000 character inline limit then attach it to a post

OK.
So I need to set an interrupt for it to be master when the digitalRead get a HIGH?
The code will then wait for a LOW?

{
  digitalRead (uWSignal);
  if(uWSignal == LOW){
  digitalWrite(DoorOpenClose, LOW);
  delay(250);
  digitalWrite(ButtonPress, LOW);
  delay(250);
  }
  else{
    }
  }

No.
Try

  if(digitalRead(uWSignal) == LOW){

OK, Will try.
Thank you

Please post your code using code tags.

I'm not sure why you have so many code blocks. For example:

{

  if(ButtonPress == CHANGE) {
  Serial.print("\nButtonPress Status = 1");
  }  
  else {
  }
}

They are unnecessary and clutter up the code. Also you are not required to have an else block for for each conditional.

I would suggest when you define your pin numbers you include the word "pin" in the variable name to avoid any confusion about what the constant is.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.