I am working on a project involving an Aduino and screen.

As i was going through the u8glib (Arduino Monochrome Graphics Library for LCDs and OLEDs), something caught my attention:

#define U8G_ESC_DLY(x) 255, ((x) & 0x7f)
#define U8G_ESC_CS(x) 255, (0xd0 | ((x)&0x0f))

How can i interpret this macro for a given x value ?

  • 1
    Macro's aren't really code. They just work on the plain text. Just look at them as if they are a "find and replace" function in a text editor.
    – Gerben
    Nov 15 '16 at 11:17

How can i interpret this macro for a given x value ?

As normal. First expand the macro, and then worry about what the comma means in context. In an expression the result is the expression on the right of the comma. In a function call it stands in for two arguments. Just look at where it's used and that's what it will mean.

  • U8G_ESC_DLY(10), /* delay 10 ms */ so in a concept like this, i can omit the left side of the comma.But can you elaborate on the function call part ? How can you define a function like this in the first place ?
    – Dogus Ural
    Nov 15 '16 at 7:19
  • somefunctionthattakestwoargs(SOMEMACROWITHACOMMA) Nov 15 '16 at 7:21
  • The library uses that to create a list of commands to initialize the display. See where it is used. As you can see, they store an array of commands that have to be send to initialize. So in this case, send 255 and then send the last x (with the first bit set to zero).
    – Gerben
    Nov 15 '16 at 11:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.