Go Down

### Topic: Making a calculator using an Arduino (Read 19256 times)previous topic - next topic

#### Techone

##### Mar 30, 2012, 04:29 pm
Hi guys;

As the title said, I am trying to do a programing exersise to make a basic calculator using a telephone keypad and 8 7 segments display.

Here what I am planning to do :

Enter a number, add it, and sum it. Easy to say, but no so easy to be done.

I will be learning to do a program do do just that.  I know, it all depend of  the type of hardware.

I did the display and the keypad circuit. I did a test program for the display and the keypad to see if it is working.

The display : Use MAX7219 to display the 8 7 segments display. The display is a CC type. Test code will be in the next post.
The keypad : A telephone keypad, with a commun connection, <-- A Row will indicated a LOW at the location of that row being press, same thing goes for the colum. I made an interrupt pulse - HIGH for any key press. If I need that pusle. A test code will be in the next post.

Next, it is to combine them and code it.

Any help, some codes, pseudo-code is very welcome. I will try to do mine version, and figure this out. Any ideas of coding this project will be nice.

#### Techone

#1
##### Mar 30, 2012, 04:36 pm
Here a picture of the display and the test code. For the new guys or to the one who are not familiar with the MAX7219. This info came from the datasheet. http://www.datasheetcatalog.org/datasheet/maxim/MAX7219-MAX7221.pdf

Code: [Select]
`const byte datapin = 12;const byte latchpin = 11;const byte clockpin = 10;void setup(){ pinMode(datapin, OUTPUT); pinMode(latchpin, OUTPUT); pinMode(clockpin, OUTPUT); // set : Normal Mode digitalWrite(latchpin, LOW); shiftOut(datapin, clockpin, MSBFIRST, 0x0C ); shiftOut(datapin, clockpin, MSBFIRST, 0x01 ); digitalWrite(latchpin, HIGH); delay(5); // set : Normal Operation digitalWrite(latchpin, LOW); shiftOut(datapin, clockpin, MSBFIRST, 0x0F ); shiftOut(datapin, clockpin, MSBFIRST, 0x00 ); digitalWrite(latchpin, HIGH); delay(5); // set : Intensity digitalWrite(latchpin, LOW); shiftOut(datapin, clockpin, MSBFIRST, 0x0A ); shiftOut(datapin, clockpin, MSBFIRST, 0x0B ); digitalWrite(latchpin, HIGH); delay(5); // set : Numbers of digits digitalWrite(latchpin, LOW); shiftOut(datapin, clockpin, MSBFIRST, 0x0B ); shiftOut(datapin, clockpin, MSBFIRST, 0x07 ); digitalWrite(latchpin, HIGH); delay(5); // set : Decode Mode Register digitalWrite(latchpin, LOW); shiftOut(datapin, clockpin, MSBFIRST, 0x09 ); shiftOut(datapin, clockpin, MSBFIRST, 0xFF ); digitalWrite(latchpin, HIGH); }void loop(){ byte j; for (int i=1;i<9;i++) {    digitalWrite(latchpin, LOW);   shiftOut(datapin, clockpin, MSBFIRST, i );   shiftOut(datapin, clockpin, MSBFIRST, i );   digitalWrite(latchpin, HIGH);   delay(5); } delay(2000); j = 8; for (int i=1;i<9;i++) {   digitalWrite(latchpin, LOW);   shiftOut(datapin, clockpin, MSBFIRST, i );   shiftOut(datapin, clockpin, MSBFIRST, j );   digitalWrite(latchpin, HIGH);   delay(5);   j--; } delay(2000); }  `

#### Techone

#2
##### Mar 30, 2012, 04:39 pm
Here a picture of the keypad and the test code.

