Shop OBEX P1 Docs P2 Docs Learn Events
please help me make my code more reliable. SOS ! — Parallax Forums

please help me make my code more reliable. SOS !

Francis160791Francis160791 Posts: 28
edited 2013-10-22 10:02 in BASIC Stamp
' {$STAMP BS2pe}
' {$PBASIC 2.5}

counter VAR Nib

TX PIN 15
Spkr PIN 15
#SELECT $stamp
#CASE BS2PE
T2400 CON 396
T9600 CON 84
T19K2 CON 32
#ENDSELECT

LcdBaud CON T19K2
LcdCls CON $0C ' clear LCD (use PAUSE 5 after)
LcdBLon CON $11 ' backlight on


SEROUT TX, Lcdbaud, ["Key in PIN",CR, LcdBLon]

main:

GOSUB top

IF (IN6=0 AND (IN7=0 OR IN0=0 OR IN1=0)) THEN
GOSUB top
PAUSE 250
ELSEIF (IN7=0 AND (IN8=0 OR IN1=0 OR IN0=0 OR IN2=0))THEN
GOSUB top
PAUSE 250
ELSEIF (IN8=0 AND (IN9=0 OR IN2=0 OR IN1=0 OR IN3=0))THEN
GOSUB top
PAUSE 250
ELSEIF (IN9=0 AND (IN10=0 OR IN3=0 OR IN2=0 OR IN4=0))THEN
GOSUB top
PAUSE 250
ELSEIF (IN10=0 AND (IN11=0 OR IN4=0 OR IN3=0 OR IN5=0))THEN
GOSUB top
PAUSE 250
ELSEIF (IN11=0 AND (IN12=0 OR IN5=0 OR IN4=0))THEN
GOSUB top
PAUSE 250
ELSE
GOSUB btm
ENDIF

GOTO main

'====================================END MAIN==============================================='

top:

IF IN0=0 THEN 'num 0
SEROUT TX, Lcdbaud,["0"]
PAUSE 180
ENDIF
DO
IF IN0=0 THEN
PAUSE 180
ELSE
EXIT
ENDIF
LOOP

IF IN1=0 THEN 'num 1
SEROUT TX, Lcdbaud,["1"]
PAUSE 180
DO
IF IN1=0 THEN
PAUSE 180
ELSE
EXIT
ENDIF
LOOP
ENDIF

IF IN2=0 THEN 'num 2
SEROUT TX, Lcdbaud,["2"]
PAUSE 180
DO
IF IN2=0 THEN
PAUSE 180
ELSE
EXIT
ENDIF
LOOP
ENDIF

IF IN3=0 THEN 'num 3
SEROUT TX, Lcdbaud,["3"]
PAUSE 180
DO
IF IN3=0 THEN
PAUSE 180
ELSE
EXIT
ENDIF
LOOP
ENDIF

IF IN4=0 THEN 'num 4
SEROUT TX, Lcdbaud,["4"]
PAUSE 180
DO
IF IN4=0 THEN
PAUSE 180
ELSE
EXIT
ENDIF
LOOP
ENDIF

IF IN5=0 THEN 'num 5
SEROUT TX, Lcdbaud,["5"]
PAUSE 180
DO
IF IN5=0 THEN
PAUSE 180
ELSE
EXIT
ENDIF
LOOP
ENDIF

RETURN

'=======================================END TOP=============================================='
btm:

IF IN6=0 THEN 'num 6
POLLIN 7, 1
POLLMODE 2
PAUSE 300
counter=0
DO
counter=counter+1
IF IN7=1 THEN
PAUSE 50
ELSE
EXIT
ENDIF
LOOP UNTIL (counter=6)

IF IN7=1 AND IN0=1 THEN
SEROUT TX, Lcdbaud,["6"]
DO
IF IN6=0 THEN
PAUSE 50
ELSE
EXIT
ENDIF
LOOP
ENDIF
ENDIF


IF IN7=0 THEN 'num 7
POLLIN 6, 1
POLLIN 8, 1
POLLMODE 2
PAUSE 300
counter=0
DO
counter=counter+1
IF IN6=1 AND IN8=1 THEN
PAUSE 50
ELSE
EXIT
ENDIF
LOOP UNTIL (counter=6)

IF IN6=1 AND IN8=1 AND IN1=1 THEN
SEROUT TX, Lcdbaud,["7"]
DO
IF IN7=0 THEN
PAUSE 50
ELSE
EXIT
ENDIF
LOOP
ENDIF
ENDIF

