Go Down

Topic: code issues (Read 1 time) previous topic - next topic

Joes

hi there when this code is called up in the main loop it only calls it once then does other things so this code below only does one revolution then stops how can i make this run continously until when the arduino is reset?

Quote

void LED2() {                 
          digitalWrite(lockoutled,HIGH);
          delay(500);
          digitalWrite(lockoutled,LOW);
          delay(500);
          digitalWrite(lockoutled,HIGH);
          delay(500);
          digitalWrite(lockoutled,LOW);
          delay(1000);
        }

wildbill

You'll need to post the whole sketch to get any meaningful help.

Far-seeker


You'll need to post the whole sketch to get any meaningful help.


Joes, also when you do use a code box instead of quote box (because code boxes have scroll bars).  To do so either click on the little button with a "#", or use "code" instead of "quote" in the brackets.

Joes

the full code:

Code: [Select]


/*                       PRIVA GAS / OIL CONTROL

*/
const int heatbutton     = 2 ;
const int ignition_fan_2 = 10;
const int saleswitch     = 4 ;
const int solenoid       = 12;
const int photo_pressure = 3 ;
const int lockoutled     = 8 ;
const int heatbutton_feed= 5 ;
const int fan            = 9 ;
const int map1_or2       = 6 ;
const int relay230_24    = 11;
const int ionisation_in  = 7 ;
const int ventbutton     = 13;
      int ionisation     = 5 ; 
bool DoneInitialization = false; 

