Menu

writing to ssd1306

Help
2017-08-13
2017-08-24
<< < 1 2 (Page 2 of 2)
  • stan cartwright

    stan cartwright - 2017-08-21

    Here's my 1st attempt sprite for ili9341 code. uses sprite height-width grid but only plots lit pixels.
    I abreviated colour names or the table looked messy. https://youtu.be/qwXrzUCCAXY
    Checking only lit pixels in sprite seems smoother than ploting background pixels.

    ;sprite
    #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
    
    #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_BLACK
    GLCDfntDefaultsize = 2
    GLCDRotate (landscape)
    GLCDCLS ILI9341_BLACK
    GLCDPrint (0,0,"TEST")
    ;
    dim sprite_height,sprite_width,sprite1data,sprite_y as byte
    dim sprite_row,sprite_column,pset_sprite,py,ptr as byte
    dim sprite_x,pixel as Word
    sprite_x=100:sprite_y=100:sprite_height=12:sprite_width=12
    pset_sprite=1
    do
    for sprite_x=0 to 300
      pset_sprite=1
      sprite
      wait 1 ms
      pset_sprite=0
      sprite
    Next
    for sprite_x=300 to 0
      pset_sprite=1
      sprite
      wait 1 ms
      pset_sprite=0
      sprite
    next
    loop
    ;
    sub sprite
    ptr=0:py=sprite_y
    for sprite_row=1 to sprite_height
      for sprite_column=0 to sprite_width-1
        ReadTable spritedata,ptr,pixel
        if pset_sprite=0 then ;I tried if pset_sprite=0 and pixel<>0 then
          pset sprite_x+sprite_column,py,GLCDBackground
        else
          if pixel<>0 then
            pset sprite_x+sprite_column,py,pixel
          end if
        end if
        ptr=ptr+1
      next sprite_column
      py=py+1
    next sprite_row
    end sub
    ;
    table spritedata
    0,0,0,0,0,ye,ye,0,0,0,0,0
    0,0,0,ye,ye,wh,wh,ye,ye,0,0,0
    0,0,y,bl,bl,wh,wh,bl,bl,0,0
    0,ye,bl,bl,bl,wh,wh,bl,bl,bl,ye,0
    0,ye,bl,bl,bl,wh,wh,bl,bl,bl,ye,0
    ye,wh,wh,wh,wh,wh,wh,wh,wh,wh,wh,ye
    ye,re,re,re,re,re,re,re,re,re,re,ye
    0,ye,re,wh,wh,wh,wh,wh,wh,re,ye,0
    0,ye,re,wh,wh,wh,wh,wh,wh,re,ye,0
    0,0,ye,re,re,wh,wh,re,re,ye,0,0
    0,0,0,ye,re,re,re,re,ye,0,0,0
    0,0,0,0,0,ye,ye,0,0,0,0,0
    end table
    
     

    Last edit: stan cartwright 2017-08-21
  • Anobium

    Anobium - 2017-08-21

    Slight improvement to the sprite draw routine. 4.7-5.4ms = ~5ms with the sprite being updated in 1.2-1.9ms. Why the difference... edges of the screen take more time as there is more to update.

    At 5ms delay the ball has persistence of vision but any game playing would be very hard!

    A video

     

    Last edit: Anobium 2017-08-21
  • stan cartwright

    stan cartwright - 2017-08-24

    I managed to get a ssd1306 sprite using pset, it takes 3.8 ms for the shape in the listing not moving. Less lit pixels, the faster it plots the sprite.

    sub sprite (sprite_x,sprite_y,sprite_height,sprite_pset)
      for sprite_column=1 to sprite_height
        readtable sprite_data,sprite_column,sprite_pixel
        for sprite_bit=0 to 7
          if sprite_pixel and 1 =1 then
            pset sprite_x+sprite_column-1,sprite_y+sprite_bit,sprite_pixel and sprite_pset
          end if
          rotate sprite_pixel right
        next sprite_bit
      next sprite_column
    end sub
    table sprite_data ;sprite shape data
      b'00010000'
      b'01100011'
      b'01000011'
      b'10000000'
      b'10000000'
      b'01000011'
      b'01100011'
      b'00010000'
    end Table
    
     
  • Anobium

    Anobium - 2017-08-24

    How quaint.

    The revised sprite method in release v0.98.00 or greater updates the sprite in 1.255ms and 615us if not moving. Mega 328p@16mhz handling a 64 bit pixels where 48 pixels are not background color.

     

    Last edit: Anobium 2017-08-24
  • stan cartwright

    stan cartwright - 2017-08-24

    I had a think for a faster method...thought 2 seperate routines,1 for plot, other for erase. Would be faster, a bit. I'm only experimenting. It's quite interesting.
    The video games from the early 80's 8 bit era where a screen byte represented more than 1 pixel never used plot to draw graphics, they were usually rotated bytes. Amstrad and BBC used 1 byte per pixel in hi res colour mode, simpler.

     
    • Anobium

      Anobium - 2017-08-24

      We are very close to releasing v0.98.00. There are many new GLCD performance features that may be of interest.

       
  • stan cartwright

    stan cartwright - 2017-08-25

    Yes indeed, looking forward to .98
    Not quaint version does't work..just 3 rows. Is var1.var2 allowed? ie bit var2 of var 1
    I changed my sprite so no rotate but don't work as previous which was so simple...but not 45 us.
    https://youtu.be/ymBa2OjQjaQ
    If I have x named tables, how do I say sprite_table=table_x ? I get errors with =

    ;should work but doesn't
    sub sprite (sprite_x,sprite_y,sprite_height,sprite_pset)
      for sprite_column=1 to sprite_height
        readtable sprite_data,sprite_column,sprite_byte
        for sprite_bit=0 to 7
          if sprite_byte.sprite_bit =1 then ; and 1 =1 then
            pset sprite_x+sprite_column-1,sprite_y+sprite_bit,(sprite_byte.sprite_bit and sprite_pset)
          end if
        next sprite_bit
      next sprite_column
    end sub
    
     
<< < 1 2 (Page 2 of 2)

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.