Page 1 of 1

Rotating arrow

Posted: Thu Mar 15, 2012 5:06 am
by Bobw
I have not done any hardware as of yet, just playing with the simulator and a Glcd.
I want to draw an arrow and have it rotate. Do I need to clear the old arrow before drawing the new one, or better yet just issue a single clear command that will clear all the pixels the arrow could possibly occupy, before drawing the new one?

Bob

Re: Rotating arrow

Posted: Thu Mar 15, 2012 10:16 am
by Benj
Hello Bob,

One way would be to create a macro to draw the arrow and include a parameter to set the foreground colour. This way you draw your arrow in the foreground colour and then when you want to move your arrow you first redraw it in the same location using the background colour as your foreground colour before then redrawing in the normal foreground colour again.

Another way might be to draw a solid box over the arrow the same colour as the background.

Hope this helps.

Re: Rotating arrow

Posted: Thu Mar 15, 2012 10:43 am
by JonnyW
Hi. You will most likely get a noticeable flicker if you draw anything but the bare minimum pixels. For this reason I would draw the arrow in the background colour as Ben suggests and not blank an area of the screen.

There are ways of introducing a flicker free mechanism, but these take up memory which is very valuable in the PIC.

Jonny

Re: Rotating arrow

Posted: Thu Mar 15, 2012 11:13 am
by JohnCrow
Hi Bob
Im working on a program with a similar requirment, and the background method works for me with very litle flicker.

Re: Rotating arrow

Posted: Sat Mar 17, 2012 7:03 am
by Bobw
I was wanting to represent degrees of rotation in 10 degree steps, 36 different arrows to draw.
Will have to play around with it some more. I like the shift fore and background color idea, will have to give it a go.
Still not 100% sold on using an Glcd over a 4x20 lcd, would be nice if I can figure out the arrow part.
Have learned the hard way that planning is everything.

Bob

Re: Rotating arrow

Posted: Sat Mar 17, 2012 11:29 pm
by JonnyW
Have learned the hard way that planning is everything.
Yeah, unfortunately most coders learn that way!

Do you mean figure the arrow part on the gLCD (i.e. the trig involved) or displaying a rotating arrow on a 4x20 LCD? If its the latter, I'd be surprised if you can get the resolution right. When I want to show something is running in a single text character I tend to step through the '| \ - /' characters and I suspect you would be reduced to this kind of look for an arrow.

Good luck with it, keep us posted with what you manage,

Jonny

Re: Rotating arrow

Posted: Tue Mar 20, 2012 4:22 pm
by Bobw
Jonny,
I was going to use a Glcg and draw the arrow. Easy enough to draw, but to make the transitions from one to the next takes several code lines per arrow. 3 lines to draw each arrow and 3 more to erase it before drawing the next one. I would need 36 different arrows total.
I may just use a 4x20 LCD and use a linear display for position. There will be a digital display of position as well.
I have already built this project once before, and want to add some "BLING" to it this time. Using a quad encoder this time, ability to manually move the rotor as well as auto via pic control, ability to self calibrate ( move to home position).

The use of a Glcd would have just looked more professional.
Hard part is finding a quad encoder and wheel that will fit in a tight space. I only have about 6-7mm head room for it.
Will have to post a picture of what I am up against.

Bob

Re: Rotating arrow

Posted: Tue Mar 20, 2012 5:05 pm
by JonnyW
OK, I think I get you. With lines (vector graphics) there is no need to draw individual arrows though. The following pseudo-code will draw an arrow at any angle:

Code: Select all

  macro draw_arrow(x0, y0, length, angle)
    .x1 = .x0 + cos(angle) * length
    .y1 = .y0 + sin(angle) * length
    draw_line(.x0, .y0, .x1, .y1)
    .x0 = .x1 - (cos(angle - 15) * .length / 4)
    .y0 = .y1 - (sin(angle - 15) * .length / 4)
    draw_line(.x0, .y0, .x1, .y1)
    .x0 = .x1 - (cos(angle + 15) * .length / 4)
    .y0 = .y1 - (sin(angle + 15) * .length / 4)
    draw_line(.x0, .y0, .x1, .y1)
In Flowcode v5, this is 3 calculation boxes and 3 component macro calls. You would then need some functions to do cos and sin (usually a look-up table, though you can do it without this if ROM is tight).

Good luck with your project,

Jonny