Code: [Select]
`//**************************************************************////  Name    : shiftIn Example 1.1                              ////  Author  : Carlyn Maw                                        ////  Date    : 25 Jan, 2007                                      ////  Version : 1.0                                               ////  Notes   : Code for using a CD4021B Shift Register    ////          :                                                   ////****************************************************************// Modify code by Techone from the original// This code is just an example of using a telephone keypad// with the use of 4021 and using shiftIn() function.// Use only shiftIn () function/*     --------------     1      2    3  <-- Row 1       4      5    6  <-- Row 2     7      8    9  <-- Row 3     *      0    #  <-- Row 4     -------------    /\     /\   /\     |     |     |    Col 1 Col 2 Col 3        Telephone keypad pinouts      gnd, col 2, col 1, row 4, col 3, row 3, row 2, row 1   4021 connection :      gnd   : pin 1   col 1 : pin 15   col 2 : pin 14   col 3 : pin 13   row 1 : pin 4   row 2 : pin 5   row 3 : pin 6   row 4 : pin 7         All keypad pins are with a 1 K pull-up resistor.      All keypad outputs goes to a 74LS04 to be inverted.   At outputs of the 74LS04 going into the 4021, place a    pull-up resistor of 4.7 K. It is for TTL --> CMOS       And connected all row output to a 74LS20 for   a interrupt signal output or any keypress output signal.   Work like : 0 - no ley               1 - a key is being press         Tigh Serial In - pin 11 to gnd.      Therefore the outputs bits are : R4-R3-R2-R1-C3-C2-C1          Button = 1 = 0b00001001 = 0x09 = 9   Button = 2 = 0b00001010 = 0x0A = 10   Button = 3 = 0b00001100 = 0x0C = 12   Button = 4 = 0b00010001 = 0x11 = 17   Button = 5 = 0b00010010 = 0x12 = 18   Button = 6 = 0b00010100 = 0x14 = 20   Button = 7 = 0b00100001 = 0x21 = 33   Button = 8 = 0b00100010 = 0x22 = 34   Button = 9 = 0b00100100 = 0x24 = 36   Button = * = 0b01000001 = 0x41 = 65   Button = 0 = 0b01000010 = 0x42 = 66   Button = # = 0b01000100 = 0x44 = 68   Button = None press = 0b00000000 = 0x00 = 0 *///define where your pins areint latchPin = 11;int dataPin = 12;int clockPin = 10;//Define variables to hold the data //for shift register.byte switchVar;void setup() {  //start serial  Serial.begin(9600);  //define pin modes  pinMode(latchPin, OUTPUT);  pinMode(clockPin, OUTPUT);   pinMode(dataPin, INPUT);  }void loop() {  //Pulse the latch pin:  //set it to 1 to collect parallel data  digitalWrite(latchPin,HIGH);  //set it to 1 to collect parallel data, wait  delayMicroseconds(20);  //set it to 0 to transmit data serially    digitalWrite(latchPin,LOW);  //while the shift register is in serial mode  //collect each shift register into a byte  //the register attached to the chip comes in first   switchVar = shiftIn(dataPin, clockPin,LSBFIRST);  //Print out the results.     Serial.print(switchVar, BIN);  Serial.print("  ");  Serial.print(switchVar, HEX);  Serial.print("  ");  Serial.println(switchVar, DEC);  //white spaceSerial.println("-------------------");//delay so all these print satements can keep up. delay(1000);}`

#3
##### Mar 30, 2012, 05:02 pm
I would suggest the <keypad.h> library for reading the key presses, works very well.
No external hardware needed, just 8 IO pins.
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

#### Nishant_Sood

#4
##### Mar 30, 2012, 06:48 pm
Hi TechOne, SO far so good things are working i think.
Where in you are seeking code help or input?
I think you yourself are working pretty fine!
"Real Men can Accomplish  Anything"

- skype : nishants5
ਫ਼ਤੇਹ ਕਰੁਂ!
www.winacro.com

#5
##### Mar 31, 2012, 01:18 am
@Techone

Did you find a cheap source for those displays or just pull it from an old calculator?

Looks like a fun project BTW.

______
Rob
Rob Gray aka the GRAYnomad www.robgray.com

#### Techone

#6
##### Mar 31, 2012, 03:56 am

Quote
Did you find a cheap source for those displays or just pull it from an old calculator?

