|
Hi Matt,
I'll try to help. :o)
First, you have to specify the type of sensor that is hooked on the port.
You do that with: type port SENSOR_TYPE
Let me know if you need to know the different values for 'type'. 3 is a
light sensor. Ports are numbered from 0 to 2 (not 1 to 3).
Having specified that you're dealing with a light sensor, the light should
turn on.
2.- Don't forget to DROP the value returned by SENSOR_READ. Otherwise, the
stack will pile up! (In a loop, let's say).
3.- I'm not sure I understand clearly what you want to do, but what I get is
that you want to read the light and act accordingly. I would do it with
something like this:
A word to set up the parameters for the light sensor:
: set_light ( port -- )
DUP 3 SWAP SENSOR_TYPE
128 SWAP SENSOR_MODE ;
A word to read the light:
: get_light ( port --- value )
DUP SENSOR_CLEAR
DUP SENSOR_READ DROP
SENSOR_VALUE ;
Now, the Condition part...
I would execute set_light followed by get_light and I would check
the returned value with IFs or CASE if there are too many values to check.
By the way, 128 for the SENSOR_MODE might not be the best set-up, unless
that's what you really want. 0 would return the raw value (wider range).
Let's stop here and let me know if I'm on the right track. If you need
anything else, let me know.
Bye
Mario
In lugnet.robotics.rcx.pbforth, Matt Jadud writes:
> I want to expand the Scheme procedure
>
> (get-light-value <sym | num>)
>
> where <sym> is one of 'PORT1, 'PORT2, 'PORT3 and num is either 0, 1, or 2
>
> to the FORTH code
>
> 128 <port> SENSOR_MODE
> <port> SENSOR_CLEAR
> <port> SENSOR_READ
> <port> SENSOR_VALUE
>
> So, if a user were to write something like
>
> (cond
> [(> (get-light-value 'PORT2) 40) (do-something)]
> [(<= (get-light-value 'PORT2) 40) (do-something-else)])
>
> it would execute the above FORTH code as it checked each condition. Do I
> understand the way the light sensor works under pbForth correctly, or is
> there something else I'd need to do to get at the value from the light
> sensor? I only ask because my tests from the console are... inconclusive.
>
> Thanks,
>
> Matt
>
> (A CC: on any replies would be appreciated!)
|
|
Message is in Reply To:
| | Light sensor question
|
| I want to expand the Scheme procedure (get-light-value <sym | num>) where <sym> is one of 'PORT1, 'PORT2, 'PORT3 and num is either 0, 1, or 2 to the FORTH code 128 <port> SENSOR_MODE <port> SENSOR_CLEAR <port> SENSOR_READ <port> SENSOR_VALUE So, if (...) (22 years ago, 15-Jul-02, to lugnet.robotics.rcx.pbforth)
|
3 Messages in This Thread:
- Entire Thread on One Page:
- Nested:
All | Brief | Compact | Dots
Linear:
All | Brief | Compact
|
|
|
|