Page 2 of 7 FirstFirst 123456 ... LastLast
Results 11 to 20 of 68

Thread: NEW COM RADIO CODE FOR 7 SEGMENT_DIODE REQUEST! (BRAINSTORMING)

  1. #11
    150+ Forum Groupie
    Join Date
    Apr 2011
    Location
    United States of America
    Posts
    233

    Re: NEW COM RADIO CODE FOR 7 SEGMENT_DIODE REQUEST! (BRAINSTORMING)

    The line:
    if (comAnode < 13) {comAnode = comAnode + 1;}else{ comAnode = 9;}

    Since the segments (a-g) are assigned to pins 2-8, the anodes for the four number blocks are assigned to 9 through 12. Because of the for-next loop within the LEDstates method, it will make five passes (one pass will include the decimal point) to determine the Case - which highlightes need to disregard the decimal point. The corrected statement should be:

    if (i <> 3){ // com1[3] = decimal point
    if (comAnode < 13) {comAnode = comAnode + 1;}else{ comAnode = 9;}
    }
    Now that I corrected the statement, I'll resume the explanation. Ok, so we know there will be five passes in the for-next loop to determine which case to use in order to assign the proper segment array values. We also know that by the time it finishes the last case (case 9) , it will have determined what the number is, assigned the proper segment array value to light up the correct segments, then fetched the LEDsegments method to write the appropriate segment pins (2-8 ) HIGH (refer to EDIT).

    After it writes the pins high, the last line of the LEDsegments method tells it to fetch the WriteAnode method. This is where comAnode comes into play... remember at the first pass of the for-next loop the value of comAnode was 9; therefore, it will digitalWrite (9, HIGH) displaying the number found from com1[i] for period determined by the following delay statement. Then it turn it off. At the second pass of the for-next loop, it will digitalWrite (10, HIGH) which is your second 7-segment led block. This continues to
    the last 7-segment led block which has the anode pin on pin12 i.e.,
    digitalWrite (12, HIGH). After it has lit the last led block (pin12), it returns to the first led block on pin9 and repeats the process - which highlights another error I made!! Correction below:

    if (i <> 3){ // com1[3] = decimal point
    if (comAnode < 12) {comAnode = comAnode + 1;}else{ comAnode = 9;}
    }

    The reason it was changed to 12 is because the statement is after the Select Case. Since it is after it, comAnode's value could have been assigned to pin13 and executed the LEDstates, LEDsegments, and WriteAnode before reverting back to pin9 - which would have thrown everything out of whack!

    I hope this all made sense.

    Edit: You're gonna love this...
    If you're using the common anode type 7-segments, you'll want to assign the values for a-g LOW to allow current to pass. That said,
    WRONG:
    case 0:
    led[7] = (1,1,1,1,1,1,0); //{a,b,c,d,e,f,g} creates '0'

    CORRECTED:
    case 0:
    led[7] = (0,0,0,0,0,0,1); //{a,b,c,d,e,f,g} creates '0'

    Yet another reason I should build & test the theory!

  2. #12
    150+ Forum Groupie BuzziBi's Avatar
    Join Date
    Mar 2013
    Location
    Norway
    Posts
    276

    Re: NEW COM RADIO CODE FOR 7 SEGMENT_DIODE REQUEST! (BRAINSTORMING)

    James.
    First of all, thanks for the explanation regarding the comAnode. (I will come back to that )
    I guess if you are going to use the "comAnode" in the "void loop()}", we must tell where the comAnodes are?
    So...... Do one set them up with "int", in an Arrey or in the void setup()}

    With int :
    Code:
    int Pin2 = 2;
    int Pin3 = 3; 
    int Pin4 = 4;
    int Pin5 = 5;
    int Pin6 = 6;
    int Pin7 = 7;
    int Pin8 = 8;
    
    
    int Com1Anode1 = 9;
    int Com1Anode2 = 10;
    int Com1Anode3 = 11;
    int Com1Anode4 = 12;
    int Com1Anode5 = 13;
    void setup()}
    
    void loop()}
    In an Arrey:
    Code:
    int comAnode[] = {9, 10, 11, 12, 13};
    void setup()}
    
    void loop()}
    Or in the void setup()}
    Code:
    int comAnode;
    void setup(){
    
    
    pinMode (Pin2, OUTPUT); //THe segment pins
    pinMode (Pin3, OUTPUT);
    pinMode (Pin4, OUTPUT);
    pinMode (Pin5, OUTPUT);
    pinMode (Pin6, OUTPUT);
    pinMode (Pin7, OUTPUT);
    pinMode (Pin8, OUTPUT);
    
    for (int comAnode = 9; comAnode < 14; comAnode++)
        {
       pinMode(comAnode, OUTPUT);
       digitalWrite(comAnode, HIGH);  
        }
    }
    void loop() {
    Now let me come back to the "explanation regarding the comAnode".
    I thought I had it regarding the common anode/common catode, but lets clarify!
    seg.gif
    As I can se it
    (with common catode), the common catode must be LOW and the segments HIGH,
    to show any given digit.
    Code:
    digitalWrite (comAnode1, LOW);
    led[7] = (1,1,1,1,1,1,0); //{a,b,c,d,e,f,g} creates '0'
    

    and (with common anode), the common anode, the anode must be HIGH and the segments LOW,
    to show any given digit.
    Code:
    digitalWrite (comAnode1, HIGH);
    led[7] = (0,0,0,0,0,0,1); //{a,b,c,d,e,f,g} creates '0'
    

    Am I correct in this, or?


    One more thing:
    I cant get the:
    Code:
    if (i <> 3){   // com1[3] = decimal point
    to compile!
    But this one does:
    Code:
    if (i < 3 > 3 ){   // com1[3] = decimal point
    Life was hard, but then came Windows 7.
    Now we can fly! --------
    --------

  3. #13
    150+ Forum Groupie
    Join Date
    Apr 2011
    Location
    United States of America
    Posts
    233

    Re: NEW COM RADIO CODE FOR 7 SEGMENT_DIODE REQUEST! (BRAINSTORMING)

    With regard to the common anode/cathode bit you wrote about at the end of your post- you are absolutely correct.

    However, the comAnode will not be in array because there is no need to store the value. It will be assigned a value at the top of the sketch: int comAnode = 9;

    Then, it will get incremented by 1 in the LEDstates method... if i does not equal three.
    It also resets the value to nine if comAnode equals twelve (because in my example, my anodes are on pins 9,10,11 & 12):

    Corrected (i <>3)... I was speaking visual basic - oops!

    if (i != 3){ // com1[3] = decimal point
    if (comAnode < 12) {comAnode = comAnode + 1;}else{ comAnode = 9;}
    }

    Setup for common anode:
    Code:
    int Pin2 = 2;
    int Pin3 = 3; 
    int Pin4 = 4;
    int Pin5 = 5;
    int Pin6 = 6;
    int Pin7 = 7;
    int Pin8 = 8;
    int comAnode = 9;  // must define starting pin;  this pin will increase to 12 in the LEDstates method
    
    void setup(){
    for (int i = 2; i < 9; i++)
        {
    pinMode (i, OUTPUT);
    digitalWrite(i, HIGH); 
    }
    
    for (int i = 9; i < 13; i++)
        {
       pinMode(i, OUTPUT);
       digitalWrite(i, LOW);  
        }
    }
    Setup for common cathode
    Code:
    int Pin2 = 2;
    int Pin3 = 3; 
    int Pin4 = 4;
    int Pin5 = 5;
    int Pin6 = 6;
    int Pin7 = 7;
    int Pin8 = 8;
    int comAnode = 9;  // must define starting pin;  this pin will increase to 12 in the LEDstates method
    
    void setup(){
    for (int i = 2; i < 9; i++)
        {
    pinMode (i, OUTPUT);
    digitalWrite(i, LOW); 
    }
    
    for (int i = 9; i < 13; i++)
        {
       pinMode(i, OUTPUT);
       digitalWrite(i, HIGH);  
        }
    }

  4. #14
    150+ Forum Groupie BuzziBi's Avatar
    Join Date
    Mar 2013
    Location
    Norway
    Posts
    276

    Re: NEW COM RADIO CODE FOR 7 SEGMENT_DIODE REQUEST! (BRAINSTORMING)

    So if I've got 4 comon anodes:
    Code:
    int Pin2 = 2;
    int Pin3 = 3; 
    int Pin4 = 4;
    int Pin5 = 5;
    int Pin6 = 6;
    int Pin7 = 7;
    int Pin8 = 8;
    int comAnode9 = 9; // must define starting pin; this pin will increase to 12 in the LEDstates method
    int comAnode10 = 10;
    int comAnode11 = 11;
    int comAnode12 = 12;
    
    void setup(){
    for (int i = 2; i < 9; i++)
    {
    pinMode (i, OUTPUT);
    digitalWrite(i, LOW); 
    }
    
    for (int i = 9; i < 13; i++)
    {
    pinMode(i, OUTPUT);
    digitalWrite(i, HIGH); 
    }
    }
    Life was hard, but then came Windows 7.
    Now we can fly! --------
    --------

  5. #15
    150+ Forum Groupie
    Join Date
    Apr 2011
    Location
    United States of America
    Posts
    233

    Re: NEW COM RADIO CODE FOR 7 SEGMENT_DIODE REQUEST! (BRAINSTORMING)

    No. You only need int comAnode = 9 ... not comAnode9, comAnode10, etc. Why? Because comAnode will increase by 1 in the last line of the LEDstates method. But before it increases by one, it will told to go to WriteAnode method:

    void WriteAnode() {
    digitalWrite (comAnode , HIGH);
    delay(30); // adjust accordingly to avoid eye detected number blink
    digitalWrite (comAnode , LOW);
    }// end WriteAnode

  6. #16
    150+ Forum Groupie BuzziBi's Avatar
    Join Date
    Mar 2013
    Location
    Norway
    Posts
    276

    Re: NEW COM RADIO CODE FOR 7 SEGMENT_DIODE REQUEST! (BRAINSTORMING)

    OOOOOOoooooo!!
    So I guess this line: for (int i = 9; i < 13; i++)
    already hawe stated where the comaAanodes are?
    On Pin 9, 10, 11 and 12.
    is that correct?
    Life was hard, but then came Windows 7.
    Now we can fly! --------
    --------

  7. #17
    150+ Forum Groupie
    Join Date
    Apr 2011
    Location
    United States of America
    Posts
    233

    Re: NEW COM RADIO CODE FOR 7 SEGMENT_DIODE REQUEST! (BRAINSTORMING)

    Yup, you got it!

  8. #18
    150+ Forum Groupie BuzziBi's Avatar
    Join Date
    Mar 2013
    Location
    Norway
    Posts
    276

    Re: NEW COM RADIO CODE FOR 7 SEGMENT_DIODE REQUEST! (BRAINSTORMING)

    Next question
    If you uses this line in the void setup, for the Segments and the Anode/Catode:
    Code:
    for (int i = 2; i < 9; i++) // The segments    
    {
    pinMode (i, OUTPUT);
    digitalWrite(i, LOW); }
    
    for (int i = 9; i < 13; i++) // The Anode/Catode
        {
       pinMode(i, OUTPUT);
       digitalWrite(i, HIGH);  
        }
    Would'nt this create problems when we in the loop adds this:
    (when we simultaneously use (i) for the segments).
    Code:
    if (i != 3){ // com1[3] = decimal point //
    if (comAnode < 12) {comAnode = comAnode + 1;}else{ comAnode = 9;}
    }
    What I wonder is, whether or not, (is this the name?) the "Parameter" for the Anode/Catode,must be given another name, both in the void setup and the void loop!
    Like this:
    Code:
        for (int i = 2; i < 9; i++) // The segments    
    {
    pinMode (i, OUTPUT);
    digitalWrite(i, LOW); }
    
    for (int x = 9; x < 13; x++) // The Anode/Catode
        {
       pinMode(x, OUTPUT);
       digitalWrite(x, HIGH);  
    
        }
    
    if (x != 3){ // com1[3] = decimal point //
    if (comAnode < 12) {comAnode = comAnode + 1;}else{ comAnode = 9;}
    }
    Life was hard, but then came Windows 7.
    Now we can fly! --------
    --------

  9. #19
    150+ Forum Groupie
    Join Date
    Apr 2011
    Location
    United States of America
    Posts
    233

    Re: NEW COM RADIO CODE FOR 7 SEGMENT_DIODE REQUEST! (BRAINSTORMING)

    In your first example - No. I purposely wrote it as such to illustrate that fact. The variable "i" is declared by the for-next loop using for (int i = 2; i < 9; i++){ //stuff here} ; Consequently, the variable "i" is confined only within the brackets of that for-next loop and that loop only. If you attempted "i" outside of the for-next loop, you would have a build error stating "i" was not declared. For that reason, variables which are to be used throughout the void loop(), void LEDstates(), etc. must be declared at the top of the sketch.

    Now, if you have a for-next loop WITHIN another for-next loop then you would have to use another variable name.

  10. #20
    150+ Forum Groupie BuzziBi's Avatar
    Join Date
    Mar 2013
    Location
    Norway
    Posts
    276

    Re: NEW COM RADIO CODE FOR 7 SEGMENT_DIODE REQUEST! (BRAINSTORMING)

    Hi James.
    I'm absolutely stuck'ed here (So, nothing new)
    Take a loock at the code, can this sum it up so far?
    I just wonder, how can I write a test line in the sketch, just to see if I can light up a couple of displays?
    I just dont know what to use in a "digitalWrite"
    Code:
    int com1[7];
    int led[7];
    
    
    int Pin2 = 2; //The segment pins A, B, C, D, E, F, G.
    int Pin3 = 3; 
    int Pin4 = 4;
    int Pin5 = 5;
    int Pin6 = 6;
    int Pin7 = 7;
    int Pin8 = 8;
    
    
    int comAnode = 9; /* Define starting pin for the common Anodes (comAnode). 
    This will including pin 10, 11, 12, with the LEDstates method, in the line: for (int i = 9; i < 13; i++)              
    */
    
    
    void setup(){
      
                                   // NOTE!
    for (int i = 2; i < 9; i++)    // Writes the Segmengt pins 2,3,4,5,6,7, and 8, 
        {                         // "LOW" (For common Catode Displays). 
    pinMode (i, OUTPUT);          // Change it to "HIGH" (For the common Anode Displays).
    digitalWrite(i, LOW);        // This will turn the Segment pins "OFF". 
    }
    
    
    
    
    for (int i = 9; i < 13; i++)     // NOTE!
        {                            // Writes the common Anode/Catode.
       pinMode(i, OUTPUT);           // Make it "HIGH" (For The common Catode Displays),
       digitalWrite(i, HIGH);       // change it to "LOW" (For The common Anode Displays).
        }
    
    
    Serial.begin(115200);  
    }
    
    
    void loop() {
      
    }
    void LEDstates(){
    
    
     for (int i = 1; i < 6; i++)  {  // does not read first digit com1 [0] or last digit com1 [6]
          if (i != 3){ // does not read the decimal point 
          if (comAnode < 12) {comAnode = comAnode + 1;}else{ comAnode = 9;}
          }
    
    
        switch (com1 [i]) {
        case 0:
           led[7] = (1,1,1,1,1,1,0);  //{a,b,c,d,e,f,g}  creates '0'
        LightSEG();
        
        case 1:
          led[7] = (0,1,1,0,0,0,0);  //{a,b,c,d,e,f,g}  creates '1'
        LightSEG();
    
    
        case 2:
          led[7] = (1,1,0,1,1,0,1);  //{a,b,c,d,e,f,g}  creates '2'
        LightSEG();
    
    
        case 3:
          led[7] = (1,1,1,0,0,0,1);  //{a,b,c,d,e,f,g}  creates '3'
        LightSEG();
    
    
        case 4:
          led[7] = (0,1,1,0,0,1,1);  //{a,b,c,d,e,f,g}  creates '4'
        LightSEG();
    
    
        case 5:
          led[7] = (1,0,1,1,0,1,1);  //{a,b,c,d,e,f,g}  creates '5'
        LightSEG();
    
    
        case 6:
          led[7] = (1,0,1,1,1,1,1);  //{a,b,c,d,e,f,g}  creates '6'
        LightSEG();
    
    
        case 7:
          led[7] = (1,1,1,0,0,0,0);  //{a,b,c,d,e,f,g}  creates '7'
        LightSEG();
    
    
        case 8:
          led[7] = (1,1,1,1,1,1,1);  //{a,b,c,d,e,f,g}  creates '8'
        LightSEG();
    
    
        case 9:
          led[7] = (1,1,1,0,0,1,1);  //{a,b,c,d,e,f,g}  creates '9'
        LightSEG();
      }
     }
    } // end LEDstates
    
    
    void LightSEG(){
    
    
     digitalWrite (Pin2, led[0]);  // a segment
     digitalWrite (Pin3, led[1]);  // b segment
     digitalWrite (Pin4, led[2]);  // c segment
     digitalWrite (Pin5, led[3]);  // d segment
     digitalWrite (Pin6, led[4]);  // e segment
     digitalWrite (Pin7, led[5]);  // f segment
     digitalWrite (Pin8, led[6]);  // g segment
     WriteAnode();
    } //end LightSEG
    
    
    void WriteAnode() {
        digitalWrite (comAnode , HIGH);
        delay(30); // adjust accordingly to avoid eye detected number blink
        digitalWrite (comAnode , LOW);
    } // end WriteAnode
    Attached Files Attached Files
    Life was hard, but then came Windows 7.
    Now we can fly! --------
    --------

Page 2 of 7 FirstFirst 123456 ... LastLast