Old calculator ?  No   They are a 3 digit 7 segments display. I got them for \$0.50 ca at Active Surplus. So I got myself a few of those.

It is a fun project. It just help me out to learn in programing, use a keypad and use a MAX7219.

I agree with you. I did look into the keypad.h. I download the library. The small problem with this solution is : Use to many pins. So I was planing to use the 4021. I was planning to build a circuit for a 4 X 5 keypad matrix using the 4021. Beside a byte have 256 combinations. I also look into the use of the chip MAX1234, a touch pad / keypad encoder compatible with SPI <-- will work with shiftIn() too.  Datasheet site : http://datasheets.maxim-ic.com/en/ds/MAX1233-MAX1234.pdf I check Mouser.com if they have it, they do, but no DIP version. The chip is QFN. ... I got a little hope with this site. http://www.ezprototypes.com/index.php Click the Chips Adapters and Sockets.

@NI\$HANT

Quote
Where in you are seeking code help or input?

Both. I am open mind about new code, new help or new ideas. This project is just some kind of "homework".

Updated :

I put the two circuit together. I did a code. It just simply "scroll" a number you press the keypad. When I press nothing, no movement, scrolling. I press a key, a number coresponding the key I press show up. The next key I press show up and place the last key next to it.<-- Shifting the number to the left.

So far, my code I have now, work just fine, but it is the keypad I have an issue with ( I think ) , during the serial monitor, the bits do not all show up. I press a key and a row bit show but no col bit, sometime it show, sometime it does not. Maybe the hex Inverter chip  - 74LS04 / 74LS14 maybe not right for the job. I do have in my parts bins a 4049, 74HC04 and 74HC14. I wil see if that will work. With the 4049, I have to re-wired the breadboard setup. I will try to wired directely the keypad to the 4021 chip, code the variable - keydata - invert the data so I can use the code almost as is. If that does not work to well , I will use a LM339 comparator and inverter chip. <-- I know, it is overkill.

Here the code I have so far.

