Rotating arrow

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 5.
To post in this forum you must have a registered copy of Flowcode 5 or higher.

Moderator: Benj

Post Reply
Bobw
Posts: 157
Joined: Sat Jan 22, 2011 10:39 pm
Location: Michigan
Has thanked: 6 times
Been thanked: 27 times
Contact:

Rotating arrow

Post 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

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Rotating arrow

Post 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.

User avatar
JonnyW
Posts: 1230
Joined: Fri Oct 29, 2010 9:13 am
Location: Matrix Multimedia Ltd
Has thanked: 63 times
Been thanked: 290 times
Contact:

Re: Rotating arrow

Post 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

User avatar
JohnCrow
Valued Contributor
Valued Contributor
Posts: 1367
Joined: Wed Sep 19, 2007 1:21 pm
Location: Lincolnshire
Has thanked: 364 times
Been thanked: 716 times

Re: Rotating arrow

Post by JohnCrow »

Hi Bob
Im working on a program with a similar requirment, and the background method works for me with very litle flicker.
1 in 10 people understand binary, the other one doesn't !

Bobw
Posts: 157
Joined: Sat Jan 22, 2011 10:39 pm
Location: Michigan
Has thanked: 6 times
Been thanked: 27 times
Contact:

Re: Rotating arrow

Post 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

User avatar
JonnyW
Posts: 1230
Joined: Fri Oct 29, 2010 9:13 am
Location: Matrix Multimedia Ltd
Has thanked: 63 times
Been thanked: 290 times
Contact:

Re: Rotating arrow

Post 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

Bobw
Posts: 157
Joined: Sat Jan 22, 2011 10:39 pm
Location: Michigan
Has thanked: 6 times
Been thanked: 27 times
Contact:

Re: Rotating arrow

Post 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

User avatar
JonnyW
Posts: 1230
Joined: Fri Oct 29, 2010 9:13 am
Location: Matrix Multimedia Ltd
Has thanked: 63 times
Been thanked: 290 times
Contact:

Re: Rotating arrow

Post 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

Post Reply