Some code to put a pre-defined shape on glcd ili9341 and erase it,
This follows on from Anobiums'ssd1306 sprite that used pset.
Any improvements welcome.
The idea is plot the sprite data but if 0 then skip when ploting and erasing. https://youtu.be/3c5cp1mMzRs
;simplespriteusingpsetonILI9341GLCD#chip mega328p, 16#option explicit#include<glcd.h>;#define GLCD_TYPE GLCD_TYPE_ILI9341#define GLCD_DC portb.2#define GLCD_CS portd.7#define GLCD_RESET portd.4 ; Reset line Tie high..not needed#define GLCD_DO portb.3 ; MOSI SDI#define GLCD_SCK portb.5 ; SCK#define ILI9341_HardwareSPI ' remove/comment out if you want to use software SPI.#define GLCD_EXTENDEDFONTSET1;;nowrenamecolourstomakeiteasiertosetupspritedata#define bk ILI9341_BLACK#define re ILI9341_RED#define gr ILI9341_GREEN#define bl ILI9341_BLUE#define wh ILI9341_WHITE#define pu ILI9341_PURPLE#define ye ILI9341_YELLOW#define cy ILI9341_CYAN#define dg ILI9341_D_GRAY#define lg ILI9341_L_GRAY#define si ILI9341_SILVER#define ma ILI9341_MAROON#define ol ILI9341_OLIVE#define li ILI9341_LIME#define aq ILI9341_AQUA#define te ILI9341_TEAL#define na ILI9341_NAVY#define fu ILI9341_FUCHSIA;GLCDBackground=ILI9341_BLACKGLCDRotate(landscape)GLCDCLSILI9341_BLACK;dimdx,dyasintegerdimtempasworddimsprite_height,sprite_widthasbyte;heightandwidthofspriteinpixelsdimspritedataasbyte;datatomakespritedimsprite_yasbyte;spritescreenypositiondimsprite_xasWord;spritexposition-screen320widedimsprite_row,sprite_column,py,ptrasbyte;spritesubvarsdimpset_spriteasbyte;0erasesprite.1plotspritedimpixelasword;datavalforspritepixel-0noplotoreraseelseit'spixellit;;demovarsdimdx,dy,spx,spy,oldspx,oldspyasbytedimspx,oldspxasword;displayis320pixelsspx=100:spy=100:sprite_height=12:sprite_width=12dx=1:dy=1;do;demomovingspriteifspx>(319-sprite_width)thendx=-1endififspx=0thendx=1endififspy>(239-sprite_height)thendy=-1endififspy=0thendy=1endifoldspx=spx:oldspy=spyspx=spx+dx:spy=spy+dypset_sprite=0;erasespritesprite(oldspx,oldspy,sprite_width,sprite_height,pset_sprite)sprite_x=spx:sprite_y=spypset_sprite=1;plotspritesprite(spx,spy,sprite_width,sprite_height,pset_sprite);redrawinnextpositionloop;enddemo;subsprite(sprite_x,sprite_y,sprite_width,sprite_height,pset_sprite)ptr=0:py=sprite_yforsprite_row=1tosprite_height;spriterowsforsprite_column=0tosprite_width-1;spritecolumnsReadTablespritedata,ptr,pixel;spritepixelifpset_sprite=0andpixel<>0then;eraseonandpixelwaslitpsetsprite_x+sprite_column,py,GLCDBackgroundelseifpixel<>0then;pixellitnotbackgroundpsetsprite_x+sprite_column,py,pixelendifendifptr=ptr+1nextsprite_columnpy=py+1nextsprite_rowendsub;tablespritedata0,0,0,0,0,ye,ye,0,0,0,0,00,0,0,ye,ye,wh,wh,ye,ye,0,0,00,0,y,bl,bl,wh,wh,bl,bl,0,00,ye,bl,bl,bl,wh,wh,bl,bl,bl,ye,00,ye,bl,bl,bl,wh,wh,bl,bl,bl,ye,0ye,wh,wh,wh,wh,wh,wh,wh,wh,wh,wh,yeye,re,re,re,re,re,re,re,re,re,re,ye0,ye,re,wh,wh,wh,wh,wh,wh,re,ye,00,ye,re,wh,wh,wh,wh,wh,wh,re,ye,00,0,ye,re,re,wh,wh,re,re,ye,0,00,0,0,ye,re,re,re,re,ye,0,0,00,0,0,0,0,ye,ye,0,0,0,0,0endtable
Last edit: stan cartwright 2017-08-23
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Some code to put a pre-defined shape on glcd ili9341 and erase it,
This follows on from Anobiums'ssd1306 sprite that used pset.
Any improvements welcome.
The idea is plot the sprite data but if 0 then skip when ploting and erasing.
https://youtu.be/3c5cp1mMzRs
Last edit: stan cartwright 2017-08-23