experiment #16
Maxb
Posts: 16
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
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
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.
Post Edited (Andy Lindsay (Parallax)) : 4/7/2005 4:16:08 PM GMT
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
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
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)