Results 1 to 3 of 3
  1. #1
    10+ Posting Member
    Join Date
    Aug 2007
    Location
    united kingdom
    Posts
    13
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Switch off 7 segment displays if battery is off

    Hey Jim and everyone,

    I'm using a Mega to run a load of 7-segments displays in my 737NG MCP.

    So far so goo - they all work!

    Of course, now i want to tweak things. When the mater battery (?F) is switched off, I want to put the MAX7219s into power saving mode and switch off the displays. Accordingly, when I switch the master battery on, I want them to light up again. Here's my sketch. What I'm trying to do is loop until the battery is value "1" then get on with the rest of the sketch.

    Not working.

    Not surprising given my programming ability.

    Help!

    Thanks,

    Roger.



    #include "LedControl.h" // need the library


    LedControl lc=LedControl(12,11,10,1); // lc is our object
    // pin 12 is connected to the MAX7219 pin 1
    // pin 11 is connected to the CLK pin 13
    // pin 10 is connected to LOAD pin 12
    // 1 as we are only using 1 MAX7219
    LedControl lc1=LedControl(9,8,7,1);
    // pin 9 is connected to the MAX7219 pin 1
    // pin 8 is connected to the CLK pin 13
    // pin 7 is connected to LOAD pin 12
    // 1 as we are only using 1 MAX7219

    LedControl lc2=LedControl(6,5,4,1);
    // pin 9 is connected to the MAX7219 pin 1
    // pin 8 is connected to the CLK pin 13
    // pin 7 is connected to LOAD pin 12
    // 1 as we are only using 1 MAX7219


    String battery, digit1, alt, altold, hdg, hdgold, spd, spdold, Vspd, Vspdold, crs, crsold;
    char Vspdsign;
    int CodeIn;// used on all serial reads
    int altint, hdgint, spdint, VSint, crsint;
    int dig1 = 0;
    int dig2 = 0;
    int dig3 = 0;
    int dig4 = 0;
    int dig5 = 0;





    void setup()
    {

    // the zero refers to the MAX7219 number, it is zero for 1 chip

    lc.shutdown(0,false);// turn off power saving, enables display
    lc.setIntensity(0,15);// sets brightness (0~15 possible values)
    lc.clearDisplay(0);// clear screen

    //lc.shutdown(1,false);// turn off power saving, enables display
    //lc.setIntensity(1,12);// sets brightness (0~15 possible values)
    //lc.clearDisplay(1);// clear screen

    // the zero refers to the MAX7219 number, it is zero for 1 chip

    lc1.shutdown(0,false);// turn off power saving, enables display
    lc1.setIntensity(0,15);// sets brightness (0~15 possible values)
    lc1.clearDisplay(0);// clear screen

    //lc1.shutdown(1,false);// turn off power saving, enables display
    // lc1.setIntensity(1,12);// sets brightness (0~15 possible values)
    // lc1.clearDisplay(1);// clear screen

    // the zero refers to the MAX7219 number, it is zero for 1 chip

    lc2.shutdown(0,false);// turn off power saving, enables display
    lc2.setIntensity(0,15);// sets brightness (0~15 possible values)
    lc2.clearDisplay(0);// clear screen

    //lc2.shutdown(1,false);// turn off power saving, enables display
    //lc2.setIntensity(1,12);// sets brightness (0~15 possible values)
    //lc2.clearDisplay(1);// clear screen

    Serial.begin(115200);

    }



    void loop()
    {
    if (Serial.available())
    { // now lets check the serial buffer for any input data

    top :
    CodeIn = getChar();
    if (CodeIn == '?') {QUESTIONMARK();}// The first identifier is "?"
    if (battery = '0') {goto top;}
    CodeIn = getChar();
    if (CodeIn == '=') {EQUALS();}// The first identifier is "="
    } // end of serial available

    }// end of void loop



    char getChar()// Get a character from the serial buffer
    {
    while(Serial.available() == 0);// wait for data
    return((char)Serial.read());// Thanks Doug
    }//end of getchar

    void QUESTIONMARK(){
    delay(11);
    CodeIn = getChar();

    switch(CodeIn) {

    case'F':

    battery = "";
    battery += getChar();
    if (battery = '0'){
    lc.shutdown(0,true);// turn on power saving, enables display
    lc1.shutdown(0,true);// turn on power saving, enables display
    lc2.shutdown(0,true);// turn on power saving, enables display
    }
    if (battery = '1'){
    lc.shutdown(0,false);// turn off power saving, enables display
    lc1.shutdown(0,false);// turn off power saving, enables display
    lc2.shutdown(0,false);// turn off power saving, enables display


    }

    break;
    }


    }

    void EQUALS(){
    delay (11);
    CodeIn = getChar(); // Get another character

    switch(CodeIn) {// Now lets find what to do with it

    case 'b'://Found the second identifier "AP Altitude set"
    alt = "";
    alt += getChar();
    alt += getChar();
    alt += getChar();
    alt += getChar();
    alt += getChar();
    if (alt != altold) {WRITEALT();}
    break;

    case 'd'://Found the second identifier "AP Heading set"
    hdg = "";
    hdg += getChar();
    hdg += getChar();
    hdg += getChar();
    if (hdg != hdgold) {WRITEHDG();}
    break;

    case 'f'://Found the second identifier "AP Speed set kts"
    spd = "";
    spd += getChar();
    spd += getChar();
    spd += getChar();
    if (spd != spdold) {WRITESPD();}
    break;

    case 'c'://Found the second identifier "AP Vertical Speed set"
    Vspdsign = 0;
    Vspdsign += getChar();
    Vspd = "";
    Vspd += getChar();
    Vspd += getChar();
    Vspd += getChar();
    Vspd += getChar();
    if (Vspd != Vspdold) {WRITEVSPD();}
    break;

    case 'e'://Found the second identifier "AP Course set"
    crs = "";
    crs += getChar();
    crs += getChar();
    crs += getChar();
    if (crs != crsold) {WRITECRS();}
    break;
    }
    }//end of EQUALS


    void WRITEALT()
    {
    //Say alt is 21500
    altint = alt.toInt();
    dig1 = altint / 10000; //dig1 = 2 (Int 21500/10000)
    altint = altint - (dig1 * 10000); //altint = 21500 - 20000 = 1500
    dig2 = altint / 1000; //dig2 = 1 (Int 1500/1000)
    altint = altint - (dig2 * 1000); // altint = 1500 - 1000 = 500
    dig3 = altint /100; //dig3 = 5 int 500/100
    altint = altint - (dig3 * 100); //altint = 500 - 5*100 = 0
    dig4 = altint /10;
    altint = altint - (dig4 * 10);
    dig5 = altint;

    lc1.setDigit(0,3,dig1,true);// (Max7219 number, Digit to use, What to Display, on or off)
    lc1.setDigit(0,4,dig2,true);
    lc1.setDigit(0,5,dig3,true);
    lc1.setDigit(0,6,dig4,true);
    lc1.setDigit(0,7,dig5,true);
    }


    void WRITEHDG()
    {
    //Say hdg is 268
    hdgint = hdg.toInt();
    dig1 = hdgint / 100; //dig1 = 2 (Int 268/100)
    hdgint = hdgint - (dig1 * 100); //hdg = 268 - 200 = 68
    dig2 = hdgint / 10; //dig2 = 6 (Int 68/10)
    dig3 = hdgint - (dig2 *10); //dig3 = 8 (68 - (6*10))

    lc1.setDigit(0,0,dig1,true);// (Max7219 number, Digit to use, What to Display, on or off)
    lc1.setDigit(0,1,dig2,true);
    lc1.setDigit(0,2,dig3,true);
    }

    void WRITESPD()
    {
    //Say spd is 250
    spdint = spd.toInt();
    dig1 = spdint / 100; //dig1 = 2 (Int 250/100)
    spdint = spdint - (dig1 * 100); //hdg = 250 - 200 = 50
    dig2 = spdint / 10; //dig2 = 5 (Int 50/10)
    dig3 = spdint - (dig2 *10); //dig3 = 0 (50 - (5*10))

    lc.setDigit(0,3,dig1,true);// (Max7219 number, Digit to use, What to Display, on or off)
    lc.setDigit(0,4,dig2,true);
    lc.setDigit(0,5,dig3,true);
    }

    void WRITEVSPD()
    {
    lc2.setChar(0,3,' ',false);
    //Say VS is -1500
    VSint = Vspd.toInt();

    //VSint = VSint - (dig1 * 10000); //VSint = 21500 - 20000 = 1500
    dig2 = VSint / 1000; //dig2 = 1 (Int 1500/1000)
    VSint = VSint - (dig2 * 1000); // VSint = 1500 - 1000 = 500
    dig3 = VSint /100; //dig 3 = 500/100 = 5
    VSint = VSint - (dig3 * 100); //VSint = = 500 - 5*100 = 0
    dig4 = VSint/10;
    VSint = VSint - (dig4 * 10);
    dig5 = VSint;

    if (Vspdsign != '-')
    {
    lc2.setChar(0,0,' ',false);

    }
    else
    {
    lc2.setChar(0,0,'-',true);// (Max7219 number, Digit to use, What to Display, on or off)
    }

    lc2.setDigit(0,1,dig2,true);
    lc2.setDigit(0,2,dig3,true);
    lc2.setDigit(0,3,dig4,true);
    lc2.setDigit(0,4,dig5,true);
    }

    void WRITECRS()
    {
    //Say crs is 268
    crsint = crs.toInt();
    dig1 = crsint / 100; //dig1 = 2 (Int 268/100)
    crsint = crsint - (dig1 * 100); //hdg = 268 - 200 = 68
    dig2 = crsint / 10; //dig2 = 6 (Int 68/10)
    dig3 = crsint - (dig2 *10); //dig3 = 8 (68 - (6*10))

    lc.setDigit(0,0,dig1,true);// (Max7219 number, Digit to use, What to Display, on or off)
    lc.setDigit(0,1,dig2,true);
    lc.setDigit(0,2,dig3,true);
    }

  2. #2
    150+ Forum Groupie
    Join Date
    Nov 2013
    Location
    Evansville, Indiana
    Posts
    243
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: Switch off 7 segment displays if battery is off

    FatCharlie,

    if (battery = '0'){ <----needs 2 equal signs
    if (battery == '0'){ <--- is equal to

    If it still doesn't work, try "0" using double quotes.

    Get rid of the delay(11), it shouldn't be needed.

    ~Fess
    I will only ever be, half the Geek that I wished I was.
    TheGeekForge.Com

  3. #3
    10+ Posting Member
    Join Date
    Aug 2007
    Location
    united kingdom
    Posts
    13
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: Switch off 7 segment displays if battery is off

    Quote Originally Posted by Fess_ter View Post
    FatCharlie,

    if (battery = '0'){ <----needs 2 equal signs
    if (battery == '0'){ <--- is equal to

    If it still doesn't work, try "0" using double quotes.

    Get rid of the delay(11), it shouldn't be needed.

    ~Fess
    Thanks Fess, I'll have a go.