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:
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?
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.
PeterH:
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
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.
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?
Abfahrt:
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.
Thanks for all the replies, my problem was easier than I thought when I was creating the post (I blame it on sleep) ]
I'm stuck on another problem now. I also had this problem in the past and I never solved it. My array is stored in PROGMEM, so I need to use pgm_read_byte to get the data. All I get is garbare, not what I expect and get when not using PROGMEM and pgm_read_byte (aka a simple array).
This is the routine I wrote (I don't use the panel yet). The array definition is at the top of the file.
void print_char(char c, byte height, byte width) {
c = c - 32;
c = c * 6;
for (int j = 0; j < height; j++) {
for (int i = 7; i >= 0 ; i--) {
if ((pgm_read_byte(&font4x6[c + j + 3]) & (1 << i)) != 0) {
Serial.print("# ");
}
else {
Serial.print("@ ");
}
}
Serial.println("");
}
}
This is the routine I wrote (I don't use the panel yet). The array definition is at the top of the file.
Well, that's just ducky. You don't suppose that we need to see it, to confirm that the code is accessing the data correctly?
All I get is garbare, not what I expect and get when not using PROGMEM and pgm_read_byte (aka a simple array).
We can't confirm that you are reading the data correctly. In fact this statement implies that you are not. Without seeing the declaration, all we can do is wish you luck.