Converting hex to binary for 7 segments display
hi! i'm working displaying numbers on 7 segment led display multiplexing. want convert hex values binary 7 segments. have idea how in other languages java unsure how go using c/c++ in arduino. know if there's way display segments hex values. appreciated! below code:
array of hex values converted binary:
what have far:
update:
thanks help! got working using bitread()
. full code:
array of hex values converted binary:
code: [select]
char digitpatternshex[pattern_count][2] = { "3f", "06", "5b", "4f", "6e", "6b", "7d", "07", "7f", "6f", "00" };
what have far:
code: [select]
void hexatobinaryarray(char[][] hexaarray){
char digitpatterns[pattern_count][segment_count];
for(int i=0; i<pattern_count; i++){
for(int j=1; j>=0;j--){
switch(char[i][j]){ //3f = 0111111
case '0':
}
}
}
}
update:
thanks help! got working using bitread()

code: [select]
#define pattern_count 11 //number of segment patterns, 0-9 , off
#define segment_count 7 //how many segments i'm controlling
#define digit_count 4 //how many digits i'm controlling
// a,b,c,d,e,f,g
int segmentpins[segment_count] = {2,3,4,5,6,7,8};
//the pins each digit
int digitpins[] = { 9, 10, 11, 12 };
// 0 1 2 3 4 5 6 7 8 9 off
byte digitpatternshex[pattern_count] = { 0x3f, 0x06, 0x5b, 0x4f, 0x66, 0x6d, 0x7d, 0x07, 0x7f, 0x6f, 0x00 };
//counter
int counter = 0;
void setup(){
serial.begin(9600);
//init segment pins output
for(int thispin=0; thispin<segment_count; thispin++){
pinmode(segmentpins[thispin], output);
}
//init digit pins output
for(int thispin=0; thispin<digit_count; thispin++){
pinmode(digitpins[thispin], output);
}
}
//turn digits off, high because common cathode
void alldigitsoff(){
for(int thispin = 0; thispin < digit_count; thispin++){
digitalwrite(digitpins[thispin], high);
}
}
//turn specific digit on
void digiton(int digitnum){
digitalwrite(digitpins[digitnum], low);
delay(2);
}
void setpattern(int pattern){
alldigitsoff();
//data pins, 8bits
for(int thispin=0; thispin<segment_count; thispin++){
if(bitread(digitpatternshex[pattern], thispin) == 1){
digitalwrite(segmentpins[thispin], high);
}else{
digitalwrite(segmentpins[thispin], low);
}
}
}
void shownumber(int currentnumber){
//display digit right left
int digitinfront = currentnumber/10;
for(int currentdigit = 0; currentdigit < digit_count; currentdigit++){
//get number in ones place
int number = currentnumber % 10; //5
currentnumber /= 10;
setpattern(number);
digiton(currentdigit);
}
}
void loop(){
//return first 2 digits of ms, 1 sec = 1000 millisec, 1.5 sec = 1500 millisec
int currentnumber = (millis()/1000);
shownumber(currentnumber);
}
you using strings - use integers:
then in binary inside array.
code: [select]
byte digitpatternshex[pattern_count] = { 0x3f, 0x06, 0x5b, 0x4f, 0x6e, 0x6b, 0x7d, 0x07, 0x7f, 0x6f, 0x00 };
then in binary inside array.
Arduino Forum > Using Arduino > Programming Questions > Converting hex to binary for 7 segments display
arduino
Comments
Post a Comment