Communicating with the Shield:
Once you’ve got your shield assembled, it’s time
to start talking to it! You can download the example
Touch_Sensor_Shield_Example.ino
file. The other files set the register definitions for the
MPR121 chip, so you shouldn’t need to mess with these at all.
//interupt
pin
int
irqPin
=
2; //
D2
First thing the code shows is the pin definitions. This is laying out the keypad functionality (ONE,
TWO, etc.) and defining which electrode pin corresponds to each number. As the comment states,
electrode pins 9, 10 and 11 are not currently connected to anything, but if you did solder on additional
buttons to those pins on the shield, you can change this.
The interrupt pin is also defined as D2. This can’t be modified without some hardware hacking on the
shield, so keep that in mind if you are interfacing additional hardware into your set up.
void
setup()
{
//make
sure
the
interrupt
pin
is
an
input
and
pulled
high
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 getNumber 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
2
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 in the backgound.
}
w w w . e k t
2
. c o m
Electronics
Katrangi
Trading