Code: [Select]
`// Keypad Serial pinsconst byte latchkeypin = 10;const byte datakeypin = 12;const byte clockkeypin = 11;// Display Serial pinsconst byte datadisplaypin = 9;const byte clockdisplaypin = 8;const byte latchdisplaypin = 7;// Anykey pinconst byte anykeypin = 2;// MAX7419 init dataword initdata[5] = { 0x0C01, 0x0F00, 0x0A0B, 0x0B07, 0x09FF };// Fill the Display array with a blank codeword display_data[8] = { 0x010F, 0x020F, 0x030F, 0x040F, 0x050F, 0x060F, 0x070F, 0x080F };  volatile boolean keystate;byte keydata;byte keynumber;byte data_box;void setup() {  //start serial  Serial.begin(9600);  //define the pins modes  pinMode(latchkeypin, OUTPUT);  pinMode(clockkeypin, OUTPUT);   pinMode(datakeypin, INPUT);  pinMode(datadisplaypin, OUTPUT);  pinMode(clockdisplaypin, OUTPUT);  pinMode(latchdisplaypin, OUTPUT);  pinMode(anykeypin, INPUT);  attachInterrupt(0,anykeypress,RISING);    /* Init the MAX7419 : Normal Mode                        Normal Operation                        Setting the Intensity                        Numbers of Digits being display                        Set to Decode Mode  */   for (int i=0;i<5;i++)  {       digitalWrite(latchdisplaypin, LOW);     shiftOut(datadisplaypin, clockdisplaypin, MSBFIRST, highByte(initdata[i]));     shiftOut(datadisplaypin, clockdisplaypin, MSBFIRST, lowByte(initdata[i]) );     digitalWrite(latchdisplaypin, HIGH);     delay(5);  }  // Blank the display  display_the_numbers();  keystate = 0;  data_box = 1;}  void loop(){  data_box = 1;  while ( keystate == 0)   {      // wait for a key press   }  read_keypad();  convert_the_keypad_data();  if ( keynumber < 0x0A )  {     for (int i=7;i>0;i--)     {       display_data[i]=display_data[i-1];       display_data[i] = word ( (i+1) , lowByte( display_data[i] ) );     }          display_data[0] = word ( 1, keynumber );     data_box++;  }  display_the_numbers();  keystate = 0;      //Print out the results.       Serial.print(keydata, BIN);    Serial.print("  ");    Serial.print(keydata, HEX);    Serial.print("  ");    Serial.print(keynumber, HEX);    Serial.print("  ");    Serial.println(keydata, DEC);  //white space//Serial.println("-------------------");//delay so all these print satements can keep up.     delay(1000);//display_the_numbers();}void read_keypad(){  //Pulse the latch pin:  //set it to 1 to collect parallel data  digitalWrite(latchkeypin,HIGH);  //set it to 1 to collect parallel data, wait  delayMicroseconds(20);  //set it to 0 to transmit data serially    digitalWrite(latchkeypin,LOW);  //while the shift register is in serial mode  //collect each shift register into a byte  //the register attached to the chip comes in first   keydata = shiftIn(datakeypin, clockkeypin,LSBFIRST);  } void convert_the_keypad_data(){  byte what_row;    what_row = ( keydata >> 3) & 0x0F;  switch ( what_row)  {    case 1:           keynumber = ( ( keydata >> 1 ) & 0x03 ) + 1;           break;    case 2:           keynumber = (( keydata >> 1 ) & 0x03 ) + 4;           break;    case 4:           keynumber = (( keydata >> 1 ) & 0x03 ) + 7;           break;    case 8:           special_key();           break;      }    }  void display_the_numbers(){   for (int i=0;i<8;i++)   {     digitalWrite(latchdisplaypin, LOW);     shiftOut(datadisplaypin, clockdisplaypin, MSBFIRST, highByte(display_data[i]) );     shiftOut(datadisplaypin, clockdisplaypin, MSBFIRST, lowByte(display_data[i]) );     digitalWrite(latchdisplaypin, HIGH);     delay(5);   }  }void special_key(){   byte special_case;      special_case = ( ( keydata >> 1) & 0x03 ) + 1;   switch ( special_case )   {     case 1:            keynumber = 0x0F;            break;     case 2:            keynumber = 0x00;            break;     case 3:            keynumber = 0x0C;            break;   }        }void anykeypress(){  keystate = 1; }  `

#### Nishant_Sood

#7
##### Mar 31, 2012, 05:17 am
Quote
during the serial monitor, the bits do not all show up. I press a key and a row bit show but no col bit, sometime it show, sometime it does not.

Serial data is so undependable ,i recently had a lot lot problem grabbing the serial data in char arrays and putting them into strings then finally i tried using <Packets> and serial flush with serial debug statements then everything became very predictable and i was able to grab the data precisely from Serial buffer.
WHEN YOU say SOMETIME it SHOW SOMETIME it does not then it definitely points out to this same problem.
"Real Men can Accomplish  Anything"

- skype : nishants5
ਫ਼ਤੇਹ ਕਰੁਂ!
www.winacro.com

#### Techone

#8
##### Mar 31, 2012, 06:37 am
@NI\$HANT
Quote
WHEN YOU say SOMETIME it SHOW SOMETIME it does not then it definitely points out to this same problem.

I was using the Serial.print() to see what data I have. I was monitoring the keyboard data.  I got monitor the bits - BIN , an hex value - HEX and the number I press - DEC.  The data in binary show me all the pins from the keypad. I was expecting this :

0b0000000 for no key press. When I press 1, the binary result is : 0b00001001 The rows bits are : 0 RRRR CCC R is a row bit. The col bits are : 0 RRRR CCC  C is the col bits.  So I expect a bit at the row and col when I press a key.  I only received this : 0b00001000 <-- that binary result. The interrupt pulse is activated. Because all the rows pins are connect to an 4 input NAND gate - 74LS20. So if I received no bits at : 00000 CCC <-- any of the C location, but a bit is activated in the 0 RRRR CCC  row location.