IF IN8=0 THEN 'num 8
POLLIN 7, 1
POLLIN 9, 1
POLLMODE 2
PAUSE 300
counter=0
DO
counter=counter+1
IF IN7=1 AND IN9=1 THEN
PAUSE 50
ELSE
EXIT
ENDIF
LOOP UNTIL (counter=6)

IF IN7=1 AND IN9=1 AND IN2=1 THEN
SEROUT TX, Lcdbaud,["8"]
DO
IF IN8=0 THEN
PAUSE 50
ELSE
EXIT
ENDIF
LOOP
ENDIF
ENDIF

IF IN9=0 THEN 'num 9
POLLIN 9, 1
POLLIN 10, 1
POLLMODE 2
PAUSE 300
counter=0
DO
counter=counter+1
IF IN8=1 AND IN10=1 THEN
PAUSE 50
ELSE
EXIT
ENDIF
LOOP UNTIL (counter=6)

IF IN8=1 AND IN10=1 AND IN3=1 THEN
SEROUT TX, Lcdbaud,["9"]
DO
IF IN9=0 THEN
PAUSE 50
ELSE
EXIT
ENDIF
LOOP
ENDIF
ENDIF


IF IN10=0 THEN 'Enter
POLLIN 9, 1
POLLIN 11, 1
POLLMODE 2
PAUSE 300
counter=0
DO
counter=counter+1
IF IN9=1 AND IN11=1 THEN
PAUSE 50
ELSE
EXIT
ENDIF
LOOP UNTIL (counter=6)

IF IN9=1 AND IN11=1 AND IN4=1 THEN
SEROUT TX, Lcdbaud,[ CR, "Thanks for banking"]
DO
IF IN10=0 THEN
PAUSE 50
ELSE
EXIT
ENDIF
LOOP
ENDIF
ENDIF

IF IN11=0 THEN 'Clear
POLLIN 10, 1
POLLIN 12, 1
POLLMODE 2
PAUSE 300
counter=0
DO
counter=counter+1
IF IN10=1 AND IN12=1 THEN
PAUSE 50
ELSE
EXIT
ENDIF
LOOP UNTIL (counter=6)

IF IN10=1 AND IN12=1 AND IN5=1 THEN
SEROUT TX, Lcdbaud,[LcdCls,"Key in PIN",CR]
DO
IF IN11=0 THEN
PAUSE 50
ELSE
EXIT
ENDIF
LOOP
ENDIF
ENDIF

IF IN12=0 THEN 'Cancel
POLLIN 11, 1
POLLIN 5, 1
POLLMODE 2
PAUSE 300
counter=0
DO
counter=counter+1
IF IN12 THEN
PAUSE 50
ELSE
EXIT
ENDIF
LOOP UNTIL (counter=6)

IF IN11=1 AND IN5=1 THEN
SEROUT TX, LcdBaud, [8, " ", 8]

DO
IF IN12=0 THEN
PAUSE 50
ELSE
EXIT
ENDIF
LOOP
ENDIF
ENDIF

RETURN

