|
|
OLED Paint - Drawing program using the touch panel
As the module under testing has a touch panel, here's a little drawing program made with 4DGL that uses the touch functions that are available. For touch panel usage 4DGL has function for getting the state of the panel (pressed/dragged/released) and X and Y coordinates.
The drawing programs is just simply made so that it fetches the X and Y coordinates from the touch panel and draws a dot at that place. As the screen isn't cleared in the loop the image stays and you can draw. There is a button for clearing the screen. The fix_coordinates function is just a quick fix I put together to correct the X and Y readings from the panel so the dot is drawn under the pen at all times. There was some offset without it when going near the edges and the drawn dot started to drift away from under the pen so it needed some correcting.

OLED Paint
Below is a video of the program running on the module:
#platform "uOLED-32024-P1T"
/*************************************************
* MetkuMods - /
*
* Filename: drawing_program_2.4dg
* Created: 2009/06/11
* Author: Aki Korhonen
* Description: Simple drawing program
**************************************************/
#inherit "4DGL_16bitColours.fnc"
var x, y, state;
var x2, y2;
func fix_coordinates()
if(x < 81)
x2 := (((810-x*10)/81) * 20)/10;
x := x + x2;
else
x2 := (((1590-(1590-(x*10-810)))/159) * 30)/10;
x := x - x2;
endif
if(y < 172)
y2 := (((1720-y*10)/172) * 20)/10;
y := y + y2;
else
y2 := (((1480-(1480-(y*10-810)))/148) * 30)/10 - 18;
y := y - y2;
endif
endfunc
func main()
gfx_Cls();
touch_Set(TOUCH_ENABLE);
while(1)
gfx_Set(PEN_SIZE, 1);
gfx_Rectangle(20, 20, 220, 280, BLUE);
gfx_Button(UP, 55, 280, GRAY, BLACK, FONT1, 4, 1, "CLEAR");
txt_MoveCursor(0, 5);
print("OLED Paint");
state := touch_Get(TOUCH_STATUS);
x := touch_Get(TOUCH_GETX);
y := touch_Get(TOUCH_GETY);
fix_coordinates();
if(55 < x && x < 185 && 280 < y && y < 300)
pause(100);
gfx_Set(PEN_SIZE, 0);
gfx_Rectangle(21, 21, 219, 279, BLACK);
else
gfx_Set(PEN_SIZE, 0);
gfx_Circle(x, y, 1, WHITE);
endif
wend
endfunc
| | Pages: 1 2 3 4 5 6 7 8 9 10 11 12 | |


Content in english!
Sisältö suomeksi!
