Menu

writing to ssd1306

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

    stan cartwright - 2017-08-13

    I find it difficult to access glcd code routines. I want to move the ssd1306 hardware cursor ie where on display,not buffer,to write a byte. This sends a byte to 0,0 next to "|test" not px,row co-ords.
    The move page/column codes did work but not with GCB.
    I tried using sub Cursor_Position_SSD1306( in LocX as byte, in LocY as byte ) but I get asm errors, wrong var type value.
    I want to write sprites to the display and have the code nearly done for rotating sprite bytes across byte rows.

    #chip mega328p, 16
    ;#option explicit
    #include <glcd.h>
    #define HI2C_BAUD_RATE 400
    #define HI2C_DATA
    HI2CMode Master
    #define GLCD_TYPE GLCD_TYPE_SSD1306
    #define GLCD_I2C_Address 0x78
    ;
    dim tmp1,row,py,px,SSD1306SendByte as byte
    GLCDCLS
    GLCDDrawString (0,0,"TEST") ;this works
    ;
    locx=50:locy=32
    px=50:py=24
    row=2
    spritebyte=255
    write_sprite_byte ;sends byte to 0,0 not px,row
    do forever
    ;
    sub write_sprite_byte ;writes byte to display at row and px co-ord
      for tmp1=1 to 6
        ReadTable databytes,tmp1,SSD1306SendByte ;move hardware cursor
        writebyte
      next tmp1
      SSD1306SendByte=spritebyte
      writedata ;write 255 to display
    end sub
    ;
    sub writedata
      HI2CStart
      HI2CSend GLCD_I2C_Address
      HI2CSend 0x64
      HI2CSend SSD1306SendByte
      HI2CStop
    end sub
    ;
    sub writebyte
      HI2CStart
      HI2CSend GLCD_I2C_Address
      HI2CSend 0x00
      HI2CSend SSD1306SendByte
      HI2CStop
    end sub
    ;
    table databytes
    0x22 ;SSD1306_PAGEADDR
    row
    7
    0x21 ;SSD1306_COLUMNADDR
    px
    127
    end Table
    
     
  • Anobium

    Anobium - 2017-08-13

    I will close the other posts and link to this post when I get some time.

     
  • stan cartwright

    stan cartwright - 2017-08-13

    This should be decimal sorry, HI2CSend 0x64
    The GCB glcd includes are a great feature. I just want to move defined chars say 8x8 or 16x16 pixels around faster than using pset or line. On a ili9341 maybe multi coloured chars which maybe simpler than ssd1306. I'll percy vere,it's interesting.

     
  • stan cartwright

    stan cartwright - 2017-08-14

    This code works and sends a byte to px,row but I've reinvented the wheel. It would be nice to access glcd include to do it.

    #chip mega328p, 16
    ;#option explicit
    ;#include <glcd.h>
    #define HI2C_BAUD_RATE 400
    #define HI2C_DATA
    HI2CMode Master
    #define GLCD_TYPE GLCD_TYPE_SSD1306
    #define GLCD_I2C_Address 0x78
    
    #define SSD1306SETCONTRAST     =0x81
    #define SSD1306DISPLAYALLON_RESUME   =0xA4
    #define SSD1306DISPLAYALLON    =0xA5
    #define SSD1306NORMALDISPLAY     =0xA6
    #define SSD1306INVERTDISPLAY     =0xA7
    #define SSD1306DISPLAYOFF    =0xAE
    #define SSD1306DISPLAYON     =0xAF
    #define SSD1306SETDISPLAYOFFSET  =0xD3
    #define SSD1306SETCOMPINS    =0xDA
    #define SSD1306SETVCOMDETECT     =0xDB
    #define SSD1306SETDISPLAYCLOCKDIV  =0xD5
    #define SSD1306SETPRECHARGE    =0xD9
    #define SSD1306SETMULTIPLEX    =0xA8
    #define SSD1306SETLOWCOLUMN    =0x00
    #define SSD1306SETHIGHCOLUMN     =0x10
    #define SSD1306SETSTARTLINE    =0x40
    #define SSD1306MEMORYMODE    =0x20
    #define SSD1306COLUMNADDR    =0x21
    #define SSD1306PAGEADDR      =0x22   ; Page 0-7 represents line 0 - 7
    #define SSD1306COMSCANINC    =0xC0
    #define SSD1306COMSCANDEC    =0xC8
    #define SSD1306SEGREMAP    =0xA0 | 0x1
    #define SSD1306CHARGEPUMP    =0x8D
    #define SSD1306EXTERNALVCC     =0x1
    #define SSD1306SWITCHCAPVCC    =0x2
    ;Scrolling #defines
    #define ACTIVATESCROLL         =0x2F
    #define DEACTIVATESCROLL       =0x2E
    #define SET_VERTICALSCROLL_AREA    =0xA3
    #define RIGHT_HORIZONTALSCROLL     =0x26
    #define LEFT_HORIZONTALSCROLL    =0x27
    #define VERT_AND_RIGHTHORIZONTAL     =0x29
    #define VERT_AND_LEFTHORIZONTAL    =0x2A
    ;
    dim ptr as Word
    dim abyte,tmp1  as byte
    dim px,py,row as byte
    
    init_glcd
    
    ;
    cls_glcd
    px=100:py=24
    row=4
    ;
    movexy ; at row and px co-ord
    abyte=195
    writedata
    
    do forever
    
    ;
    sub cls_glcd
      px=0:row=0
      movexy
      abyte=0
      for ptr=1 to 1024
        writedata
      next ptr
    end sub
    ;
    sub writedata
      HI2CStart
      HI2CSend GLCD_I2C_Address
      HI2CSend 64
      HI2CSend aByte
      HI2CStop
    end sub
    ;
    sub writebyte
      HI2CStart
      HI2CSend GLCD_I2C_Address
      HI2CSend 0
      HI2CSend aByte
      HI2CStop
    end sub
    ;
    sub movexy
    abyte= SSD1306PAGEADDR
    writebyte
    abyte = row
    writebyte
    abyte = 7
    writebyte
    
    abyte= SSD1306COLUMNADDR
    writebyte
    abyte = px
    writebyte
    abyte = 127
    writebyte
    end sub
    ;
    sub init_glcd
      for tmp1 = 1 TO 25
        readtable ssd1306_init,tmp1,abyte
        writebyte
      next tmp1
    end sub
      table ssd1306_init
        SSD1306DISPLAYOFF                   ; 0xAE
        SSD1306SETDISPLAYCLOCKDIV           ; 0xD5
        0x80                                 ; the suggested ratio 0x80
        SSD1306SETMULTIPLEX                 ; 0xA8
        0x3F
        SSD1306SETDISPLAYOFFSET             ; 0xD3
        0x00                                  ; no offset
        SSD1306SETSTARTLINE              ; line #0
        SSD1306CHARGEPUMP                   ; 0x8Deeprom 9, (0x14
        0x14              ; INTERNAL VCC
        SSD1306MEMORYMODE                  ; 0x20
        0x00                                ; Horiz mode. 0x0 act like ks0108
        SSD1306SEGREMAP
        SSD1306COMSCANDEC
        SSD1306SETCOMPINS                  ; 0xDA
        0x12
        SSD1306SETCONTRAST                 ; 0x81
        0xCF              ; INTERNAL VCC
        SSD1306SETPRECHARGE                ; 0xd9
        0xF1              ; INTERNAL VCC
        SSD1306SETVCOMDETECT               ; 0xDB
        0x40
        SSD1306DISPLAYALLON_RESUME         ; 0xA4
        SSD1306NORMALDISPLAY  ; 0xA6
        SSD1306DISPLAYON                   ; 0xA4
    '  SSD1306_DISPLAYALLON               ; 0xA5
      end table
    
     
  • Anobium

    Anobium - 2017-08-14

    Yes. You are reinventing the wheel.

     
  • Anobium

    Anobium - 2017-08-14

    Here goes..

    To access the buffer simply use yourbytevariable = SSD1306_BufferAlias(n) where n is in the range of 1 to 1024 for a 128 * 64 pixels display.

    Then you want to send 6 bytes?

    Simply use:
    Cursor_Position_SSD1306 ( GLCDX, GLCDY ) 'where GLCDX and GLCDY are valid locations for the sprite
    Write_Data_SSD1306 ( yourbytevariable ) 'where yourbytevariable is a byte value from your 6 byte sprite array.

    As this will overwrite the display buffer you should consider saving the existing 6 bytes and restoring usingPixelStatus_SSD1306 ( GLCDX, GLCDY ) 'where GLCDX and GLCDY are valid locations for the target location of the sprite.

     
  • stan cartwright

    stan cartwright - 2017-08-14

    Thanks sir. It could have waited until you were back. I am reinventing the wheel, it's my way of understanding these displays,from the ground up, in GCB. Some of the init I don't understand yet,chargepump vcc etc.
    Time of posting this is NEARLY working. You can see were I'm going with the idea, then use the glcd buffer and routines instead.
    I don't know if the rotate from hi_byte to low_byte is ok. On the display 16 bytes but sprite seems rotated wrong.
    EDIT This works,yippee! I got top and bottom of sprites wrong way round.
    I'll try 16x16 next if developers interested in the project fo sprites. This is just first working code.
    edit2 Not quite right though. rotating byte left into byte 2 now. I'm confused again,doh
    I used SSD1306MEMORYMODE 0x00 ; Horiz mode. 0x0 act like ks0108
    which is not recomended in ssd1306_glcd.h

    #chip mega328p, 16
    ;#option explicit
    ;#include <glcd.h>
    #define HI2C_BAUD_RATE 400
    #define HI2C_DATA
    HI2CMode Master
    #define GLCD_TYPE GLCD_TYPE_SSD1306
    #define GLCD_I2C_Address 0x78
    ;
    #define SSD1306SETCONTRAST     =0x81
    #define SSD1306DISPLAYALLON_RESUME   =0xA4
    #define SSD1306DISPLAYALLON    =0xA5
    #define SSD1306NORMALDISPLAY     =0xA6
    #define SSD1306INVERTDISPLAY     =0xA7
    #define SSD1306DISPLAYOFF    =0xAE
    #define SSD1306DISPLAYON     =0xAF
    #define SSD1306SETDISPLAYOFFSET  =0xD3
    #define SSD1306SETCOMPINS    =0xDA
    #define SSD1306SETVCOMDETECT     =0xDB
    #define SSD1306SETDISPLAYCLOCKDIV  =0xD5
    #define SSD1306SETPRECHARGE    =0xD9
    #define SSD1306SETMULTIPLEX    =0xA8
    #define SSD1306SETLOWCOLUMN    =0x00
    #define SSD1306SETHIGHCOLUMN     =0x10
    #define SSD1306SETSTARTLINE    =0x40
    #define SSD1306MEMORYMODE    =0x20
    #define SSD1306COLUMNADDR    =0x21
    #define SSD1306PAGEADDR      =0x22   ; Page 0-7 represents line 0 - 7
    #define SSD1306COMSCANINC    =0xC0
    #define SSD1306COMSCANDEC    =0xC8
    #define SSD1306SEGREMAP    =0xA0 | 0x1
    #define SSD1306CHARGEPUMP    =0x8D
    #define SSD1306EXTERNALVCC     =0x1
    #define SSD1306SWITCHCAPVCC    =0x2
    ;Scrolling #defines
    #define ACTIVATESCROLL         =0x2F
    #define DEACTIVATESCROLL       =0x2E
    #define SET_VERTICALSCROLL_AREA    =0xA3
    #define RIGHT_HORIZONTALSCROLL     =0x26
    #define LEFT_HORIZONTALSCROLL    =0x27
    #define VERT_AND_RIGHTHORIZONTAL     =0x29
    #define VERT_AND_LEFTHORIZONTAL    =0x2A
    ;
    dim tmp1,tmp2,row,py,px as byte
    dim shiftsright,sprite1,sprite_hibyte,sprite_lowbyte,spritebyte,abyte as byte
    dim glcdbuffer(1024) as byte
    dim ptr as word
    ;
    init_glcd
    clearbuffer
    ;
    cls_glcd
    px=20:py=20
    draw_sprite
    do forever
    ;
    sub clearbuffer
    for ptr=1 to 1024
      glcdbuffer(ptr)=0
    next ptr
    end sub
    ;
    sub cls_glcd
      px=0:row=0
      move_cursor_rowpx
      abyte=0
      for ptr=1 to 1024
        writedata
      next ptr
    end sub
    ;
    sub writedata
      HI2CStart
      HI2CSend GLCD_I2C_Address
      HI2CSend 64
      HI2CSend aByte
      HI2CStop
    end sub
    ;
    sub writebyte
      HI2CStart
      HI2CSend GLCD_I2C_Address
      HI2CSend 0
      HI2CSend aByte
      HI2CStop
    end sub
    ;
    sub move_cursor_rowpx ;move display write row,column position
      abyte= SSD1306PAGEADDR
      writebyte
      abyte = row
      writebyte
      abyte = 7
      writebyte
      ;
      abyte= SSD1306COLUMNADDR
      writebyte
      abyte = px
      writebyte
      abyte = 127
      writebyte
    end sub
    ;
    sub draw_sprite
      if (py and 7)= 0 then ;sprite on row
        row=FnLSR (py,3)
        move_cursor_rowpx
        ;ptr=py And $F8 << 4 Or px
        ptr=py And 0xF8 : ptr=(FnLSl (ptr,4) or px) + 1  ;buffer position to start writing to
        for tmp1=1 to 8 ;8 vertical bytes in a horizontal row
          ReadTable sprite1, tmp1, sprite_hibyte ;this vertical sprite byte
          ;xor sprite byte to buffer byte
          glcdbuffer(ptr)=glcdbuffer(ptr) xor sprite_hibyte ;hibyte in buffer
          ;write buffer byte to display
          abyte=sprite_hibyte
          writedata
          ptr=ptr+1
        next tmp1
      else  ;sprite is between rows
        for tmp1=1 to 8 ;8 vertical bytes in a horizontal row
          ReadTable sprite1, tmp1, sprite_hibyte ;this vertical sprite byte
          shiftsleft=py And 7 ;number of left shifts
          sprite_lowbyte=0; clear it
          do until shiftsleft=0
            set c off
            rotate sprite_hibyte left
            rotate sprite_lowbyte left ;carry from hi to low byte
            shiftsleft=shiftsleft-1
          loop ;rotate byte to py screen co-ord
          ;
          ;sprite byte now is between hi and low byte
          ;
          ptr=py And 0xF8:ptr=(FnLSl (ptr,4) or px)+1 ;buffer position to start writing to
          ;
          ;xor sprite byte to buffer bytes
          glcdbuffer(ptr)=glcdbuffer(ptr) xor sprite_hibyte ;above byte in buffer
          ptr=ptr+128 ;next row in buffer
          glcdbuffer(ptr)=glcdbuffer(ptr) xor sprite_lowbyte ;below byte in buffer
          ;
          ;now write the hi low bytes from buffer to display
          row= FnLSR (py,3) ;row 0 to 7
          move_cursor_rowpx
          abyte=sprite_hibyte
          writedata ;write below byte to display from buffer
          ;
          row=row+1 ;next row of display bytes
          move_cursor_rowpx
          abyte=sprite_lowbyte
          writedata ;write above byte to display from buffer
          px=px+1
        next tmp1
      end if
    end sub
    ;
    table sprite1 ;sprite shape data
      b'11111111'
      b'11000011'
      b'10011001'
      b'10100101'
      b'10100101'
      b'10011001'
      b'11000011'
      b'11111111'
    end Table
    ;
    sub init_glcd
      for tmp1 = 1 TO 25
        readtable ssd1306_init,tmp1,abyte
        writebyte
      next tmp1
    end sub
    table ssd1306_init
      SSD1306DISPLAYOFF                   ; 0xAE
      SSD1306SETDISPLAYCLOCKDIV           ; 0xD5
      0x80                                 ; the suggested ratio 0x80
      SSD1306SETMULTIPLEX                 ; 0xA8
      0x3F
      SSD1306SETDISPLAYOFFSET             ; 0xD3
      0x00                                  ; no offset
      SSD1306SETSTARTLINE              ; line #0
      SSD1306CHARGEPUMP                   ; 0x8Deeprom 9, (0x14
      0x14              ; INTERNAL VCC
      SSD1306MEMORYMODE                  ; 0x20
      0x00                                ; Horiz mode. 0x0 act like ks0108
      SSD1306SEGREMAP
      SSD1306COMSCANDEC
      SSD1306SETCOMPINS                  ; 0xDA
      0x12
      SSD1306SETCONTRAST                 ; 0x81
      0xCF              ; INTERNAL VCC
      SSD1306SETPRECHARGE                ; 0xd9
      0xF1              ; INTERNAL VCC
      SSD1306SETVCOMDETECT               ; 0xDB
      0x40
      SSD1306DISPLAYALLON_RESUME         ; 0xA4
      SSD1306NORMALDISPLAY  ; 0xA6
      SSD1306DISPLAYON                   ; 0xA4
    '  SSD1306_DISPLAYALLON               ; 0xA5
    end table
    
     

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

    Anobium - 2017-08-15

    @Stan. If you have some time. Can you help with some developement? I have an open request for Elipse and Triangle support across all the GLCDs. Should be relatively simple. Got time to do this?

     
    • Anobium

      Anobium - 2017-08-15

      @Stan.

      Elipse: I have a program as a good starter. This has a prototype Elipse method. You should be able to port to any GLCD device. The ADC simply lets you change to the elipse parameters on the GLCD device rather than having to change the source program.
      I have not looked at FilledElipse.

      Triangle: There are many example of triangle on the internet. I do have a C++ example but I have not ported to Great Cow BASIC.
      I have not looked at FilledTriangle.

      See attached for the current working prototype.

       

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

    stan cartwright - 2017-08-15

    I'll have a go. A general flood fill for polygons would be handy but might need test pixel status.

     
    • Anobium

      Anobium - 2017-08-15

      OK. Complete one method at a time. You should keep the method in the program and do not do what I have done.... use silly variable names such as xx, yy and xx. Rename to something very specific or use temp variables that are already used by other GLCD methods.

      Good luck.

       
  • Anobium

    Anobium - 2017-08-17

    Here is a sprite program. It looks like a little pacman running across the screen!

    As I have not write a sprite routine before this took about 15mins. I took an existing method, used your table, added extendability to the tables and it truly worked first time.

    I probably have the wrong solution but it should be a good start.

    You can.
    1. Create many sprites
    2. Place sprites at any screen location
    3. Place any of the sprites at any location.

    Attached is the code and a link to the GIF of the animation. https://1drv.ms/i/s!Ase-PX_n_4cvgqMV5QlYa7eB_A71OA

    Enjoy.

     

    Last edit: Anobium 2017-08-17
  • Anobium

    Anobium - 2017-08-18

    A version for an UNO... pretty fast. The little sprite runs back and forth across the screen with some pace. If you were playing ping-pong with this sprite... you would lose every time.

    I am sure the method is not 100% correct but I am not totally sure what to expect as an outcome.

    To define a sprint you need to define in the 8 tables. This makes the system extensible.

    A sprite is pulled from each element of the 8 tables.

    Sprite 1 is at element 1 of all the tables. This is 8 * 8 of 0’s. So, you can blank things out.
    Sprite 2 is at element 2 of all the tables. This is 8 * 8 of an eye… looks like an eye to me.
    Sprite 3 is at element 3 of all the tables. This is 8 * 8 of 1’s. So, all pixels are set.

    This is the way to make extensible sprites else all the tables will have hard coded names.

    To draw a sprite. GLCDDrawSprite_SSD1306 xx, 8 , 2, GLCDBackground
    Xpos, Ypos, Sprite Number, Color (so you can invert sprites).

    Enjoy

     

    Last edit: Anobium 2017-08-18
  • Anobium

    Anobium - 2017-08-19

    A small video of the GLCD Sprite in operation and the hex for an UNO. Power, 0V and I2C are the standard device connections.

    The video does not do the OLED display or the library justice - looks ok when using the 'mark one eyeball'. :-)

    This uses the very very latest GLCD libraries for the SH1106 and SH1306. These do support faster operations and the Sprite library is not include in the standard build.

    https://1drv.ms/v/s!Ase-PX_n_4cvgqMWE3QF56WeHoGDZw

     

    Last edit: Anobium 2017-08-19
  • Anobium

    Anobium - 2017-08-19

    Bouncing ball routine... boucing in a box... wow... it is like the 1980's.

    UNO. Power, 0V and I2C are the standard device connections for a SD1306 OLED.

    This is screen shot only. No video.

     

    Last edit: Anobium 2017-08-19
    • Chris Roper

      Chris Roper - 2017-08-19

      Same method as zx81

      My first actual Computer.
      Befor that it was HP calculators and a Motorola MEK6800D2

       
      • Anobium

        Anobium - 2017-08-19

        In the day. I was part of the Acorn Dev team and the Jupiter.... a Forth interpreter in a ZX81plastic chassis.

        Those were not the days.

         
        • Chris Roper

          Chris Roper - 2017-08-19

          I worked for ZX Africa for a while - we reproduced and distributed the ZX
          software for Psion and Sinclair throughout Sub Saharan Africa.
          I think I still have a full set of cassettes for each package released for
          the ZX81, probably no longer readable.
          I do remember that Forth Interpreter, I wrote some good code with it and I
          still have a copy of "Starting Forth" next to my bed of all places :)

          On 19 August 2017 at 22:37, Anobium evanvennn@users.sf.net wrote:

          In the day. I was part of the Acorn Dev team and the Jupiter.... a Forth
          interpreter in a ZX81plastic chassis.

          Those were not the days.

          writing to ssd1306
          https://sourceforge.net/p/gcbasic/discussion/579126/thread/c197a382/?limit=250#a729/3c02/85b8


          Sent from sourceforge.net because you indicated interest in
          https://sourceforge.net/p/gcbasic/discussion/579126/

          To unsubscribe from further messages, please visit
          https://sourceforge.net/auth/subscriptions/

           
          • Anobium

            Anobium - 2017-08-20

            Amazing someone who knows about the Jupiter Ace. It is not dead... https://en.m.wikipedia.org/wiki/Jupiter_Cantab

             
            • Chris Roper

              Chris Roper - 2017-08-20

              I knew of the Jupiter but the the FORTH I used was for the ZX81.
              I cant recall the makers but I remember two versions, Tape based and ROM
              based.
              Not sure if the JUPITER FORTH was ever used on the ZX81 but FORTH in
              general was a technically brilliant but I guess doomed to obscurity :)

              EDIT:
              What I used probably was the same one afterall.

               

              Last edit: Chris Roper 2017-08-20
  • stan cartwright

    stan cartwright - 2017-08-19

    Same thing without using pset. Flickery video. Same method as zx81.The first people to do it on sinclair spectrum cleaned up. https://youtu.be/LUzWlghjH1Q
    Your sprite002a gives error 118 Variable CURRCHARVAL not explicitly declared..but it's dim'ed.
    I always get errors trying to use vars in includes.
    I'm using latest gcb with ssd1306 that came with it and latest ssd1306 you posted here for another user.

     

    Last edit: stan cartwright 2017-08-19
  • stan cartwright

    stan cartwright - 2017-08-19

    I got it working using the glcd include and using the buffer ssd1306 buffer_alias. Paste and try.

    #chip mega328p, 16
    #option explicit
    #include <glcd.h>
    #define HI2C_BAUD_RATE 400
    #define HI2C_DATA
    HI2CMode Master
    #define GLCD_TYPE GLCD_TYPE_SSD1306
    #define GLCD_I2C_Address 0x78
    ;
    ;sprite vars
    dim tmp1,row,py,px as byte
    dim shiftsleft,sprite1,sprite_hibyte,sprite_lowbyte,abyte as byte
    dim ptr as word
    ;demo vars
    dim dx,dy as byte
    dim py,px,spx,spy,oldspx,oldspy,pixel as byte
    ;
    GLCDCLS
    dx=1:dy=1:spx=20:spy=20
    px=spx:py=spy
    draw_sprite ;xor 1st time
    ;
    do ;demo
      if spx=119 then
        dx=255
      end if
      if spx=0 then
        dx=1
      end if
      if spy=55 then
        dy=255
      end if
      if spy=0 then
        dy=1
      end if
      oldspx=spx:oldspy=spy
      spx=spx+dx:spy=spy+dy
      px=oldspx:py=oldspy
      draw_sprite ;erase sprite
      px=spx:py=spy
      draw_sprite ;redraw in next position
    loop
    ;
    sub writedata
      HI2CStart
      HI2CSend GLCD_I2C_Address
      HI2CSend 64
      HI2CSend aByte
      HI2CStop
    end sub
    ;
    sub writebyte
      HI2CStart
      HI2CSend GLCD_I2C_Address
      HI2CSend 0
      HI2CSend aByte
      HI2CStop
    end sub
    ;
    sub move_cursor_rowpx ;move display write row,column position
      abyte= SSD1306_PAGEADDR
      writebyte
      abyte = row
      writebyte
      abyte = 7
      writebyte
      ;
      abyte= SSD1306_COLUMNADDR
      writebyte
      abyte = px
      writebyte
      abyte = 127
      writebyte
    end sub
    ;
    sub draw_sprite
      if (py and 7)= 0 then ;sprite on row
        row=FnLSR (py,3)
        move_cursor_rowpx
        ptr=py And 0xF8
        repeat 4
        set c off
        rotate ptr left
        end repeat
        ptr=(ptr or px)+1 ;buffer position to start writing to
    ;
        for tmp1=1 to 8 ;8 vertical bytes in a horizontal row
          ReadTable sprite1, tmp1, sprite_hibyte ;this vertical sprite byte
          ;xor sprite byte to buffer byte
          SSD1306_BufferAlias(ptr)=SSD1306_BufferAlias(ptr) xor sprite_hibyte ;hibyte in buffer
          ;write buffer byte to display
          abyte=SSD1306_BufferAlias(ptr) ;sprite_hibyte
          writedata
          ptr=ptr+1
        next tmp1
      else  ;sprite is between rows
        for tmp1=1 to 8 ;8 vertical bytes in a horizontal row
          ReadTable sprite1, tmp1, sprite_hibyte ;this vertical sprite byte
          shiftsleft=py And 7 ;number of left shifts
          sprite_lowbyte=0; clear it
          sprite_lowbyte=0; clear it
          repeat shiftsleft
            set c off
            rotate sprite_hibyte left
            rotate sprite_lowbyte left ;carry from hi to low byte
          end repeat ;rotate byte to py screen co-ord
          ;
          ;sprite byte now is between hi and low byte
          ptr=py And 0xF8
          repeat 4
          set c off
          rotate ptr left
          end repeat
          ptr=(ptr or px)+1 ;buffer position to start writing to
          ;
    ;      ptr=py And 0xF8:ptr=(FnLSl (ptr,4) or px)+1 ;buffer position to start writing to
          ;xor sprite byte to buffer bytes
          SSD1306_BufferAlias(ptr)=SSD1306_BufferAlias(ptr) xor sprite_hibyte ;above byte in buffer
          row= FnLSR (py,3) ;row 0 to 7
          move_cursor_rowpx
          abyte=SSD1306_BufferAlias(ptr) ;sprite_hibyte
          writedata ;write upper byte to display from buffer
          ;
          ptr=ptr+128 ;next row in buffer
          SSD1306_BufferAlias(ptr)=SSD1306_BufferAlias(ptr) xor sprite_lowbyte ;below byte in buffer
          ;
          row=row+1 ;next row of display bytes
          move_cursor_rowpx
          abyte=SSD1306_BufferAlias(ptr) ;sprite_lowbyte
          writedata ;write lower byte to display from buffer
          px=px+1
        next tmp1
      end if
    end sub
    ;
    table sprite1 ;sprite shape data
      b'11111111'
      b'11000011'
      b'10011001'
      b'10100101'
      b'10100101'
      b'10011001'
      b'11000011'
      b'11111111'
    end Table
    ;
    
     
  • Anobium

    Anobium - 2017-08-20

    I did try. I hooked up my scope and after each sprite draw I toggle a port.

    Optimised existing method 19-24 ms. A delay is needed to see the box bouncing.
    Your method 32-40 ms

    We have revised the library extensively and with your changes I think we can get it faster.

     

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

    stan cartwright - 2017-08-20

    I got sprite002a to work by commenting option explicit because CurrCharVal was not declared.
    It works fine. When I 1st used GCB I drew and erased a small shape from x,y by a list of pset x+1,y+1. pset x+2,y+2...etc but seemed to remember it was slow and flickered. Your sprite runs smoothly.
    I didn't work out the timing by looking at my code but thought the more pixels in the sprite the slower it would be but you plot 64 fast even non lit.
    You made the display faster by checking if the pixel had changed in the buffer and not write if the same.
    I'm going to try using pset for multicoloured ili9341 sprites but maybe writng bytes would be faster as it's not bit mapped. Is a pixel a byte or 3, one each for R,G,B? The data sheet was jibberish to me.

     
1 2 > >> (Page 1 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.