oled-emit
works like the standard word emit
. It blocks the calling thread, as long as the character is not written to the OLED display (less than 300 us for a 6x8 character and 400 kHz I2C). Horizontal (x) position is in pixel (0 to 127), vertical position (y) is in lines, a line consists of 8 pixels. 0, 0 is upper left corner. Larger fonts takes more than one line.
oled-emit ( Char -- ) Emits a character (writes a character to the OLED display) oled-emit? ( -- Flag ) OLED ready to get a character (I2C not busy) hook-emit ( -- a-addr ) Hooks for redirecting terminal IO on the fly hook-emit? ( -- a-addr ) oledpos! ( x y -- ) Set OLED cursor position, x (column) horizontal position, max. 127 y (row) vertical position (a line consists of 8 pixels), max. 3 for 128x32 or 7 for 128x64 displays. oledpos@ ( -- x y ) Get the current OLED cursor position oledcmd ( c-addr -- ) Send command to the OLED controller SSD1306. First byte contains the length of the command. oledclr ( -- ) Clears the OLED display, sets the cursor to 0, 0 oledfont ( u -- ) Select the font, u: 0 6x8, 1 8x8, 2 8X16 , 3 12X16 oledcolumn! ( u -- ) Write a column (8 pixels) to the current position. Increment position. Bit 0 on top oledcolumn@ ( -- u ) Read a column (8 pixels) from the current position I2Cdev ( u -- ) Sets the 7-bit I2C address I2Cput ( c-addr u -- ) c-addr buffer address for the message with lengh u to send I2Cget ( c-addr u -- ) c-addr buffer address for the message to receive I2Cputget ( a1 u1 a2 u2 -- ) a1 buffer address for the message to send, a2 buffer address for the message to receive >oled ( -- addr1 addr2 ) redirect to oled *) >term ( addr1 addr2 -- ) terminate redirection *) *) part of redirection.fs
: oled-hallo ( -- ) hook-emit @ \ save emit hook ['] oled-emit hook-emit ! \ redirect terminal to oled-emit ." Hallo Velo! " cr ." ciao" hook-emit ! \ restore old hook ;or even simpler
: oled-hallo ( -- ) >oled \ redirect terminal to oled-emit ." Hallo Velo! " cr ." ciao" >term \ terminate redirection ;or on a command line
>oled .( Hallo Velo!) >termshow date and time on OLED (see CmsisRtos#How_to_use_Tasks for a background task).
: clock ( -- ) oledclr 3 oledfont -1 -1 -1 alarm! \ set an alarm every second begin wait-alarm \ wait a second 0 0 oledpos! >oled .time >term key? until key drop ;To change the display type you have to edit the oled.h and rebuild the project:
#define OLED_4PIN_128X32 0 // the cheap one with 4 pins, Adafruit Raspberry Pi #3527 #define OLED_BONNET_128X64 1 // Adafruit Bonnet for Raspberry Pi #3531 #define OLED_FEATHER_128X32 2 // Adafruit FeatherWing #2900 #define OLED_FEATHER_128X64 3 // Adafruit FeatherWing #4650 #define OLED_OCTOPUS_128X64 4 // Octopus PIS-1277 #define OLED_LANDSCAPE 0 #define OLED_PORTRAIT 1 // configure your OLED type #define OLED_DISPLAY_TYPE OLED_OCTOPUS_128X64 #define OLED_ORIENTATION OLED_LANDSCAPE
I | Attachment | History | Action | Size | Date | Who | Comment |
---|---|---|---|---|---|---|---|
png | Codepage-850.png | r1 | manage | 2.4 K | 2021-01-05 - 21:21 | PeterSchmid | |
jpg | oled-mecrisp-cube-header.jpg | r1 | manage | 66.2 K | 2021-01-02 - 22:14 | PeterSchmid | |
jpg | oled-mecrisp-cube.JPG | r1 | manage | 5100.2 K | 2021-01-02 - 22:14 | PeterSchmid |