Pages: [1]   Go Down
Author Topic: 7segment displays with max7219 chip counting  (Read 721 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

hello all,

i have just started using arduino from various other C based controllers and have a uni project that im trying to sort out asap.  i have 2 7segment displays mutiplexed up and working fine, but im trying to work out how i can have a potentiometer connected to control the digits that have been displayed.  The hardwear works fine its just my coding abilities that i am having trouble with. In fact i have no idea how to start. 
any help would be gratefully appreciated

cheers
   
adknott
Logged

USA
Offline Offline
Jr. Member
**
Karma: 0
Posts: 78
ClockTHREE Rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I'd start by writing a function

// set/unset segments of display identified by display_id
void seven_seg_contol(int display_id, uint8_t bits){
    for(uint8_t i = 0; i < 8; i++){
    if(1 && bits >> i){
        // light up the ith segment of display_id
    }
    else{
        // unlight the ith segment of display_id
    }
}

Then define constants for each digit.
const uint8_t ONE = 0b00010001;  // just for instance I don't really know which bits to be on or off
const uint8_t TWO = 0b01111001;  // just for instance I don't really know which bits to be on or off
...

Then write a higher level function display

void seven_seg_display(uint8_t two_digit_num){
   // ones digit
    switch(two_digit_num % 10){
    case 1:
        seven_set_control(ONES_DIGIT, ONE);
        break;
    ...
    }
   // tens digit
    switch(two_digit_num / 10){
    case 1:
        seven_set_control(TENS_DIGIT, ONE);
        break;
    ...
    }
}
Logged

Pages: [1]   Go Up
Jump to: