I am trying to store multiple numbers entered from a capacitive key pad (made by sparkfun).
They’ve supplied some starter code (does all of the i2c heavy lifting) from which I am trying to build off of for my project.
In essence, they have it set up to print one digit that corresponds to the number pressed and this works great. However, I would like to store multiple numbers (i.e. press “2,5” and I would like to store “25” as either an int, char or String - either way it will hopefully end up logged on an sdcard).
I would like the getNumber() function to return a value (i could then run the getNumber function inside a for loop that would store the values outputted by getNumber into an array). I am stuck because attachInterrupt() calls a function (in this case getNumber) but this function is NOT allowed to return anything. Is there anyway of storing this value? My best guess at this point is probably to write the value temporarily to EEPROM and then read it out in a second function that opens the sdwrite functionality. Is writing to memory a feasible solution or is there a ‘better’ way?
Here’s the setup() and getNumber() functions:
//make sure the interrupt pin is an input and pulled high
//for testing purposes
//configure serial out
// initalize I2C bus. Wiring lib not used.
// initialize mpr121
// Create and interrupt to trigger when a button
// is hit, the IRQ pin goes low, and the function getNumber is run.
// prints ‘Ready…’ when you can start hitting numbers
int touchNumber = 0;
touchstatus = getTouchStatus();
for (int j=0; j<12; j++) // Check how many electrodes were pressed
if ((touchstatus & (1<<j)))
// check to see what touchNumber is equal to
if (touchNumber == 1)
if (touchstatus & (1<<SEVEN))
digits = ‘7’;
else if (touchstatus & (1<<FOUR))
digits = ‘4’;
else if (touchstatus & (1<<ONE))
digits = ‘1’;
else if (touchstatus & (1<<EIGHT))
digits = ‘8’;
else if (touchstatus & (1<<FIVE))
digits = ‘5’;
else if (touchstatus & (1<<TWO))
digits = ‘2’;
else if (touchstatus & (1<<NINE))
digits = ‘9’;
else if (touchstatus & (1<<SIX))
digits = ‘6’;
else if (touchstatus & (1<<THREE))
digits = ‘3’;
//do nothing if more than one button is pressed, or if all are released
else if (touchNumber == 0)
Serial.println(“touch number is 0”);
Serial.print(touchNumber); // this should be the same thing as saying return touch; (last line of script)
/* getTouchStatus() will return a 16-bit value that relates the
current touched status of each button. The LSB represents electrodes
0-7 (bit 0 = electrode 0), and the lowest 4 bits of the MSB
represent electrods 8-11. A 1 means a button is being touched.*/
touch = mpr121Read(0x01) << 8;
touch |= mpr121Read(0x00); //note: “x |= y” is the same as “x = x | y”
Serial.println(touch) //for debugging