Shop OBEX P1 Docs P2 Docs Learn Events
Buttons, LCD, and LEDs — Parallax Forums

Buttons, LCD, and LEDs

cool1100cool1100 Posts: 2
edited 2008-12-18 03:20 in BASIC Stamp
First I would like to say hi to everyone, I'm Jim and have been lurking on this site for months. The information provided by PARALLAX and the members of this forum is just awesome.... Now for my problem, This project seems a little pointless but I'm just learning and thought this would be fun to try. I'm trying to make the LCD screen go blank and the back light go off after the button is released, but while the button is pressed the LCD flickers off and on. When I remove the "LCD clear and back light off" line the project works by showing me what button is being pressed with the back light on all the time. Any help would be great, thanks.

' PDB - TestButtonsAndLCD.bs2

' {$STAMP BS2}
' {$PBASIC 2.5}

DEBUG "BUTTON STATES", CR,
" 0 1 2 4", CR,
"



"

DO
DEBUG CRSRXY, 0, 3,
"B0 = ", BIN1 IN12,
" B1 = ", BIN1 IN13,
" B2 = ", BIN1 IN14,
" B3 = ", BIN1 IN15
PAUSE 50

IF (IN12 = 0) THEN
HIGH 0
SEROUT 8, 84, [noparse][[/noparse]22, 12, 17]
PAUSE 5
SEROUT 8, 84, [noparse][[/noparse]"B0 is PRESSED!!"]
ELSE
LOW 0
'SEROUT 8, 84, [noparse][[/noparse]21, 18]
ENDIF

IF (IN13 = 0) THEN
HIGH 1
SEROUT 8, 84, [noparse][[/noparse]22, 12, 17]
PAUSE 5
SEROUT 8, 84, [noparse][[/noparse]"B1 is PRESSED!!"]
ELSE
LOW 1
'SEROUT 8, 84, [noparse][[/noparse]21, 18]
ENDIF

IF (IN14 = 0) THEN
HIGH 2
SEROUT 8, 84, [noparse][[/noparse]22, 12, 17]
PAUSE 5
SEROUT 8, 84, [noparse][[/noparse]"B2 is PRESSED!!"]
ELSE
LOW 2
'SEROUT 8, 84, [noparse][[/noparse]21, 18]
ENDIF

IF (IN15 = 0) THEN
HIGH 3
SEROUT 8, 84, [noparse][[/noparse]22, 12, 17]
PAUSE 5
SEROUT 8, 84, [noparse][[/noparse]"B3 is PRESSED!!"]
ELSE
LOW 3
'SEROUT 8, 84, [noparse][[/noparse]21, 18]
ENDIF

LOOP

Comments

  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2008-12-17 06:18
    Hi Jim, heres what is happening, your program starts at the top works its way to the bottom then starts all over again, so assuming IN12,IN13,IN14 and IN15 are normally logic 1 then at the first IF..Then because IN12 is 1 the program will goto the else instruction and turn the display and backlight off. The same happens for the next IF..Then and the next two also.

    Now assume you press the button attached to IN12, the display will switch on so will the backlight and the display will clear (just what you wanted). Then the program moves on to the next IF...THEN instruction , sees that IN13 is still at logic 1 so it switches the display off again, the program loop continues to switch the display on and off giving you the flicker you observed.

    There are many ways to tackle this problem, perhaps first I would create two subroutines , one to switch the display on and one to switch it off. Next you must monitor the states of all the switches not just one to make your conditional decisions. Because of the pins you have chosen for the buttons you could easily look at INC , without any buttons pressed INC is going to be %1111 so your conditional statements could be IF INC < 15 GOSUB Display_ON and IF INC =15 Display_Off.

    hope that makes sense to you

    Jeff T.
  • cool1100cool1100 Posts: 2
    edited 2008-12-18 03:20
    Thanks for the reply Jeff,

    I thought about using subroutines, but assumed I would get the same results as I am basically doing the same instruction only locating it in a different area of the program. I will try the subs, but I think your idea about monitoring the states of the pins is what I need to do.

    Again thanks for the help.

    Jim
Sign In or Register to comment.