Go Down

Topic: else loop ignored anywhere (Read 1 time) previous topic - next topic

gianpa70

Hi there.

I am new of IDE and C++ but having good notions on programming I started working at a controller on Arduino Uno.

I started up with my complete sketch, then I found this hurdle and reduced the sketch down to the hurdle  itself with no success.

Problem is: Any if else cycle works, but this one doesn't, even if left ALONE in the void loop!

I changed input pins and output pins, no way. Much more complicated ifte loop worked, not this one. Syntax is the same, no code error... just ignored!

Please can anyone suggest what cause IDE to ignore an else loop?

jremington

Please read the "How to use this forum" post and follow the directions.
Post your code, using code tags.

Delta_G

Please can anyone suggest what cause IDE to ignore an else loop?

No, the IDE nor the compiler nor the board will "ignore" any statements.  You messed up your code somehow.  You may not notice it, but you must have.  Or perhaps your wiring.  But either way you've made some mistake. 

You chose not to show us anything about the code you were talking about, so there's not a lot we can do to help you find the mistake. 

But trust me, your line of code is not being "ignored". 
|| | ||| | || | ||  ~Woodstock

Please do not PM with technical questions or comments.  Keep Arduino stuff out on the boards where it belongs.

gianpa70

Hardware is ok: I changed both input and output ports and then checked them again with other ifte cycles and worked.

Here is the latest tested code, from which I removed each and every line other than the "criminal one", and still it didn't work. You will notice that there is a lot more vars and I/O defined, as the code in which this loop is bugging is much larger.

Thanks for any help, for sure a new-comer mess up  :o

int DDC = 6; //Durata in ore del ciclo singolo di deumidificazione
int DFC = 2; //Durata in ore del ciclo di soffiaggio in deumidificazione riscaldata
int CT = 0.250; //Durata in secondi di un loop programma
long CDC = DDC * 3600 / CT; //Numero loops di fine conteggio a termine ciclo deumidificazione
long CFC = DFC * 3600 / CT; //Numero loops del ciclo di soffiaggio in deumidificazione riscaldata
int DryUp = 0; //Richiesta deumidificazione attiva
long CountDU = 0; //Contatore loops in deumidificazione
int FT0 = 400; //Soglia di attivazione comparata al segnale ingresso flussometro -> settare durante taratura su impianto con misura volumetrica e tester su V ingresso pin A0!!!

void setup(){
  pinMode(1, INPUT);//livello avvio pompa sommersa, NC
  pinMode(2, INPUT);//livello arresto pompa sommersa, NA
  pinMode (3, INPUT);//livello shut down pompa circolazione, NC
  pinMode (4, INPUT); //stato igrostato, NA
  pinMode (5, INPUT);//stato termostato, NA
  pinMode (6, INPUT);//failure fan 1,0-5V
  pinMode(7, INPUT);//failure fan 2, 0-5V
  pinMode (A0, INPUT);//segnale flussimetro pre-convertito (impulsi->tensione)
  pinMode (8, OUTPUT);//rele avvio scaldiglia perimetrale
  pinMode(9, OUTPUT);//rele avvio alimentatore fan1 e fan2
  pinMode(10, OUTPUT);//rele avvio fan1
  pinMode(11, OUTPUT); //rele avvio fan2
  pinMode (12, OUTPUT);//rele avvio pompa sommersa
  pinMode(13, OUTPUT);//rele avvio pompa circolazione
  pinMode(A1, OUTPUT);//LED allarme fan1
  pinMode(A2, OUTPUT); //LED allarme fan2
  pinMode(A3, OUTPUT);//LED allarme bassissimo livello serbatoio
}