Comments

  • ElectricAyeElectricAye Posts: 4,561
    edited 2013-10-20 20:52
    "Thanks for banking" ????

    "Key in PIN" ???

    This wouldn't be one of those fake ATMs would it?

    It might help if your code had some comment lines, for starters.
  • FranklinFranklin Posts: 4,747
    edited 2013-10-20 21:34
    And was formatted correctly using [code] tags...
  • Duane DegnDuane Degn Posts: 10,588
    edited 2013-10-20 22:10
    I can see why Franklin is wanting to direct people here:

    attachment.php?attachmentid=78421&d=1297987572
  • Duane DegnDuane Degn Posts: 10,588
    edited 2013-10-20 22:14
    What kind of buttons are you using? You have a lot of pauses in the code. I think it would be hard to read the buttons reliably with so many pauses.
  • Francis160791Francis160791 Posts: 28
    edited 2013-10-20 22:17
    cause my project is about ATM. i need to use Utilize OPTEK OPB732 sensor to display on my LCD. this the whole code , and i need to make it more reliable. if i place 2 finger on both sensor, the number will display both number. but i just want to display one by one.
  • Duane DegnDuane Degn Posts: 10,588
    edited 2013-10-20 22:29
    Utilize OPTEK OPB732 sensor

    What are these? Do you have a link?
    Duane Degn wrote: »
    What kind of buttons are you using?

    And how are the buttons wired. A schematic would help.

    There can be lots of issues when reading buttons.

    I have a project which uses a 4x4 keypad. I ended up having some trouble reading the keypresses. I got some help here.

    If you describe your setup well, others may be able to help you find a solution to any problems you're having. Notice, I included a schematic and a picture when I asked for help (hint, hint).
    Duane Degn wrote: »
    You have a lot of pauses in the code. I think it would be hard to read the buttons reliably with so many pauses.

    Why so many pauses?
  • Francis160791Francis160791 Posts: 28
    edited 2013-10-20 22:41
    i don't have any link. cause i cannot show post my ppt online. i solder the sensor on to the board. pauses is to deny the time when i place mt finger on top of the sensor.
  • ElectricAyeElectricAye Posts: 4,561
    edited 2013-10-21 07:41
    ...i need to use Utilize OPTEK OPB732 sensor to display on my LCD. ....

    Is this what you are using for a keypad? If so, it seems to me this could have troubles with reading other fingers, knuckles, thumbs, shirt sleeves, etc. while the person is pressing the desired buttons. The data sheet states it can read up to 1 inch from the sensor, and one of the graphs shows it could read maybe 2 inches if you do not set your thresholds with care.

    http://www.mouser.com/ds/2/414/OPB732-10181.pdf
  • Francis160791Francis160791 Posts: 28
    edited 2013-10-21 18:35
    yes. i try using my finger, and it work . just that i want to be more reliable . :D
  • ElectricAyeElectricAye Posts: 4,561
    edited 2013-10-21 19:17
    ...if i place 2 finger on both sensor, the number will display both number. but i just want to display one by one.

    This description confuses me.

    yes. i try using my finger, and it work . just that i want to be more reliable .

    I think you need to describe your problem in more detail. And you need to describe in more detail what you want your code to do and not do.
  • Francis160791Francis160791 Posts: 28
    edited 2013-10-21 19:59
    i want to display the number i want to display. cause my project got 13 sensor. if i place my finger on 2 sensor. it will display both . i just want to display one sensor at a time.
  • ElectricAyeElectricAye Posts: 4,561
    edited 2013-10-21 21:03
    ... if i place my finger on 2 sensor. it will display both . i just want to display one sensor at a time.

    If two sensors are being triggered, how is the program supposed to know which one of the sensors is the correct one to display? If I were looking at the keyboard with one of your fingers pressing on numbers 6 and 7, how could I tell you meant to display a 6 and not a 7?

    Maybe what you need is a way to back up your cursor position, blank out the present display, back up the cursor position again and overwrite the previous number displayed with the new number? Is that what you're talking about?
  • Hal AlbachHal Albach Posts: 747
    edited 2013-10-21 21:31
    I'm not sure what you are trying to do with the POLLIN and POLLMODE commands, but as written I don't believe they will do anything since you have not specified a POLLOUT command. As it is set up in this program, all that is happening is that POLLIN 7, 1 (for instance), will set pin 7 to an input and get it ready to detect a logic 1 (high) when POLLMODE 2 is executed. When pin 7 goes high, it will then cause a ( POLLOUT pin-x, state ) to toggle pin-x. You set up POLLOUT by specifying the initial state of pin-x. But in the program you posted there are no POLLOUT commands.
    I'm also wondering how you are avoiding double entries with the sensors you are using. It seems you will get an output as the finger approaches the sensor, and when it is touched the output goes away. When the finger is withdrawn you will get another output from the same sensor. If you are relying on pause commands then how will you account for a caffeine junkie who will touch the keys very quickly while ol' grandma Moses will very slowly push on each one.
  • GadgetmanGadgetman Posts: 2,436
    edited 2013-10-22 10:02
    Those sensors are NOT designed for use with fingers.
    They're PROXIMITY sensors, and are designed to detect something close by that's moving in a predictable way, not something that may actually touch them.

    Because there's a gap between transmitter an receiver, it will stop detecting anything that comes too close.

    And if you have several sensors grouped together like a keypad, you risk 'false positives' with the IR beam from one transmitter being reflected to the receiver of another sensor.

    The ONLY WAY to make this work somewhat reliably at all is to set up 'walls' 1" high between the sensors so that the signal can't bounce off to the wrong place.
Sign In or Register to comment.