Been trying to figure out a good way to either inc or dec a variable by some multiple. Anyone have a good suggestion? Things I've been trying just have not worked as the variable gets mutiplied for instance x10 but the contents of variable gets multiplied not incremented by 10.
i:=0
inc(i);
i:=i*10
i now = 10
so we do this several more times and results are
i=110
i=1110
i=11110
just don't do what I need. I understand why.
I'm trying to do increments as such 210,220,230,240 etc....
and so on
I need to perform this with dec also using negative numbers so I can decrement a number as such 240,230,220,210 etc...
This is for my encoder project which is working great but only inc or dec a value by one. I need to change to different multiples to make setting the final value faster. multiples of 1, 10, 100, 1000, 10000, 100000....
A keypad entry will be added shortly but for now got to get the encoder to do it's job.
Thanks, help is appreciated.
Brian
how to inc or dec number by multiple of 10, 100, 1000....?
I'm not a Pascal (BASIC) user, but would this work?
Looks like you are multiplying instead of incrementing (or decrementing).
Code: Select all
i:= 0
i:= i+10
i:= i-10
i:= i+210
Why pay for overpriced toys when you can have
professional grade tools for FREE!!!
professional grade tools for FREE!!!
Hi, you could do something like this:
I am no sure though if this is what you had in mind...
Addendum: in following posts it became clear that "Inc" only accepts one paremeter: the variable to be incremented. The increment value is always "1". Sorry for the inconvenience.
But: one can always write ones own "Inc" and "Dec" functions or procedures (which will have to have another name of course...).
Code: Select all
var MyNumber, Delta: integer;
...
Delta = -1000;
...
...
inc(MyNumber, Delta);
...
...
inc(MyNumber, Delta);
...
...
Addendum: in following posts it became clear that "Inc" only accepts one paremeter: the variable to be incremented. The increment value is always "1". Sorry for the inconvenience.
But: one can always write ones own "Inc" and "Dec" functions or procedures (which will have to have another name of course...).
Last edited by Dany on 23 Dec 2008 20:56, edited 1 time in total.
Kind regards, Dany.
Forget your perfect offering. There is a crack in everything, that's how the light gets in... (L. Cohen)
Remember when we were young? We shone like the sun. (David Gilmour)
Forget your perfect offering. There is a crack in everything, that's how the light gets in... (L. Cohen)
Remember when we were young? We shone like the sun. (David Gilmour)
Wow, thanks, didn't know it could do that either.Dany wrote:Hi, you could do something like this:I am no sure though if this is what you had in mind...Code: Select all
var MyNumber, Delta: integer; ... Delta = -1000; ... ... inc(MyNumber, Delta); ... ... inc(MyNumber, Delta); ... ...
Thanks much,
edited:
Tried this but the compiler is not accepting it.
expects a ) but found a ,
inc(MyNumber, Delta);
.....................^.................
would have been nice though.
Brian
Looks like you are right. Guess I should not be programming so early in the morning. I did mult and suppose to addrmteo wrote:I'm not a Pascal (BASIC) user, but would this work?Looks like you are multiplying instead of incrementing (or decrementing).Code: Select all
i:= 0 i:= i+10 i:= i-10 i:= i+210
I'll see if I can correct this now.
Thanks much,
Brian
Well I got it working. Now just have to get a button to cycle through what ever multipiler I want to use.
Curious as whether you can run two interrupt routines at the same time?
Or as my encoder is using 2 interrupts (detects change on B port pins) if I can attach a button(switch) also to one of those same port pins?
Thanks
Brian
Curious as whether you can run two interrupt routines at the same time?
Or as my encoder is using 2 interrupts (detects change on B port pins) if I can attach a button(switch) also to one of those same port pins?
Thanks
Brian
You can have as many interrupts as you want (within limits). Just poll the interrupt flags in the ISR to determine the source of the interrupt. Which PIC are you using?
With the PIC24s and dsPICs, it is a lot nicer and easier as these devices have vectored interrupts.
With the PIC24s and dsPICs, it is a lot nicer and easier as these devices have vectored interrupts.
Why pay for overpriced toys when you can have
professional grade tools for FREE!!!
professional grade tools for FREE!!!
Its an 18f4620. Just I think I might be hardpressed to use another one because my encoder and Lcd share PortB. I could move if I have to the lcd over to another port but would have to make an interface board for it to plug into the Easypic5 board. Not a difficult thing as I've done most of my external devices like that. I'm still fairly new to using interrupts but starting to get a feel for them. I think I'll hold off on using pic24s and dspics for now until I get a better grasp of the ones I have.
Thanks again,
Brian
Thanks again,
Brian
Well, apparently mP cannot either. I was blinded and/or mislead by the other Pascal compiler I use (for PC): Delphi. Sorry for the inconvenience.rmteo wrote:Dany, interesting that mP supports that construct.
Unfortunately (for me), mB does not.
But: one can always write ones own "Inc" and "Dec" functions or procedures (which will have to have another name of course...).
Kind regards, Dany.
Forget your perfect offering. There is a crack in everything, that's how the light gets in... (L. Cohen)
Remember when we were young? We shone like the sun. (David Gilmour)
Forget your perfect offering. There is a crack in everything, that's how the light gets in... (L. Cohen)
Remember when we were young? We shone like the sun. (David Gilmour)