So I concluded that the keypad is a bit "bad" or not so conductive. I did try to change 74LS04 ---> 74LS14. Got worse, not better. Maybe TTL gate are more "picky" when I come to voltage input level. Come to think of it, when a key is press, the keyboard do not really make a proper "short" = 0 = LOW for the TTL gate, the voltage is not low enought to become a zero for the TTL gate is consern. I will try CMOS gate. They are less "picky" , but they are "picky" about static electricity. One tiny "zap" and it is "Bye-Bye chippo ... ".  If that solution is not working, the LM339 route. I will set to 2.5 V for reference.  Now that I call "overkill". I will need 2 chip of the LM339. I have those in my parts bins. And I know, a lost of breadboarding.

#### Nishant_Sood

#9
##### Mar 31, 2012, 07:13 am
Quote
the Serial.print() to see what data I have

I think that is ok but sometimes we use flushing and Packets atleast at the end of the elements we are sending so as to make them land complete in the programme but nevermind as you are saying that the keypad isn't that much conductive.

Quote
And I know, a lost of breadboarding.

A a lots of BreadBoarding atleast its easier than the Solder breadboarding.
"Real Men can Accomplish  Anything"

- skype : nishants5
ਫ਼ਤੇਹ ਕਰੁਂ!
www.winacro.com

#### Techone

#10
##### Apr 01, 2012, 06:51 am
Updated :

I got the keyboard working better by using 74HC14. But a few "double entry" and a few "not reading right". In that case, I will use the LM339 to take care of the keypad "bad contact". Just a lots of breadboarding.

I just finish coding the calculator program. So far, The "Add" section is not working right. I may need some help. The rest is working fine. The "Clear" section is working fine. I will double check the "keynumber" section. Look it is working fine, but I will double check it.

I may re-code the "add" section. Instead of extracting the thousands, hundrens, tens, etc, and use a long variable, I will try the method use when we where in Grade 3. How to add a number.

Any help from you guys will be nice.

Code: [Select]
`// Check for the "Add / Equal" button    if ( ( keynumber == 0x0B ) && ( over_flow == 0) )    {            the_number= 0;      for (int i=0;i<8;i++)      {        temp_number = long(digit_number[i]) * power_of_ten[i];        the_number = the_number + temp_number;            }        add_number = add_number + the_number;      if (add_number <= 99999999)      {        for (int i=7;i>=0;i--)        {          digit_number[i] = byte(add_number / power_of_ten[i]);          add_number = add_number - (long(digit_number[i]) * power_of_ten[i]);          display_data[i] = word ( ( i + 1) , digit_number[i] );                }        for (int i=7;i>0;i++)        {          if ( digit_number[i] == 0 )          {             display_data[i] = word ( ( i + 1 ), 0x0F );          }          else          {            break;          }          }                display_the_numbers();        add_flag = 1;        keystate = 0;      }      else      {        // Over Flow        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;              display_the_numbers();                }         `

#### Techone

#11
##### Apr 01, 2012, 06:52 am
Here the complete code:

