Coder Social home page Coder Social logo

Comments (4)

daschr avatar daschr commented on May 18, 2024

Well you can access the buffer directly. See https://github.com/daschr/pico-ssd1306/blob/main/ssd1306.c#L143 to get an idea how to access a pixel. The buffer is horizontally line by line encoded where (0,0) is the upper left corner.
Also, one byte encodes 8 pixels where the most significant bit represents the bigger y.
F.e: pixel (8,56) is encoded at byte=buffer[8 + (56/8)] and then (byte>>(y%8))&1.

You could use something like this:

uint8_t ssd1306_get_pixel(ssd1306_t *p, uint32_t x, uint32_t y){
    const uint8_t p = (p->buffer[x+p->width*(y>>3)]>>(y&0x7))&1;
    return p;
}

from pico-ssd1306.

NonRidiculousAdjective avatar NonRidiculousAdjective commented on May 18, 2024

Hey, sorry for the late reply, so if I understand it correctly, you store the pixels in an array of uint8_t, where each 1 or 0 is a pixel except the most significant digit, which stores the y value?

from pico-ssd1306.

NonRidiculousAdjective avatar NonRidiculousAdjective commented on May 18, 2024

Do you like reserve the most significant nibble for all 64 lines of y ?

from pico-ssd1306.

daschr avatar daschr commented on May 18, 2024

I think my explanation was a bad.
The RAM stores the display data in pages of 128 x 1byte. Each bytes encodes the 8 vertically neighbouring pixels.
See https://cdn-shop.adafruit.com/datasheets/SSD1306.pdf page 25.
So if you want to access the pixel at (x,y), you first calculate the page (y/8, since each byte encodes 8 vertically pixels) and multiplicate it by 128 (size of a page). Then you add x to for getting the position of the byte in the array. Now, you have to access the y%8 bit of the byte, which encodes the pixel.

from pico-ssd1306.

Related Issues (12)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.