So ive been studying the code for the arduino touch shield located here. I think I have a pretty good understanding of the code so far Im just not sure how I would set up a password to power a pin on the arduino. This is what im working on now can any one give points for my code?
/*
Touch Sense Shield Example using the MPR121 touch sensor IC
SparkFun Electronics
created on: February 25, 2013
license: Beerware. Feel free to use, reuse, modify and do
anything with this code. If you find it useful, you can buy me a
beer next time we meet!
This is a simple example sketch to show of the functionality of
the MPR121 capacitive touch sensor. Pressing a pad will print the
corresponding number onto the Serial Monitor at 9600 bps.
Hardware: Any Arduino.
*/
// include the atmel I2C libs
#include "mpr121.h"
#include <Wire.h>
const byte MPR121_ADDRESS = 0x5A;
// Match key inputs with electrode numbers
// The defined numbers match up to key labels on the touch shield
#define ELE1 8
#define ELE2 5
#define ELE3 2
#define ELE4 7
#define ELE5 4
#define ELE6 1
#define ELE7 6
#define ELE8 3
#define ELE9 0
//extras (not connected to buttons on the shield)
#define ELE9 9
#define ELE10 10
#define ELE11 11
//interupt pin
const byte irqPin = 2; // D2
void setup()
{
//make sure the interrupt pin is an input and pulled high
pinMode(irqPin, INPUT);
digitalWrite(irqPin, HIGH);
Serial.begin(9600); //configure serial out
Wire.begin(); // initalize I2C bus
mpr121QuickConfig(); // initialize mpr121
Serial.println("MPR121 Initialized. Press buttons!");
}
void loop()
{
if (!digitalRead(irqPin))
{
getNumber();
}
}
void getNumber()
{
int touchNumber = 0;
uint16_t touchstatus;
char digits;
touchstatus = getTouchStatus();
for (int j=0; j<12; j++) // Check how many electrodes were pressed
{
if ((touchstatus & (1<<j)))
touchNumber++;
}
if (touchNumber == 1)
{
if (touchstatus & (1<<ELE7))
{
digits = '7';
}
else if (touchstatus & (1<<ELE4))
{
digits = '4';
}
else if (touchstatus & (1<<ELE1))
{
digits = '1';
}
else if (touchstatus & (1<<ELE8))
{
digits = '8';
}
else if (touchstatus & (1<<ELE5))
{
digits = '5';
}
else if (touchstatus & (1<<ELE2))
{
digits = '2';
}
else if (touchstatus & (1<<ELE9))
{
digits = '9';
}
else if (touchstatus & (1<<ELE6))
{
digits = '6';
}
else if (touchstatus & (1<<ELE3))
{
digits = '3';
}
Serial.println(digits);
}
//do nothing if more than one button is pressed, or if all are released
else if (touchNumber == 0)
;
else
;
}
/* 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.*/
unsigned int getTouchStatus()
{
Wire.beginTransmission(MPR121_ADDRESS); // Transmit I2C address
Wire.write(0x00); // Write register address of touch status byte
Wire.endTransmission(false); // Transmit bytes, and send restart message
Wire.requestFrom(MPR121_ADDRESS, (byte) 2);
byte lsb = Wire.read();
byte msb = Wire.read();
unsigned int touch = ((msb << 8) | lsb);
return touch;
}
/* mpr121Read(byte) will read a byte from the register at location
address. */
byte mpr121Read(byte address)
{
Wire.beginTransmission(MPR121_ADDRESS); // Transmit I2C address
Wire.write(address); // Write register address
Wire.endTransmission(false); // Transmit bytes, and send restart message
Wire.requestFrom(MPR121_ADDRESS, (byte) 1);
byte value = Wire.read();
return value;
}
/* mpr121Write(byte, byte) will write a byte (data) to a register
(at address). */
void mpr121Write(byte address, byte data)
{
Wire.beginTransmission(MPR121_ADDRESS);
Wire.write(address);
Wire.write(data);
Wire.endTransmission();
}
void mpr121QuickConfig(void)
{
// Section A
// This group controls filtering when data is > baseline.
mpr121Write(MHD_R, 0x01);
mpr121Write(NHD_R, 0x01);
mpr121Write(NCL_R, 0x00);
mpr121Write(FDL_R, 0x00);
// Section B
// This group controls filtering when data is < baseline.
mpr121Write(MHD_F, 0x01);
mpr121Write(NHD_F, 0x01);
mpr121Write(NCL_F, 0xFF);
mpr121Write(FDL_F, 0x02);
// Section C
// This group sets touch and release thresholds for each electrode
mpr121Write(ELE0_T, TOU_THRESH);
mpr121Write(ELE0_R, REL_THRESH);
mpr121Write(ELE1_T, TOU_THRESH);
mpr121Write(ELE1_R, REL_THRESH);
mpr121Write(ELE2_T, TOU_THRESH);
mpr121Write(ELE2_R, REL_THRESH);
mpr121Write(ELE3_T, TOU_THRESH);
mpr121Write(ELE3_R, REL_THRESH);
mpr121Write(ELE4_T, TOU_THRESH);
mpr121Write(ELE4_R, REL_THRESH);
mpr121Write(ELE5_T, TOU_THRESH);
mpr121Write(ELE5_R, REL_THRESH);
mpr121Write(ELE6_T, TOU_THRESH);
mpr121Write(ELE6_R, REL_THRESH);
mpr121Write(ELE7_T, TOU_THRESH);
mpr121Write(ELE7_R, REL_THRESH);
mpr121Write(ELE8_T, TOU_THRESH);
mpr121Write(ELE8_R, REL_THRESH);
mpr121Write(ELE9_T, TOU_THRESH);
mpr121Write(ELE9_R, REL_THRESH);
mpr121Write(ELE10_T, TOU_THRESH);
mpr121Write(ELE10_R, REL_THRESH);
mpr121Write(ELE11_T, TOU_THRESH);
mpr121Write(ELE11_R, REL_THRESH);
// Section D
// Set the Filter Configuration
// Set ESI2
mpr121Write(FIL_CFG, 0x04);
// Section E
// Electrode Configuration
// Enable 6 Electrodes and set to run mode
// Set ELE_CFG to 0x00 to return to standby mode
mpr121Write(ELE_CFG, 0x0C); // Enables all 12 Electrodes
//mpr121Write(ELE_CFG, 0x06); // Enable first 6 electrodes
// Section F
// Enable Auto Config and auto Reconfig
/*mpr121Write(ATO_CFG0, 0x0B);
mpr121Write(ATO_CFGU, 0xC9); // USL = (Vdd-0.7)/vdd*256 = 0xC9 @3.3V mpr121Write(ATO_CFGL, 0x82); // LSL = 0.65*USL = 0x82 @3.3V
mpr121Write(ATO_CFGT, 0xB5);*/ // Target = 0.9*USL = 0xB5 @3.3V
}
so if i wanted to make i so if i hit 1 it would turn power to pin 1 would it be somthing like this? Im not sure how to define multiple touchstatus like 777 digital write (1, HIGH)
{
if (touchstatus & (1<<ELE7))
digitalWrite (1, HIGH)
{