Go Down

Topic: SOLVED (Thanks) "if" and "els" with distance sensor and LCD display (Read 634 times) previous topic - next topic

CtrlAltElite

The complete code is above, but the problem is solved now.
The complete code above has the || where there should be a &&, and the semicolon where the semicolon shouldn't be, so we can't see exactly what it is you are trying to compile when you got the error you said you had.
Has there been an outbreak of the stupid virus, and I didn't get the memo?

MichDragstar

Just one more question: what part of the code makes it happen I read the distance with a ,
pe 43,23cm and not 43cm

MichDragstar

The complete code above has the || where there should be a &&, and the semicolon where the semicolon shouldn't be, so we can't see exactly what it is you are trying to compile when you got the error you said you had.
This is how I have changed the code now, and it works fine.
Code: [Select]
if (targetDistance > 40) {
      LCD.print("LEV LOW ");       
  }
else if (targetDistance < 40 && targetDistance > 20) {
      LCD.print("LEV MED ");       
  }
else (targetDistance < 20); {
  LCD.print ("LEV HI ");
}


the only question I have is why there is a , in the distance value. pe 43.23cm and not simply 43cm

CtrlAltElite

I think your chances of repeatedly being able to measure to an accuracy of 1/10th of a millimetre are pretty remote - the wavelength of a 40kHz signal in air is something like 8.5mm.
Has there been an outbreak of the stupid virus, and I didn't get the memo?

MichDragstar

Can I remove the , in the valua on the LCD ? And reading pe just 43cm and not 43,22

CtrlAltElite

Code: [Select]
 LCD.print((int) (targetDistance + 0.5)); //Print measured distance
This will print the value as a rounded integer.
(I'm sorry, I only just realised that "pe" should be "be")
Has there been an outbreak of the stupid virus, and I didn't get the memo?

MichDragstar

see pic please about the , in the value

MichDragstar

Code: [Select]
  LCD.print((int) (targetDistance + 0.5)); //Print measured distance
This will print the value as a rounded integer.
(I'm sorry, I only just realised that "pe" should be "be")
Sorry CtrlAltElite, "pe" ment for me "per example" .
I am really thankfull to you for your great help. The value is now without the ,
In Belgium it is now 22u20. So good night and ones more thank you!!!!!!!!!!

Go Up