### Thread: Making a counter in VS Express 2013

1. No Profile Picture
Registered User
Devshed Newbie (0 - 499 posts)

Join Date
Feb 2014
Posts
3
Rep Power
0

#### Making a counter in VS Express 2013

I am new to programming. I need some help. I have a rotary encoder with a value of 2000(dblValue= encoders value shown below) per 1 revolution. Which for me = 3 Ft I need it to be at every 1 Ft witch would be a value of 666. I need the counter to increase by 1 when the encoders value(dblValue) reaches multiples or increments of 666 . What would this code look like? Any help would be very much appreciated!!

'Read the value of Timer0.
LJUD.eGet(u3.ljhandle, LJUD.IO.GET_TIMER, 0, dblValue,
dummyDoubleArray)

At this point, dblValue now has the value from Timer0 which is your
2. No Profile Picture
Contributing User
Devshed Newbie (0 - 499 posts)

Join Date
Nov 2010
Posts
126
Rep Power
161
so the rotary device return 0 to 2000 and nothing more?

the values of 666 = 1ft
1332=2ft
1998=3ft

you can use modular arithmatic to return these values

use div 666 and you should see 1 when 666 upto 1332, 2 when 1332 upto 1998 and 3 when 1998+

does that help?

the div operator is DIV and also \ in different languages check your help documentation.

here to help

remember to close threads and rate those who help you.
3. No Profile Picture
Registered User
Devshed Newbie (0 - 499 posts)

Join Date
Feb 2014
Posts
3
Rep Power
0
Thank you so much for your response. It is greatly appreciated!

> so the rotary device return 0 to 2000 and nothing more?

The encoder will continue to rotate at 2000 resolution per revolution until it reaches a predetermined limit.
The encoder count could be as high a 2 million.

> the values of 666 = 1ft
>1332=2ft
>1998=3ft

This is absolutely correct!

>you can use modular arithmatic to return these values

> use div 666 and you should see 1 when 666 upto 1332, >2 when 1332 upto 1998 and 3 when 1998+

>does that help?

That is exactly what I need it to do. But I am still not sure exactly how to use the information you gave me. Sorry I am just to new to programming to figure it out. If you would not mind could show me exactly what the code needs to look like? Thanks for you help
4. No Profile Picture
Contributing User
Devshed Newbie (0 - 499 posts)

Join Date
Nov 2010
Posts
126
Rep Power
161
Originally Posted by Tonn80
Thank you so much for your response. It is greatly appreciated!

> so the rotary device return 0 to 2000 and nothing more?

The encoder will continue to rotate at 2000 resolution per revolution until it reaches a predetermined limit.
The encoder count could be as high a 2 million.

> the values of 666 = 1ft
>1332=2ft
>1998=3ft

This is absolutely correct!

>you can use modular arithmatic to return these values

> use div 666 and you should see 1 when 666 upto 1332, >2 when 1332 upto 1998 and 3 when 1998+

>does that help?

That is exactly what I need it to do. But I am still not sure exactly how to use the information you gave me. Sorry I am just to new to programming to figure it out. If you would not mind could show me exactly what the code needs to look like? Thanks for you help
do you know how to use the div command?

a=b div 666 or a=b/666 note the / not \

i am confusing myself \ and / appear to do the same thing, but if you look more closely you will see that one of them returns the integer part ( whole number) calculated by the division of the values.

the one that returns the integer is the DIV in some languages it is expressed as DIV in others it is the slash opposite to the one that is normally used for division. in more obsqure languages it is a function div(value,divisor), but her in vb you can use the \ i am sure. or maybe the / you will soon wee when you try it

so use

feet=rotator \ 666
feet rotator/666
or feet=rotator div 666

one of them is bound to work in our version... soory to be so vague I am on the wrong machine and thinking in a completely different language currently.

the counter part of div is mod it is the remainder or the division.. also an integer

so 3 div 2 = 1 the remainder is not a half but is 1 from 3 mod 2

something to think about when you do modular arithmatic is that a whole load of zeroes can pop up as the mod operator rolls over the boundary between a complete division and one with a remainder.

have a play with the lines i have suggested and get back to me

hope this helps
5. No Profile Picture
Registered User
Devshed Newbie (0 - 499 posts)

Join Date
Feb 2014
Posts
3
Rep Power
0
That did help Thanks for all the info