do something once inside repeat
xanadu
Posts: 3,347
I have this code using the LCD object and it's monitoring pin 1 of the prop. Having the LCD output in the monitor loop constantly refreshes the display. How would I make this only change the display if the pin input changes instead of refreshing each loop?
repeat
if ina[1] == 1
lcd.backlight(true)
lcd.clrln(1)
lcd.gotoxy(0, 1)
lcd.str(string("Off"))
if ina[1] == 0
lcd.backlight(true)
lcd.clrln(1)
lcd.gotoxy(0, 1)
lcd.str(string("On"))

Comments
You need to keep track of the previous state of the pin.
[COLOR=#ff0000]previousState := 2[/COLOR] ' we want and invalid state to start with repeat if ina[1] == 1 and [COLOR=#ff0000]previousState == 0 [/COLOR] lcd.backlight(true) lcd.clrln(1) lcd.gotoxy(0, 1) lcd.str(string("Off")) [COLOR=#ff0000]previousState := 1 [/COLOR] if ina[1] == 0 and [COLOR=#ff0000]previousState == 1 [/COLOR] lcd.backlight(true) lcd.clrln(1) lcd.gotoxy(0, 1) lcd.str(string("On")) [COLOR=#ff0000]previousState := 0[/COLOR]previousState := 2 ' we want an invalid state to start with repeat if ((newState := ina[1]) <> previousState) lcd.backlight(true) lcd.clrln(1) lcd.gotoxy(0, 1) if (newState) lcd.str(string("Off")) else lcd.str(string("On")) previousState := newState-Phil
best regards Stefan
Thanks but the avatar was not my idea, a knock off version if you will hehe.
@PhiPi - Great input, I see I would need to do that for my code and will, thanks.