Help Me Understand Segmented Digit Displays, How HEX>Binary is Used


newbie playing arduino uno starter kit, exploring language , whatnot.

so kit came single digit 7-segment (though 8-segment due decimal point) 4 digit display. unfortunately common anode variety couldn't play max7219 , 4-digit according guides saw. wired these directly arduino board pins.

the sample code came array digits 0-9
byte numcode[10] = {0xfc, 0x60, 0xda, 0xf2, 0x66, 0xb6, 0xbe, 0xe0, 0xfe, 0xf6}

it seems stupidly simple now, last 2 characters hexadecimal values can translated 8-bit binary number, , string of 8 zeros , ones corresponds 8 segments of display, telling each 1 on or off in order.
e.g., 0xda displays "2"
because da hexadecimal for:
218 in normal decimal
11011010 in 8-bit binary

8 of digit segments arranged:

displaying "2" without decimal point means
a - b - c - d - e - f - g - dp
on-on-off-on-on-off-on-off
1 - 1 - 0 - 1 - 1 - 0 - 1 - 0

well, in process of deciphering how heck hexadecimals correlated displayed number, created table possible hex values , resulting display. drudgery accompanied epiphany, meaningless work had small value. yes, hooked display , changed code see every single 0x _ _ hex combination in reality. cut work in half after realizing every other value previous 1 decimal added.
you can ogle fruits of labor here

probably could've skipped part, we're on same page. there's part of code writes number digit. need understanding bitwise math business.

code: [select]
    (j = 0; j < 8; j++)
    {
      if (numcode[i] & 1 << j) //at point equal typed in number. "&" , "<<" bitwise math things.
        digitalwrite(9 - j, low); //turn on something
      else
        digitalwrite(9 - j, high); //turn off something
    }


using 2 example, i=2, numcode[2] means 0xda, mentioned 11011010 in binary.
why getting &1 , shifted left 0 through 7 times if statement, , how condition true or false?
"2" ---- 11011010
1   ---- 00000001
2&1 --- 00000000   it seems come out false none of numcodes have decimal point "on"
<<j ?

i'm not understanding part of taking binary of what's displayed, , doing bitwise math it. how translates writing correct things pins. can explain what's going on?

waitaminute . . . .

is shifting 00000001 across input binary 1 when 1's line up? sliding across? seems on tip of tongue or brain

pin 9 checks 00000001
pin 8 checks 00000010
pin 7 checks 00000100

etc

as pins 2-9 connected segments a-dp?


Arduino Forum > Using Arduino > Programming Questions > Help Me Understand Segmented Digit Displays, How HEX>Binary is Used


arduino

Comments

Popular posts from this blog

Error: ‘for’ loop initial declarations are only allowed in C99 or C11 mode - Raspberry Pi Forums

class MPU6050 has no member named begin

missing filename after '-o'