MianQi
May 25, 2021, 4:32am
#1
I used these code in my program:
case btnUP:
{
cursorCoordinateY--;
constrain(cursorCoordinateY, 0, 1);
while, I got "cursorCoordinateY = -1" in Serial Monitor, and the cursor location on LCD1602 is "-1", not "0", what maybe the reason?
6v6gt
May 25, 2021, 6:57am
#3
It is only a snippet so how the variable is defined and how you printed it is not clear. However, constrain() is defined like this and it is difficult to see what goes wrong in your specific case:
#define constrain(amt,low,high) ((amt)<(low)?(low):((amt)>(high)?(high):(amt)))
J-M-L
May 25, 2021, 8:18am
#5
Constrain does not modify your variable, it just gives the result of constraining that variable.
Try with
cursorCoordinateY = constrain(cursorCoordinateY, 0, 1);
system
Closed
September 22, 2021, 8:19am
#6
This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.