|
Post by jamesbowman on Sept 6, 2017 8:44:19 GMT -8
Here's how to draw an engine speedometer using a graphic for the dial and needle:  By the way, this uses the Bitmap support from the latest (Sept 2017) GD2 library and asset converter, so you may need to update. Thanks to Simon Hilton for providing some graphics for the dial and needle:   First convert them for use with the GD2: $ gd2asset -o speedo_assets.h GaugeFace.png OffsetNeedle.png Assets report ------------- Header file: speedo_assets.h GD2 RAM used: 140800 Flash used: 12428
12K is small enough to fit in Arduino flash -- so there is no need to put them on microSD card. Create an Arduino project with the speedo_assets.h file and this: #include <EEPROM.h> #include <SPI.h> #include <GD2.h>
#include "speedo_assets.h"
void setup() { GD.begin(); LOAD_ASSETS(); bitmaps.offsetneedle.center.x = 101; }
void draw_speedo(int x, int y, int angle) { bitmaps.gaugeface.draw(x, y); bitmaps.offsetneedle.draw(x, y, angle); }
int angle = DEGREES(116);
void loop() { GD.ClearColorRGB(30, 40, 50); GD.Clear();
draw_speedo(GD.w / 2, GD.h / 2, angle); angle += DEGREES(1);
GD.swap(); }
Upload it and you'll see a nicely rotating speedometer needle. The "angle" argument in the code controls the needle position -- hook it up to your sensor to get a live position. 
|
|
|
Post by MangyDog on Sept 7, 2017 6:14:03 GMT -8
Lol thats a lot simpler than what i had going with the bmp matrixes...
|
|