void setup()
{
  pinMode(heatbutton,       INPUT );   
  pinMode(ignition_fan_2,   OUTPUT);
  pinMode(saleswitch,       INPUT );
  pinMode(solenoid,         OUTPUT);
  pinMode(photo_pressure,   INPUT );
  pinMode(lockoutled,       OUTPUT);
  pinMode(heatbutton_feed,  OUTPUT);
  pinMode(fan,              OUTPUT);
  pinMode(map1_or2,         INPUT );
  pinMode(relay230_24,      OUTPUT);
  pinMode(ionisation_in,    INPUT );
  pinMode(ventbutton,       INPUT );
  Serial.begin(9600);
//-------------------------------------------
  digitalWrite(heatbutton_feed, HIGH);
//--------------------------------------------------------
}

  void loop()       
  {
   //              ******  map 1 or 2  ******
    if (digitalRead(map1_or2)==   HIGH)  {
     oil();  }                                 // Oil map
    else {                                   
     gaz();  }                                 // Gaz map
     
  //--------------------------------------------------------
  //                            ******  Serial  ******
  Serial.print("** PRIVA CONTROL  **");
  void newLine();
 
  Serial.print("Pilot or ign       :");
  Serial.println(digitalRead(map1_or2));
 
  Serial.print("Ionisation swith input  :");
  Serial.println(digitalRead(ionisation_in));
 
  Serial.print("photo or pressure       :");
  Serial.println(digitalRead(photo_pressure));
 
  Serial.print("sales switch           :");
  Serial.println(digitalRead(saleswitch));
 
  Serial.print("Ionisation              :");
  Serial.println(analogRead(ionisation));
 
 
  delay(1000);
 
  }
 
  //------------------------------------------------------------------------------------
  //                           ******  gaz map-1  ******
    void gaz() {       
//------------------------------------------------------------------------------------- 

  if (digitalRead(heatbutton)==   HIGH) {                 // Heat button
  digitalWrite(fan,               HIGH);
  delay(4000);
  //-------------------------------------------------------------------------------------
  if (digitalRead(saleswitch)==   HIGH) {                 // sale switch if HIGH
  digitalWrite(solenoid,          HIGH);
  delay(5000);
digitalWrite(ignition_fan_2,     HIGH);
   }
  //-------------------------------------------------------------------------------------
else {                                                  // sale switch if LOW
   delay(10);
   digitalWrite(solenoid,          LOW);
    digitalWrite(fan,              LOW);
    LED2();
   digitalWrite(heatbutton_feed,   LOW);
  }
  //--------------------------------------------------------------------------------------
if (digitalRead(photo_pressure)== LOW)  {                // pressure if LOW
   delay(10);
   digitalWrite(solenoid,          LOW);
   LED1();
   digitalWrite(fan,               LOW);
   digitalWrite(heatbutton_feed,   LOW);
      }
    }
   else {                                                //when heat button is LOW
  digitalWrite(solenoid,           LOW);
  digitalWrite(ignition_fan_2,     LOW);
 
  if (digitalRead(photo_pressure)==LOW) {                //   low gaz pressure
  digitalWrite(solenoid,           LOW);
  digitalWrite(heatbutton_feed,    LOW);
   LED1();                                               //   Lock out LED
  }
    if (digitalRead(ventbutton)== HIGH) {
  digitalWrite(fan,               HIGH);
  }
  else {
  digitalWrite(fan,               LOW);
    }
}
}
   //--------------------------------------------------------------------------------------
   //                       ******  oil map-2  ******

   void oil() {

  //--------------------------------------------------------------------

  if (digitalRead(heatbutton)==            HIGH) {
    delay(10);    //debounce
    if (!DoneInitialization)
    {                                                 
      if (digitalRead(ionisation_in)==     HIGH) {          // if ionisation swith HIGH
        int val = analogRead(ionisation);
        if (val <900) {                                       
          LED3();
          digitalWrite(heatbutton_feed,    LOW);
          return;
        }
      }   
      else {                         
        if (digitalRead(photo_pressure)==  HIGH)
        {                                                   // if photo swith HIGH
        delay(10);
          LED1();         
          digitalWrite(heatbutton_feed,    LOW);
         return;
       }
      }
      digitalWrite(fan,                    HIGH);
      delay(4000);       
     
    //---------------------------------------------------------------------
    if (digitalRead(saleswitch)==   HIGH) {           // sale switch if HIGH
    digitalWrite(relay230_24,       HIGH);            // 230V out put to ignition
    digitalWrite(ignition_fan_2,    HIGH);
    delay(1000);
      digitalWrite(solenoid,        HIGH);
    }
    DoneInitialization=true;                          // Initialization is done, don't run it again until button has been low
    }
    //---------------------------------------------------------------------
    if (digitalRead(saleswitch)==   LOW) {            // sale switch if LOW
      digitalWrite(solenoid,        LOW);
      digitalWrite(fan,             LOW);
      LED2();
      digitalWrite(heatbutton_feed, LOW);
    }
    //---------------------------------------------------------------------
    delay(3000);
    if (digitalRead(ionisation_in)== HIGH)             // if ionisation swith HIGH
    {
      int val = analogRead(ionisation);
      if (val >900) {                                  // ionisation if LOW   
       digitalWrite(solenoid,        LOW);
       digitalWrite(heatbutton_feed, LOW);
       LED3();
      }
    }

    if (digitalRead(photo_pressure)==LOW)  {           // photo if LOW
      delay(10);
      digitalWrite(solenoid,         LOW);
      digitalWrite(heatbutton_feed,  LOW);
      LED1();
    }
    //---------------------------------------------------------------------
    else {
      digitalWrite(ignition_fan_2,   LOW);
    }
  }
    //---------------------------------------------------------------------
    else {                                          // switching off
    digitalWrite(solenoid,       LOW);
    digitalWrite(ignition_fan_2, LOW);
    DoneInitialization=false;                       // resetting the count
    delay(1000);
    digitalWrite(relay230_24,     LOW);
    if (digitalRead(ventbutton)== LOW) {
    delay(5000);
    digitalWrite(fan,            LOW);
        }
    //--------------------------------------------------------
    //                ******  vent button  ******
    if (digitalRead(heatbutton)== LOW) {
    if (digitalRead(ventbutton)== HIGH) {
    digitalWrite(fan,             HIGH);
    }
    else {
    digitalWrite(fan,             LOW);
      }
     }
    }
   }
   //--------------------------------------------------
   //         ****** LED blink LOCK OUTS ******
   //--------------------------------------------------
        void LED1() {                 // gaz: HIGH/LOW pressure     oil: photo LOW  or auxhillary
          digitalWrite(lockoutled,HIGH);
          delay(1000);
          digitalWrite(lockoutled,LOW);
          delay(1000);
        }
       
     
        void LED2() {                  // sale switch if LOW
          digitalWrite(lockoutled,HIGH);
          delay(500);
          digitalWrite(lockoutled,LOW);
          delay(500);
          digitalWrite(lockoutled,HIGH);
          delay(500);
          digitalWrite(lockoutled,LOW);
          delay(1000);
        }
       
       
        void LED3() {                  // ionisations
          digitalWrite(lockoutled,HIGH);
          delay(500);
          digitalWrite(lockoutled,LOW);
          delay(500);
          digitalWrite(lockoutled,HIGH);
          delay(500);
          digitalWrite(lockoutled,LOW);
          delay(500);
          digitalWrite(lockoutled,HIGH);
          delay(500);
          digitalWrite(lockoutled,LOW);
          delay(1000);
        }
       

   



Quote


You'll need to post the whole sketch to get any meaningful help.


Joes, also when you do use a code box instead of quote box (because code boxes have scroll bars).  To do so either click on the little button with a "#", or use "code" instead of "quote" in the brackets.


sorry just pushed wrong button 

CrossRoads

Looks like you need to hit some pretty specific conditions for the various if paths to call out the LED2 function.
Need to be in void oil or void gaz and saleswitch needs to be Low.
You could add some serial.prints and see if the code flow is following the expected path, or if variables aren't getting the values you expected.
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