void loop() {
  int LSP = digitalRead(1); //assegnazione variabili agli input pins
  int LSPH = digitalRead(2);
  int LSD = digitalRead(3);
  int HSH = digitalRead(4);
  int TSL = digitalRead(5);
  int FF1 = digitalRead(6);
  int FF2 = digitalRead(7);
  int FT = analogRead(A0);
 
  if(LSP == LOW && LSPH == LOW){digitalWrite(8,HIGH);}
  else if (LSPH == HIGH) {
  digitalWrite(8, LOW);}

PaulS

Your code, as incorrectly posted, won't even compile.

So, any talk of it functioning properly, or not, it just blowing smoke.
The art of getting good answers lies in asking good questions.

Delta_G

Is that the whole code?  Is that the end of loop? ( There's a brace missing is why I ask)

What is connected to those pins?  You're going to need to show the wiring.  I get that you think it is fine, but you also said it doesn't work which indicates otherwise.  The comment (if I translated right) seems to indicate it is a level switch.  If so, do you have a pulldown resistor for it or is it floating when it isn't made?  
|| | ||| | || | ||  ~Woodstock

Please do not PM with technical questions or comments.  Keep Arduino stuff out on the boards where it belongs.

jremington

Quote
Please read the "How to use this forum" post and follow the directions.
Post your code, using code tags.

gianpa70

yes, I misses the last bracket closing the loop from cut-paste. And yes, it is a portion of the full loop, the one that seems to be ignored when running: I removed any other part of code so to exclude the cause from being a problem of conflict among different instructions. The code is now run on test bed and yes, am using 10k pulldown to bring input pins voltage to ground. The code is supposed to control hydraulic system and heaters. The code I posted is just controlling the start/stop of the refilling pump between LSP (start) and LSPH (stop)

The code DOES get COMPILED and DOES run: it simply provides no output on pin 12, whatever the combination of LSP and LSPH. The same pins work perfectly on direct digitalWrite command, and feed-in perfectly on digitalRead as input to other loops

All in all, this one seems to be a wicked loop!

Delta_G

it simply provides no output on pin 12,
That makes sense.  There's not a single line of code in there that writes anything to pin 12.  You are writing to pin 8. 
|| | ||| | || | ||  ~Woodstock

Please do not PM with technical questions or comments.  Keep Arduino stuff out on the boards where it belongs.

saximus

...it simply provides no output on pin 12, whatever the combination of LSP and LSPH.
But the code you've posted is trying to write to pin 8?

Are you able to have it connected to a computer and print the values of LSP and LSPH to a serial monitor to double check they are reading what you think they are?

gianpa70

yes, correct: I switched to pin 8  in my hardware sanity check... and the LED on pin 8 does not lit either. 

Good point the one of printing to my laptop the vars status, but have no clue what code to use to do that?

PaulS

Quote
Good point the one of printing to my laptop the vars status, but have no clue what code to use to do that?
Is that a question? Or a statement?

Ever heard of Serial.print()?
The art of getting good answers lies in asking good questions.

gianpa70

ok, so: from serial monitor reading serial prints it turns clear that pin1 does not read the high DI. That's quite strange, I don't think it's burnt. I noticed that pins 1 and 2 have tx and rx designation, so my doubt is they could be unable to work as input pins while the usb cable is connected to the laptop. Second doubt I have (but this other sxenario should affect all the other signals as well, which is not the case) is that I am not doing the right thing using the 5 VDC from the board to generate the inputs under a 1k resistor, without bridging the 5  VDC output ground into the ground pin on the D I/O bank. Are they maybe 2 separate grounds??

J-M-L

You can't use pin1

pinMode(1, INPUT);//livello avvio pompa sommersa, NC

And use Serial communication with your PC

Pin 1 is Tx from the serial hardware
Hello - Please do not PM me for help,  others will benefit as well if you post your question publicly on the forums.
Bonjour Pas de messages privés SVP, postez dans le forum directement pour que ça profite à tous

TomGeorge

Hi,
Welcome to the forum.

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Please avoid using pins 0 and 1, as they are the programming pins and the monitor also uses them.

Thanks..  Tom.... :)
Everything runs on smoke, let the smoke out, it stops running....

Go Up