Code: [Select]
`/*   size : 3118 bytes      Calculator Version 1.0      Just add a number enter by the keypad and display it.   With 2 function : Add / Equal ===> * button                      Clear ==>  # button   It will use a MAX7219 for display the data ( for the shiftOut() ).   and a 4021 for the keypad input data with the use of    an NOT gate 74HC14. ( for the shiftin() )   See the keypad example in the tread for details.     The interrupt use a 72LS20 from the row pins, any LOW signal will   produce a HIGH pulse to be use has an interrupt signal.   By Serge J Desjardins   aka techone / tech37   Toronto, Ontario, Canada   Compile and Tested.      Bug :   The add section need to be re-code.*/// Keypad Serial pinsconst byte latchkeypin = 10;const byte datakeypin = 12;const byte clockkeypin = 11;// Display Serial pinsconst byte datadisplaypin = 9;const byte clockdisplaypin = 8;const byte latchdisplaypin = 7;// Anykey and interrupt pinconst byte anykeypin = 2;// MAX7419 init dataword initdata[5] = { 0x0C01, 0x0F00, 0x0A0B, 0x0B07, 0x09FF };// Fill the Display array with a blank codeword display_data[8] = { 0x0100, 0x020F, 0x030F, 0x040F, 0x050F, 0x060F, 0x070F, 0x080F };  // The digit arraybyte digit_number[8] = {0,0,0,0,0,0,0,0};// For the digits extraction calculationlong power_of_ten[8] = {1,10,100,1000,10000,100000,1000000,10000000};// Key press keypad flag volatile boolean keystate;// Overflow flagboolean over_flow;// add button flagboolean add_flag;// Clear button flagboolean clear_flag;// The keypad data byte keydata;byte keynumber;// the ADD calculationlong the_number;long temp_number;long add_number;void setup() {  //start serial  //Serial.begin(9600);  //define the pins modes  pinMode(latchkeypin, OUTPUT);  pinMode(clockkeypin, OUTPUT);   pinMode(datakeypin, INPUT);  pinMode(datadisplaypin, OUTPUT);  pinMode(clockdisplaypin, OUTPUT);  pinMode(latchdisplaypin, OUTPUT);  pinMode(anykeypin, INPUT);  // setup the interrupt pin  attachInterrupt(0,anykeypress,RISING);    /* Init the MAX7419 : Normal Mode                        Normal Operation                        Setting the Intensity                        Numbers of Digits being display                        Set to Decode Mode  */   for (int i=0;i<5;i++)  {       digitalWrite(latchdisplaypin, LOW);     shiftOut(datadisplaypin, clockdisplaypin, MSBFIRST, highByte(initdata[i]));     shiftOut(datadisplaypin, clockdisplaypin, MSBFIRST, lowByte(initdata[i]) );     digitalWrite(latchdisplaypin, HIGH);     delay(5);  }  // Blank the display  display_the_numbers();  // init the flags and the calculation variable  keystate = 0;  add_number = 0;  add_flag = 0;  over_flow = 0;  clear_flag = 1;  }  void loop(){    while ( keystate == 0)   {      // wait for a key press   }  read_keypad();  convert_the_keypad_data();  // reset add flag and set the display   if ( (( add_flag == 1) || ( clear_flag = 1 )) && ( over_flow == 0 ) )  {    for (int i=0;i<8;i++)    {      digit_number[i] = 0;      display_data[i] = word ( ( i+1 ), 0x0F );    }    add_flag = 0;    clear_flag = 0;    }  // Enter the numbers routine    if ( ( keynumber < 0x0A ) && ( over_flow == 0 ) )  {           // Enter the key number and move the arrays data.          for (int i=7;i>0;i--)     {       digit_number[i] = digit_number[i-1];       display_data[i]=display_data[i-1];       display_data[i] = word ( (i+1) , lowByte( display_data[i] ) );     }     digit_number[0] = keynumber;          display_data[0] = word ( 1, keynumber );          display_the_numbers();     keystate = 0;      }  else  {    // Check for the "Add / Equal" button    if ( ( keynumber == 0x0B ) && ( over_flow == 0) )    {            the_number= 0;      for (int i=0;i<8;i++)      {        temp_number = long(digit_number[i]) * power_of_ten[i];        the_number = the_number + temp_number;             }        add_number = add_number + the_number;      if (add_number <= 99999999)      {        for (int i=7;i>=0;i--)        {          digit_number[i] = byte(add_number / power_of_ten[i]);          add_number = add_number - (long(digit_number[i]) * power_of_ten[i]);           display_data[i] = word ( ( i + 1) , digit_number[i] );                }        for (int i=7;i>0;i++)        {          if ( digit_number[i] == 0 )          {             display_data[i] = word ( ( i + 1 ), 0x0F );          }          else           {            break;          }           }                display_the_numbers();        add_flag = 1;        keystate = 0;      }      else      {        // Over Flow        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;              display_the_numbers();                 }             }        // Check for the "Clear" button     if ( keynumber == 0x0E )    {      digit_number[0] = 0;      display_data[0] = 0x0100;      for ( int i=1;i<8;i++)      {        digit_number[i] = 0;        display_data[i] = word( (i+1), 0x0F );                     }      add_number = 0;      keystate = 0;      over_flow = 0;      add_flag = 0;      clear_flag = 1;      display_the_numbers();         }      }     //For troubleshooting the program using Serial Monitor /*      Serial.print(keydata, BIN);    Serial.print("  ");    Serial.print(keydata, HEX);    Serial.print("  ");    Serial.print(keynumber, HEX);    Serial.print("  ");    Serial.println(keydata, DEC);    delay(1000);*/}// Read keypad data via a 74HC14 - Inverter from the 4021void read_keypad(){  digitalWrite(latchkeypin,HIGH);  delayMicroseconds(20);  digitalWrite(latchkeypin,LOW);  keydata = shiftIn(datakeypin, clockkeypin,LSBFIRST);  } // Convert the keypad data into BCD// And a code for *, 0, # buttonvoid convert_the_keypad_data(){  byte what_row;    what_row = ( keydata >> 3) & 0x0F;  switch ( what_row)  {    case 1:           keynumber = ( ( keydata >> 1 ) & 0x03 ) + 1;           break;    case 2:           keynumber = (( keydata >> 1 ) & 0x03 ) + 4;           break;    case 4:           keynumber = (( keydata >> 1 ) & 0x03 ) + 7;           break;    case 8:           special_key();           break;      }    }  // the display the data routine to the MAX7219 void display_the_numbers(){   for (int i=0;i<8;i++)   {     digitalWrite(latchdisplaypin, LOW);     shiftOut(datadisplaypin, clockdisplaypin, MSBFIRST, highByte(display_data[i]) );     shiftOut(datadisplaypin, clockdisplaypin, MSBFIRST, lowByte(display_data[i]) );     digitalWrite(latchdisplaypin, HIGH);     delay(5);   }  }// A special code for 0, *, # buttonvoid special_key(){   byte special_case;      special_case = ( ( keydata >> 1) & 0x03 ) + 1;   switch ( special_case )   {     case 1:            keynumber = 0x0E;            break;     case 2:            keynumber = 0x00;            break;     case 3:            keynumber = 0x0B;            break;   }        }// Interrupt Routibevoid anykeypress(){  keystate = 1; }  `

