Starting Point System : Forum

You are not logged in.

#1 2010-03-11 19:19:03

SA4AER
New member

monitor pin state

Hello.

I've been reading the manual up and down a couple of times and I'm still a little confused.

Is it possible to monitor a pin state and depending on the state do something stand alone?
For example: monitor a digital input, and depending on the state activate/deactivate an output.
Or, measure an analog input and controlling an PWM output to control a servo.

I see that there are some event handlers, but only reset and background exists.

And can I use the IF command to check the state of an pin?

This is how I thought I would write, but it didn't work.

if pin 14 state = 1 then led on   

(else led off)


Is there some plans to implement an event handler for pinstate in the future?
Would be a lot easier just to define an event for an pinstate and then write some code when the state is true.

//Henrik

Offline

 

#2 2010-03-12 15:21:59

gremlinc5
Member

Re: monitor pin state

Try this out:

NOT Port implementation wrote:

dim myvar as int

create a variable

pin 1 in

enable pin 1 input

pin 2 out

enable pin 2 output

pin 1 state

get pin 1 logic value

let myvar = ?

put automatically the value read from pin 1 to myvar

if myvar = 0 then pin 2 high
if myvar = 1 then pin 1 low

0 become 1 or 1 become 0 (NOT Port)

Led Drive wrote:

pin 1 in
pin 1 state
if ? = 0 then led off
if ? = 1 then led on

Last edited by gremlinc5 (2010-03-12 16:14:22)


ST7FLite39 daughter board
REva 2.10
RLink 3.4
"uChameleon" as: SPI Master for debug, Analog output for sensing emulation

Offline

 

#3 2010-03-12 15:31:46

gremlinc5
Member

Re: monitor pin state

SA4AER wrote:

Is it possible to monitor a pin state and depending on the state do something stand alone?
For example: monitor a digital input, and depending on the state activate/deactivate an output.
Or, measure an analog input and controlling an PWM output to control a servo.

No, you need a software event handler on PC for Monitor Values automated usage. Use VB or C# to take Pin Monitor event to act.
Triggered digital pin are handled by hardware pin generated interrupts... and we cant change instructions in program memory, that code send only on COM the "pin 1 0" and "pin 1 1" messages.

so you need to catch them ("pin 1 0" or "pin 1 1") from COM Port by PC software to do something.

In ADC and State cases is different: use "?", mathematical and logic instructions.

SA4AER wrote:

if pin 14 state = 1 then led on   

(else led off)

"pin 14 state" is a command, it call a routin made of instruction that give you a value... I dont think that the command parser of uChameleon can handle it. Try to modify my code using "led on" and "led off" out of "pin 1 high" and "pin 1 low".

The parser can handle as manual said:
if <value A> <operator> <value B> then <command>
not
if <COMMAND> <operator> <value B> then <command>
it's quite different

Read the paragraph of "? the special variable" you will understand that Pin State value is put in ? not in the command that you give... the command do something, the ? contain something

Ciao, Michele smile

Last edited by gremlinc5 (2010-03-12 15:49:02)


ST7FLite39 daughter board
REva 2.10
RLink 3.4
"uChameleon" as: SPI Master for debug, Analog output for sensing emulation

Offline

 

#4 2010-03-12 16:15:59

gremlinc5
Member

Re: monitor pin state

SA4AER wrote:

Is there some plans to implement an event handler for pinstate in the future?
Would be a lot easier just to define an event for an pinstate and then write some code when the state is true.

This is a great idea, I hope that it could be done by Starting System wink


ST7FLite39 daughter board
REva 2.10
RLink 3.4
"uChameleon" as: SPI Master for debug, Analog output for sensing emulation

Offline

 

#5 2010-03-12 17:45:57

SA4AER
New member

Re: monitor pin state

Thanks a lot for the example.
Now it works. smile

And I put the code to check the pin in the background event and did a "background on" and got an loop so it checks it all the time like this:

onevent background
dim myvar as int
pin 9 in
pin 9 pullup on
pin 9 state
let myvar = ?
if ? = 0 then led off
if ? = 1 then led on
endevent

Offline

 

#6 2010-03-12 17:59:01

gremlinc5
Member

Re: monitor pin state

SA4AER wrote:

Thanks a lot for the example.
Now it works. smile

And I put the code to check the pin in the background event and did a "background on" and got an loop so it checks it all the time like this:

onevent background
dim myvar as int
pin 9 in
pin 9 pullup on
pin 9 state
let myvar = ?
if ? = 0 then led off
if ? = 1 then led on
endevent

dont use myvar if you use ? directly in the "if statement".
Because you are saving redundant information like:

myvar = value
if value = 0 then

myvar isnt used in this case wink

you can delete "dim" and "let" statement

onevent background
pin 9 in
pin 9 pullup on
pin 9 state
if ? = 0 then led off
if ? = 1 then led on
endevent

Last edited by gremlinc5 (2011-10-18 11:03:39)


ST7FLite39 daughter board
REva 2.10
RLink 3.4
"uChameleon" as: SPI Master for debug, Analog output for sensing emulation

Offline

 

Board footer

Powered by FluxBB

Home