Far-seeker


sorry just pushed wrong button 


No problem...

Joes

it all works exactly how i want it to apart from the three LED blink LOCK OUTS at the bottom they only do the code in each section once when called up.

wildbill

I can't see why those led routines wouldn't get called repeatedly. Of course, the led won't flash in a continuous pattern for any of the functions because of all the other delays in the code, but I'd expect them to run again and again given that restriction. What do you actually observe the led doing?

Joes

the led does exactly what it says in the code but only does it once.

wildbill

Then it is time, as Crossroads said, to add some print statements to your code to see the execution path.

mhastie1234

I just had a question. Does it not have to be in the void loop part of the sketch to run over and over again or will it do that command anywhere with in the sketch. For my own curiosity.

Thanks

Joes


mhastie1234

Cut and paste into bottom of void loop. Let me know?

PeterH


Does it not have to be in the void loop part of the sketch to run over and over again or will it do that command anywhere with in the sketch. For my own curiosity.


Your entry points are setup() which gets called once, and loop() which gets called repeatedly. If you want your code to run repeatedly, put it in loop() or in a function called from loop().
I only provide help via the forum - please do not contact me for private consultancy.

Joes

ok
i have just changed it all about so everything is now in void loop the only problem is that the led part to the code is running all the time istead of when its called up i think i have written up the call up command incorrectly?

Code: [Select]


/*                       PRIVA GAS / OIL CONTROL

*/
const int heatbutton     = 2 ;
const int ignition_fan_2 = 10;
const int saleswitch     = 4 ;
const int solenoid       = 12;
const int photo_pressure = 3 ;
const int lockoutled     = 8 ;
const int heatbutton_feed= 5 ;
const int fan            = 9 ;
const int map1_or2       = 6 ;
const int relay230_24    = 11;
const int ionisation_in  = 7 ;
const int ventbutton     = 13;
      int ionisation     = 5 ; 
bool DoneInitialization = false; 

