Making a calculator using an Arduino

Updated :

The new keypad circuit is still no done. Today, when I was finish my afternoon run, going home, and in the kitchen, I was thinking about my code, and it occur to me that I made a executable bug in the ADD routine. I was installing the carry into the next array box, that may explain some garbage data in my display. No add right , screw up numbers, etc. Instead to place the carry into the add_number[] array, I just simply use a "temp" variable. Use the / and % to isolate the unit number.

Example : temp = add_number / 10; <-- the carry calculation

  • temp = 12 / 10 --> 1 or 8 / 10 --> 0 *
    Extract Unit : add_number = add_number % 10;
    add_number = 12 % 10 --- > 2 or 8 % 10 ---> 8 <-- the unit to be display.
    Add also, I fix the "cosmetic" bug. Was display : 00001234 Now : 1234
    I change the interrupt routine : I just add : digitalWrite(latchkeypin, HIGH); And remove that line from the read_keypad routine.
    *Next post is the new and final code. <-- I think *
    Here the old code :
    *_</em></em> <em><em><em>*if ( over_flow == 0)     {            for (int i=0;i<8;i++)       {         add_number[i] = add_number[i+1] + add_number[i] + digit_number[i];         if (add_number[i] > 0x09 )         {           add_number[i+1] = 1;           display_data[i] = word ( ( i + 1 ), ( add_number[i] - 10 ));         }         else         {             display_data[i] = word ( ( i + 1 ) , add_number[i]);         }              }              // check for over flow       if ( add_number[8] > 0)       {              over_flow = 1;         digit_number[0] = 0;                display_data[0] = 0x010B;         for ( int i=1;i<8;i++)         {           digit_number[i] = 0;           display_data[i] = word( (i+1), 0x0F );                      }              keystate = 0;         over_flow = 1;         add_flag = 1;              display_the_numbers();                }       else       {         keystate = 0;         over_flow = 0;         add_flag = 1;         display_the_numbers();       }          }*</em></em></em> <em><em>_*

The new Add section
*_</em></em> <em><em><em>*// Choise 2 - the add section void add_section() {     byte temp;       if ( over_flow == 0 )     {       // The Add logic        temp = 0; // the carry variable       for (int i=0;i<8;i++)       {         add_number[i] = temp + add_number[i] + digit_number[i];         temp = add_number[i] / 10;         add_number[i] = add_number[i] % 10;         display_data[i] = word ( ( i + 1 ) , add_number[i] );       }              // check for over flow       if ( temp != 0)       {              over_flow = 1;         digit_number[0] = 0;                display_data[0] = 0x010B;         for ( int i=1;i<8;i++)         {           digit_number[i] = 0;           display_data[i] = word( (i+1), 0x0F );                      }              keystate = 0;         over_flow = 1;         add_flag = 1;              display_the_numbers();                }       else       {         /*         For a cleaner display by removing         the zero's on the left side of the number         */         for (int i=7;i>0;i--)         {           if (add_number[i] == 0)           {             display_data[i] = word ( ( i + 1 ) , 0x0F );           }           else           {             break;           }                  }                  keystate = 0;         over_flow = 0;         add_flag = 1;         display_the_numbers();       }          } }*</em></em></em> <em><em>_*