
void setup()
{
//make sure the interrupt pin is an input and pulled hig
h
pinMode(irqPin, INPUT);
digitalWrite(irqPin, HIGH);
//configure serial out
Serial.begin(9600);
// initalize I2C bus. Wiring lib not used.
i2cInit();
// initialize mpr121
mpr121QuickConfig();
// Create and interrupt to trigger when a button
// is hit, the IRQ pin goes low, and the function getNum
ber is run.
attachInterrupt(0,getNumber,LOW);
// prints 'Ready...' when you can start hitting numbers
Serial.println("Ready...");
}
The setup loop starts by setting the interrupt pin as an input and pulling it
high. The serial bus is started at 9600 bps. Next, the code initializes the I C
communication lines without using the Wiring library.
The MPR121 chip is then configured with the proper sensitivity settings on
the electrodes. The final step in the setup loop creates an interrupt in the
code that will trigger when any of the buttons are hit.
void loop()
{
//You can put additional code here. The interrupt will run i
n the backgound.
}
The loop function is actually empty currently, as the button presses use the
interrupt we created in the setup loop. If you did have additional hardware
you wanted to incorporate into your project, the code for it can live in this
loop.
The last two functions in the example code tell the Arduino to check the
electrode states for a button press and what to print out when a button
press is detected.
2
Page 12 of 24