Go Down

Topic: Printing fonts on HT1632 LED matrix (bitwise math and PROGMEM help!) (Read 709 times) previous topic - next topic

Abfahrt

I'm trying to implement some simple font printing on my HT1632 matrix, but I'm currently stuck at a very basic step of the implementation. I'm using stealing the fonts from the arduino-tvout library. This is how a font definition looks like:

Code: [Select]

PROGMEM const unsigned char font4x6[] = {
4,6,32,
//space
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000,
//!
0b01000000,
0b01000000,
0b01000000,
0b00000000,
0b01000000,
0b00000000,
[...]


My problem now is, how can I extract the bit information for my panel. I'm using two functions to set a LED on or off, how can I get a specific bit from the byte?

PeterH

You want to read one bit from a byte value? How about using bitRead()?
I only provide help via the forum - please do not contact me for private consultancy.

UKHeliBob

Or use the more obtuse, but somehow more satisfying, bitwise operators to mask the bits you don't want, leaving only the one(s) that you do want.  The bitRead() function is easier to understand but make sure that you read the description in the reference to understand exactly which bit you are reading.  ie bit 0 is not the leftmost bit.
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

Abfahrt


You want to read one bit from a byte value? How about using bitRead()?


I thought of that but I think it's better with bitwise math. The problem is, I can't think of a way to achieve that


Or use the more obtuse, but somehow more satisfying, bitwise operators to mask the bits you don't want, leaving only the one(s) that you do want.  The bitRead() function is easier to understand but make sure that you read the description in the reference to understand exactly which bit you are reading.  ie bit 0 is not the leftmost bit.


That's exactly what I'm looking for, the problem is I can't find anything related on the internet. What bitwise operation should I look for, for example?

PeterH


I thought of that but I think it's better with bitwise math. The problem is, I can't think of a way to achieve that


I'm not sure in which way you think it's "better". The Arduino functions save you from having to understand how to use the bitwise operators ('&', '|', '~') yourself. If you want to use the bitwise operators yourself then you will need to work out how to use them. It isn't hard, and this is a standard part of the C++ language which is well documented. But if you don't know how to use the bitwise operators and don't want to learn how, then use the helper functions that Arduino provides. Since you're only accessing single bits, the helper functions do EXACTLY the same thing as the bitwise operators would, and are slightly simpler to use.
I only provide help via the forum - please do not contact me for private consultancy.

Go Up