Shop OBEX P1 Docs P2 Docs Learn Events
Photocell circuit, need help! — Parallax Forums

Photocell circuit, need help!

TheForsytheTheForsythe Posts: 12
edited 2012-04-10 18:01 in BASIC Stamp
So far ive got this:

' {$STAMP BS2}
' {$PBASIC 2.5}
DEBUG "Elevator Capacity Check!", CR


LightCount VAR Byte


DO


LightCount = 0 ' Initialize counter to 0


DO : LOOP UNTIL IN13 = 1 'Wait for elevator door to close
Counter:
PAUSE 2000 'Pause for 2 seconds while people get settled


IF IN0 = 0 THEN LightCount = LightCount + 1 ' PhotoCell on, count it
IF IN1 = 0 THEN LightCount = LightCount + 1 ' PhotoCell on, count it
IF IN2 = 0 THEN LightCount = LightCount + 1 ' PhotoCell on, count it
IF IN3 = 0 THEN LightCount = LightCount + 1 ' PhotoCell on, count it
IF IN4 = 0 THEN LightCount = LightCount + 1 ' PhotoCell on, count it
IF IN5 = 0 THEN LightCount = LightCount + 1 ' PhotoCell on, count it
IF IN6 = 0 THEN LightCount = LightCount + 1 ' PhotoCell on, count it
IF IN7 = 0 THEN LightCount = LightCount + 1 ' PhotoCell on, count it
IF IN8 = 0 THEN LightCount = LightCount + 1 ' PhotoCell on, count it
IF IN9 = 0 THEN LightCount = LightCount + 1 ' PhotoCell on, count it
IF IN10 = 0 THEN LightCount = LightCount + 1 ' PhotoCell on, count it
IF IN11 = 0 THEN LightCount = LightCount + 1 ' PhotoCell on, count it
IF IN12 = 0 THEN LightCount = LightCount + 1 ' PhotoCell on, count it


DEBUG DEC LightCount, CR ' Output number of photocells that are not seeing light


IF LightCount > 9 THEN OUT15 = 1 ELSE OUT15 = 0 ' Turn on LED when 10 or more photocells see light
Hold:
DO : LOOP UNTIL IN13 = 1
OUT15 = 0
DO : LOOP WHILE IN13 = 1
DEBUG ? IN13
PAUSE 250
LOOP




I need to have the counter wait until IN13 = 1 and then start counting. This is right at the beginning of my program, here:

LightCount = 0 ' Initialize counter to 0


DO : LOOP UNTIL IN13 = 1 'Wait for elevator door to close
Counter:
PAUSE 2000 'Pause for 2 seconds while people get settled


how do i do this?!?!?!

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2012-04-10 17:11
    What's wrong with "DO : LOOP UNTIL IN13 = 1"? That will wait until IN13 is a 1. The "PAUSE 2000" will wait for 2 seconds.

    Maybe you need to first describe carefully what you're trying to do, step by step. Usually it's better to describe what you want to do rather than start writing code, then work from that description (once it looks correct) when you start to write code. Remember that a description describes your intent ... what you want to accomplish in terms of your original problem, not a prose version of code.
  • TheForsytheTheForsythe Posts: 12
    edited 2012-04-10 17:38
    okay, I am trying to create a counter that will count 13 the values of 13 different photocells and give me a 1 if more than 9 of them are blocked. I need the lightcounter not to initiste until IN13 is a 1.
  • Mike GreenMike Green Posts: 23,101
    edited 2012-04-10 18:01
    So, what's wrong with "DO : LOOP UNTIL IN13 = 1"?
Sign In or Register to comment.