Shop OBEX P1 Docs P2 Docs Learn Events
experiment #16 — Parallax Forums

experiment #16

MaxbMaxb Posts: 16
edited 2005-04-08 21:47 in Learn with BlocklyProp
hi,


Still working on my project,and the thing is
I want to use the WAIT_FOR_COUNT subroutine with an analog sensor.
except that my EVENT INPUT PIN is a Dio (communication between ADC0834 and BS2)
·
Also, my proximity sends me results in DEC, stored in a BYTE(4), in that case, adc(1)
adc(1) = 80 to 115·· '·between these·results, it doesn't count for an event
But, if adc(1) is between 60 and 79, this should be count has 1 event

EventIn VAR In13 'input 13 is a Dio

adc(1)=80 to 115
80 to 115 =IsOK
IsOK·VAR BYTE

adc(1)=60 to 79
60 to 79 =anALERT
anALERT VAR BYTE· 'won't work...but it is a try

OK·CON 0······· ' results between 80 to 115
ALERT CON 1·· ' results between 60 to 79
Target CON 4· ' target count

Wait_For_Count:
IF (EventIn=·IsOk) then Wait_For_Count
eCount=eCount+1

and if I want to add 1 to eCount,
how am I doing that with an analog sensor?
where results aren't digital, but analog

thanks
maxb