void setup()
{
  pinMode(heatbutton,       INPUT );   
  pinMode(ignition_fan_2,   OUTPUT);
  pinMode(saleswitch,       INPUT );
  pinMode(solenoid,         OUTPUT);
  pinMode(photo_pressure,   INPUT );
  pinMode(lockoutled,       OUTPUT);
  pinMode(heatbutton_feed,  OUTPUT);
  pinMode(fan,              OUTPUT);
  pinMode(map1_or2,         INPUT );
  pinMode(relay230_24,      OUTPUT);
  pinMode(ionisation_in,    INPUT );
  pinMode(ventbutton,       INPUT );
  Serial.begin(9600);
//-------------------------------------------
  digitalWrite(heatbutton_feed, HIGH);
//--------------------------------------------------------
}

  void loop()       
  {     
  //--------------------------------------------------------
  //                            ******  Serial  ******
  Serial.print("** PRIVA CONTROL  **");
  void newLine();
 
  Serial.print("Pilot or ign       :");
  Serial.println(digitalRead(map1_or2));
 
  Serial.print("Ionisation swith input  :");
  Serial.println(digitalRead(ionisation_in));
 
  Serial.print("photo or pressure       :");
  Serial.println(digitalRead(photo_pressure));
 
  Serial.print("sales switch           :");
  Serial.println(digitalRead(saleswitch));
 
  Serial.print("Ionisation              :");
  Serial.println(analogRead(ionisation));
 
 
  delay(1000);
 
 
     //              ******  map 1 or 2  ******
    if (digitalRead(map1_or2)==   LOW)  {
  //------------------------------------------------------------------------------------
  //                           ******  gaz map-1  ******

  if (digitalRead(heatbutton)==   HIGH) {                 // Heat button
  digitalWrite(fan,               HIGH);
  delay(4000);
  //-------------------------------------------------------------------------------------
  if (digitalRead(saleswitch)==   HIGH) {                 // sale switch if HIGH
  digitalWrite(solenoid,          HIGH);
  delay(5000);
digitalWrite(ignition_fan_2,     HIGH);
   }
  //-------------------------------------------------------------------------------------
else {                                                  // sale switch if LOW
   delay(10);
   digitalWrite(solenoid,          LOW);
    digitalWrite(fan,              LOW);
    void LED2();
   digitalWrite(heatbutton_feed,   LOW);
  }
  //--------------------------------------------------------------------------------------
if (digitalRead(photo_pressure)== LOW)  {                // pressure if LOW
   delay(10);
   digitalWrite(solenoid,          LOW);
   void LED1();
   digitalWrite(fan,               LOW);
   digitalWrite(heatbutton_feed,   LOW);
      }
    }
   else {                                                //when heat button is LOW
  digitalWrite(solenoid,           LOW);
  digitalWrite(ignition_fan_2,     LOW);
 
  if (digitalRead(photo_pressure)==LOW) {                //   low gaz pressure
  digitalWrite(solenoid,           LOW);
  digitalWrite(heatbutton_feed,    LOW);
   void LED1();                                         //   Lock out LED
  }
    if (digitalRead(ventbutton)== HIGH) {
  digitalWrite(fan,               HIGH);
  }
  else {
  digitalWrite(fan,               LOW);
    }
  }
}

   //--------------------------------------------------------------------------------------
   //                       ******  oil map-2  ******
   else {
  //--------------------------------------------------------------------

  if (digitalRead(heatbutton)==            HIGH) {
    delay(10);    //debounce
    if (!DoneInitialization)
    {                                                 
      if (digitalRead(ionisation_in)==     HIGH) {          // if ionisation swith HIGH
        int val = analogRead(ionisation);
        if (val <900) {                                       
         void LED3();
          digitalWrite(heatbutton_feed,    LOW);
          return;
        }
      }   
      else {                         
        if (digitalRead(photo_pressure)==  HIGH)
        {                                                   // if photo swith HIGH
        delay(10);
          void LED1();         
          digitalWrite(heatbutton_feed,    LOW);
         return;
       }
      }
      digitalWrite(fan,                    HIGH);
      delay(4000);       
     
    //---------------------------------------------------------------------
    if (digitalRead(saleswitch)==   HIGH) {           // sale switch if HIGH
    digitalWrite(relay230_24,       HIGH);            // 230V out put to ignition
    digitalWrite(ignition_fan_2,    HIGH);
    delay(1000);
      digitalWrite(solenoid,        HIGH);
    }
    DoneInitialization=true;                          // Initialization is done, don't run it again until button has been low
    }
    //---------------------------------------------------------------------
    if (digitalRead(saleswitch)==   LOW) {            // sale switch if LOW
      digitalWrite(solenoid,        LOW);
      digitalWrite(fan,             LOW);
      void LED2();
      digitalWrite(heatbutton_feed, LOW);
    }
    //---------------------------------------------------------------------
    delay(3000);
    if (digitalRead(ionisation_in)== HIGH)             // if ionisation swith HIGH
    {
      int val = analogRead(ionisation);
      if (val >900) {                                  // ionisation if LOW   
       digitalWrite(solenoid,        LOW);
       digitalWrite(heatbutton_feed, LOW);
       void LED3();
      }
    }

    if (digitalRead(photo_pressure)==LOW)  {           // photo if LOW
      delay(10);
      digitalWrite(solenoid,         LOW);
      digitalWrite(heatbutton_feed,  LOW);
      void LED1();
    }
    //---------------------------------------------------------------------
    else {
      digitalWrite(ignition_fan_2,   LOW);
    }
  }
    //---------------------------------------------------------------------
    else {                                          // switching off
    digitalWrite(solenoid,       LOW);
    digitalWrite(ignition_fan_2, LOW);
    DoneInitialization=false;                       // resetting the count
    delay(1000);
    digitalWrite(relay230_24,     LOW);
    if (digitalRead(ventbutton)== LOW) {
    delay(5000);
    digitalWrite(fan,            LOW);
        }
    //--------------------------------------------------------
    //                ******  vent button  ******
    if (digitalRead(heatbutton)== LOW) {
    if (digitalRead(ventbutton)== HIGH) {
    digitalWrite(fan,             HIGH);
    }
    else {
    digitalWrite(fan,             LOW);
      }
     }
    }
   }
   //--------------------------------------------------
   //         ****** LED blink LOCK OUTS ******
   //--------------------------------------------------
       void LED1(); {                 // gaz: HIGH/LOW pressure     oil: photo LOW  or auxhillary
          digitalWrite(lockoutled,HIGH);
          delay(1000);
          digitalWrite(lockoutled,LOW);
          delay(1000);
        }
       
     
        void LED2(); {                  // sale switch if LOW
          digitalWrite(lockoutled,HIGH);
          delay(500);
          digitalWrite(lockoutled,LOW);
          delay(500);
          digitalWrite(lockoutled,HIGH);
          delay(500);
          digitalWrite(lockoutled,LOW);
          delay(1000);
        }
       
       
        void LED3(); {                  // ionisations
          digitalWrite(lockoutled,HIGH);
          delay(500);
          digitalWrite(lockoutled,LOW);
          delay(500);
          digitalWrite(lockoutled,HIGH);
          delay(500);
          digitalWrite(lockoutled,LOW);
          delay(500);
          digitalWrite(lockoutled,HIGH);
          delay(500);
          digitalWrite(lockoutled,LOW);
          delay(1000);
        }
       
  }
   


Go Up