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
Rotating arrow
Moderator: Benj
- 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
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.
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.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
- 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
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
There are ways of introducing a flicker free mechanism, but these take up memory which is very valuable in the PIC.
Jonny
- JohnCrow
- 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
Hi Bob
Im working on a program with a similar requirment, and the background method works for me with very litle flicker.
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 !
-
- Posts: 157
- Joined: Sat Jan 22, 2011 10:39 pm
- Location: Michigan
- Has thanked: 6 times
- Been thanked: 27 times
- Contact:
Re: Rotating arrow
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
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
- 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
Yeah, unfortunately most coders learn that way!Have learned the hard way that planning is everything.
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
-
- Posts: 157
- Joined: Sat Jan 22, 2011 10:39 pm
- Location: Michigan
- Has thanked: 6 times
- Been thanked: 27 times
- Contact:
Re: Rotating arrow
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
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
- 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
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:
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
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)
Good luck with your project,
Jonny