Hi guys. I've posted some oled code that I thought may be useful and thought a "scope for 08m2" would be nice as seems lots of people have trouble with getting a working example to start off with it's tedious so posted template code but for picaxe with 1K scratchpad. I got this code from a light meter I posted and compiled to 255 bytes 08m2. I didn't use x2 stuff like power or rotate or set bit so it was portable but I just get a few pixels.
Anyone other than hippy (don't spoil it) want to point out my errors and then it could be handy code example to play with. 1st time I used bptr. You can assume the oled is working and set up so I didn't post the boring stuff. inefficient 1st draft ...so don't point it out...please
The code should erase display old data-2nd array, then display new data-1st array,then swap 1st array with 2nd then fill 1st array with new data and repeat.
Anyone other than hippy (don't spoil it) want to point out my errors and then it could be handy code example to play with. 1st time I used bptr. You can assume the oled is working and set up so I didn't post the boring stuff. inefficient 1st draft ...so don't point it out...please
Code:
gosub InitialiseLcd
gosub ClearDisplay
adcsetup = %0000000000000010
for bptr=0 to 127 ;get 127 samples and store twice in 2 128 byte arrays
readadc a.0,sample
@bptr = sample/4 ;fit to screen res and store sample in 1st array
push bptr ;save array pointer
bptr=bptr+127
@bptr=sample/4 ;store same sample in 2nd array
pop bptr ;restore array pointer
next bptr
;
start:
for bptr =0 to 127 ; number of bytes in array
push bptr ;save pointer
bptr=bptr+128 ;point to 2nd array
sample=@bptr/8 ;screen row
pop bptr ;restore pointer to 1st array
hi2cout (0,SSD1306_PAGEADDR)
hi2cout (0,sample) ;set screen row 0 to 7
hi2cout (0,7) ;control code thingy
;
hi2cout (0,SSD1306_COLUMNADDR)
hi2cout (0,bptr) ;set column 0 to 127
hi2cout (0,127) ;control code thingy
;
hi2cout (64,0) ;erase old screen data in 1st array
;
;sample=@bptr
pixel=@bptr and 7 ;pixel in byte
screen_byte=1
do until pixel=1
screen_byte=screen_byte*2 ;get pixel position in byte!!! maybe wrong this bit "not a pun"
dec pixel
loop
;
hi2cout (0,SSD1306_PAGEADDR)
hi2cout (0,sample) ;set row 0 to 7
hi2cout (0,7) ;control code thingy
;
hi2cout (0,SSD1306_COLUMNADDR)
hi2cout (0,bptr) ;set columnn 0 to 127
hi2cout (0,127) ;control code thingy
;
hi2cout (64,screen_byte) ;plot new screen data in 1st array as pixel
next bptr
;get new samples into 1st array
for bptr=0 to 127
temp=@bptr ; get old sample
bptr=bptr+128 ; point to 2nd array
@bptr=temp ; copy last data from 1st array to old data in 2nd array for erasing on screen
bptr=bptr-128 ; restore bptr
;
readadc a.0,sample ;get new sample
sample=sample/4 ;scale to screen res
@bptr=sample ;store new data in 1st array
next bptr
;
goto start
Last edited: