0
Offline
Full Member
Karma: 0
Posts: 236
Arduino rocks
|
 |
« on: August 08, 2012, 12:13:27 pm » |
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? void LED2() { digitalWrite(lockoutled,HIGH); delay(500); digitalWrite(lockoutled,LOW); delay(500); digitalWrite(lockoutled,HIGH); delay(500); digitalWrite(lockoutled,LOW); delay(1000); }
|
|
|
|
|
Logged
|
|
|
|
|
New Jersey
Offline
Edison Member
Karma: 24
Posts: 2345
|
 |
« Reply #1 on: August 08, 2012, 12:15:08 pm » |
You'll need to post the whole sketch to get any meaningful help.
|
|
|
|
|
Logged
|
|
|
|
|
USA
Offline
God Member
Karma: 14
Posts: 644
|
 |
« Reply #2 on: August 08, 2012, 01:55:30 pm » |
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.
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Full Member
Karma: 0
Posts: 236
Arduino rocks
|
 |
« Reply #3 on: August 08, 2012, 02:16:28 pm » |
the full code: /* 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); }
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
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
Boston area, metrowest
Offline
Brattain Member
Karma: 240
Posts: 16427
Available for Design & Build services
|
 |
« Reply #4 on: August 08, 2012, 02:30:53 pm » |
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.
|
|
|
|
|
Logged
|
|
|
|
|
USA
Offline
God Member
Karma: 14
Posts: 644
|
 |
« Reply #5 on: August 08, 2012, 02:48:15 pm » |
sorry just pushed wrong button
No problem...
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Full Member
Karma: 0
Posts: 236
Arduino rocks
|
 |
« Reply #6 on: August 08, 2012, 03:02:45 pm » |
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.
|
|
|
|
|
Logged
|
|
|
|
|
New Jersey
Offline
Edison Member
Karma: 24
Posts: 2345
|
 |
« Reply #7 on: August 08, 2012, 03:41:23 pm » |
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?
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Full Member
Karma: 0
Posts: 236
Arduino rocks
|
 |
« Reply #8 on: August 08, 2012, 03:49:53 pm » |
the led does exactly what it says in the code but only does it once.
|
|
|
|
|
Logged
|
|
|
|
|
New Jersey
Offline
Edison Member
Karma: 24
Posts: 2345
|
 |
« Reply #9 on: August 08, 2012, 04:17:14 pm » |
Then it is time, as Crossroads said, to add some print statements to your code to see the execution path.
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 16
|
 |
« Reply #10 on: August 08, 2012, 08:59:30 pm » |
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
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Full Member
Karma: 0
Posts: 236
Arduino rocks
|
 |
« Reply #11 on: August 09, 2012, 12:50:36 pm » |
good question
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 16
|
 |
« Reply #12 on: August 09, 2012, 10:47:03 pm » |
Cut and paste into bottom of void loop. Let me know?
|
|
|
|
|
Logged
|
|
|
|
|
Milton Keynes UK
Offline
Tesla Member
Karma: 88
Posts: 6287
-
|
 |
« Reply #13 on: August 10, 2012, 07:21:03 am » |
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().
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Full Member
Karma: 0
Posts: 236
Arduino rocks
|
 |
« Reply #14 on: August 10, 2012, 01:02:26 pm » |
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? /* 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); } }
|
|
|
|
|
Logged
|
|
|
|
|
|