#### Nishant_Sood

#12
##### Apr 01, 2012, 07:08 am
Quote
byte digit_number[8] = {0,0,0,0,0,0,0,0};

// For the digits extraction calculation
long power_of_ten[8] = {1,10,100,1000,10000,100000,1000000,10000000};

should the arrays not be [7] here?i think the last one is free.
"Real Men can Accomplish  Anything"

- skype : nishants5
ਫ਼ਤੇਹ ਕਰੁਂ!
www.winacro.com

#### Techone

#13
##### Apr 01, 2012, 07:24 am
array -> 7 ?  No... 8   "Boxes"    from Box 0 to Box 7 = 8 boxes

The arrays need data into them. I init my arrays, even it is Zero's. The code need it. I always init my variables.

My full calculator code is compiling. A bug in the Add section, an execution bug. I need to check it out, and maybe re-code that section.

The problem with me when I code, I have "writter's block". My mind is just "blank" and I have no clue how can I do this, and it is the lack of ideas of how can I program this out. That what I call "Writter's block".

#### Nishant_Sood

#14
##### Apr 01, 2012, 07:41 am
Quote
I have "writter's block". My mind is just "blank" and I have no clue how can I do this

Why don't you just form specific functions for specific tasks like for e.g. >> Add() function for adding and pass on the processed variables(after formulating them for unit place etc.) into the respective function after just checking the * for Add or equal button  .
"Real Men can Accomplish  Anything"

- skype : nishants5
ਫ਼ਤੇਹ ਕਰੁਂ!
www.winacro.com

Go Up