Comments

  • edited 2005-04-07 16:12
    There are many ways to solve this, but I think SELECT...CASE would be the most straight forward. Below is a program that you can test. Just enter fictitious ADC values into the Debug Terminal's transmit windowpane and examine the programs response in the Debug Terminal's receive windowpane.

    If you've never used the Debug Terminal's transmit windowpane before, you can see how it is used in What's a Microcontroller v2.2, pages 120 to 121. What's a Microcontroller is available for free download from www.parallax.com -> Downloads -> Stamps in Class Tutorials. By going through the activities in this book, you will find many programming techniques that will be useful in your projects, including the SELECT...CASE statement in the program below.

    [color=#008000]' {$STAMP BS2}[/color]
    [color=#008000]' {$PBASIC 2.5}[/color]
     
    value VAR Byte
    counter VAR Nib
     
    [color=#0000ff]DEBUG[/color] "Enter values: ", [color=#800080]CR[/color]
     
    DO
     
      [color=#0000ff]DEBUG[/color] [color=#ff0000]">"[/color]
      [color=#0000ff]DEBUGIN[/color] [color=#000080]DEC[/color] value
     
      [color=#0000ff]SELECT[/color] value
     
        [color=#0000ff]CASE[/color] 80 [color=#0000ff]TO[/color] 115
          counter = 0
          [color=#0000ff]DEBUG[/color] [color=#ff0000]"everything okay, "[/color]
     
        [color=#0000ff]CASE[/color] 60 [color=#0000ff]TO[/color] 79
          counter = counter + 1
          [color=#0000ff]IF[/color] counter < 4 [color=#0000ff]THEN[/color]
            [color=#0000ff]DEBUG[/color] [color=#ff0000]"Warning, "[/color]
          [color=#0000ff]ELSEIF[/color] counter >= 4 [color=#0000ff]THEN[/color]   [color=#008000]' A simple ELSE would work too.[/color]
            [color=#0000ff]DEBUG[/color] [color=#ff0000]"Alert, alert, counter exceeded limit"[/color], [color=purple]CR[/color]
          [color=#0000ff]ENDIF[/color]
     
        [color=#0000ff]ENDSELECT[/color]
     
        [color=#0000ff]DEBUG[/color] ? counter
     
    [color=#0000ff]LOOP[/color]
    
    

    Post Edited (Andy Lindsay (Parallax)) : 4/7/2005 4:16:08 PM GMT
  • MaxbMaxb Posts: 16
    edited 2005-04-07 19:40
    first, I want to say thank you,

    I read the SELECT...CASE statement in What's a Microcontroller v2.2,, except that
    I don't have the Debug Terminal's transmit windowpane, ( I am using MacBS2 software)
    '' SelectCaseWithValues.bs2 takes numeric values you enter into the Debug Terminal''

    In that case, I tryed to replace Value by adc(1),
    like this:
    Select adc(1),
    but negative, didn't work either
    To resolve this, is there any alternative?
    what else sould I do or read..

    thanks again,
    Maxb
  • Tracy AllenTracy Allen Posts: 6,664
    edited 2005-04-08 06:45
    Download a copy of freeware "GoSerial", or "Zterm" for Macintosh OS10. These are general purpose terminal programs that can talk to the serial port. That may be the same USB-serial port you are using to program the Stamp from MacBS2. GoSerial is rudimentary, while zterm has been around evolving forever and has more bells an whistles.

    Set it up for 9600 baud, with no handshaking. That is the way the Stamp DEBUG or DEBUGIN commands work. If you want to use other baud rates, you will have to use SEROUT and SERIN on the Stamp.

    At first be careful to close the terminal program before you open MacBS2 and vice versa. Some funny things can happen when both programs are vying for the same serial port.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • MaxbMaxb Posts: 16
    edited 2005-04-08 21:47
    Hello,

    I am still having problem with my program, after trying many things...
    I want to make a demo of my system to my teacher, that's why I·cut down my program.
    My project is·a Preventive Drowsiness and Fatigue System at the Wheel. I have 1 proximity sensor,
    and 2 force sensor on the steering wheel.
    Thus, head nodding and hands' pressure on the steering wheel are my inputs.

    I am using an ADC0834, and a BS2. Results are placed in a BYTE(4).
    ·I tryed to solve my problem with Counter, Select Case, and with my experience...
    except that right now, I don't know solve this..
    I took the whole day trying to resolve this:

    Depending on the position of the head, and the pressure of hands on the steering wheel,
    the system provides different outputs.

    My main problem is, How to use analog values in a program. (data coming in, and how to use it)

    Let's say in 4 seconds, the head moves back and forth, 1-2 seconds in "Sleep position", then
    come back to a "normal" distance between the head and the seat, which
    is 4 inches===80 to 120 DEC from Proxi "adc(0)"
    The system records driver's behavior depending on how many times head is noding and
    hands' pressure decrease..
    I attached my not working code... : (
    I am sure that it is too long.. sorry, but I tryed
    thanks,

    Maxb



    DEBUG "Channel", DEC1 chan, ": ", DEC3 adc(chan), CR
    NEXT
    PAUSE 1000

    '
    [noparse][[/noparse] Fatigue ]

    Begin:
    IF adc(0) > 100 THEN First ' could be between 80 to 120, for a normal head position

    Book:
    IF adc(0) > 100 THEN Book
    PAUSE 2000
    GOSUB Fatigue_Indicator1

    Library:
    IF adc(0) > 100 THEN Library
    PAUSE 2000
    GOSUB Fatigue_Indicator2


    Street:
    IF adc(0) > 100 THEN Street
    PAUSE 2000
    GOSUB Fatigue_Indicator3


    City:
    GOSUB Fatigue_Indicator4
    GOSUB Wait_for_Count
    GOTO First


    Fatigue_Indicator1:
    Counter=0
    IF adc(0) > 60 THEN Nekst
    Nekst:
    IF adc(0) < 80 THEN Counting0
    Counting0:
    Counter = Counter + 1
    DEBUG CLS, "first sign",CR
    PAUSE 2000
    RETURN

    Fatigue_Indicator2:
    IF adc(0) > 60 THEN Nekst1
    Nekst1:
    IF adc(0) < 80 THEN Counting1
    Counting1:
    Counter = Counter + 1
    DEBUG "second sign",CR
    PAUSE 2000
    RETURN


    Fatigue_Indicator3:
    IF adc(0) > 60 THEN Nekst2
    Nekst2:
    IF adc(0) < 80 THEN Counting2
    Counting2:
    Counter = Counter + 1
    DEBUG "third sign",CR
    PAUSE 2000
    RETURN

    Fatigue_Indicator4:
    IF adc(0) > 60 THEN Nekst3
    Nekst3:
    IF adc(0) < 80 THEN Counting3
    Counting3:
    Counter = Counter + 1
    DEBUG "last sign",CR
    PAUSE 2000
    RETURN

    WAIT_for_Count:
    IF Counter = 4 THEN Light1
    RETURN

    Light1:
    DEBUG " yellow level",CR
    PAUSE 2000
    GOSUB Yellow

    GOTO Reset
    END

    '
    [noparse][[/noparse] Subroutines ]

    ' Reads ADC0834 inputs as single-ended
    ' -- input to read is passed in 'chan' (0 - 3)
Sign In or Register to comment.