Firmware example #include "mpr121.h" // mpr register definitions #include "sine1024.c" // sine table #include // Teensy version of the Arduino "wire I2C " Library int POT0=0; int POT1=0; int POT2=0; float poti0; IntervalTimer myTimer; //phase values for every note int phase[12] = {0, 0, 0, 0, 0, 0, 0, 0, 0 , 0, 0, 0}; // Select scale for whole notes or Chromatic scale //int well_tempered[16] ={ 262, 277, 294, 311, 330, 349, 370, 392, 415, 440, 466, 494, 523, 554, 587, 622}; //cromatic scale int well_tempered[16] ={ 262, 292, 330, 349, 392, 440, 494, 523, 587, 659, 699, 784, 880, 989, 1047, 1175}; //major scale int irqpin = 11; // Digital 11 boolean touchStates[12]; //to keep track of the previous touch states void setup(){ pinMode(irqpin, INPUT); digitalWrite(irqpin, HIGH); //enable pullup resistor //Serial.begin(115200); //Serial.print("Serial Begin.\n"); //Wire.begin(); // Setup for Master mode, pins 18/19, external pullups, 400kHz, 200ms default timeout Wire.begin(I2C_MASTER, 0x00, I2C_PINS_18_19, I2C_PULLUP_EXT, 400000); Wire.setDefaultTimeout(200000); // 200ms analogReadResolution(12); analogWriteResolution(12); pinMode (0, OUTPUT); pinMode (1, OUTPUT); pinMode (2, OUTPUT); pinMode (3, OUTPUT); pinMode (4, OUTPUT); pinMode (5, OUTPUT); pinMode (8, OUTPUT); myTimer.begin(beep, 125); // set up time 8000 times a sec--125 usec mpr121_setup(); //attachInterrupt(irqpin, isrService, FALLING); // interrrupt 1 is data ready } void loop(){ readTouchInputs(); } void readTouchInputs(){ if(!checkInterrupt()){ //read the touch state from the MPR121 Wire.requestFrom(0x5A,2); byte LSB = Wire.read(); byte MSB = Wire.read(); uint16_t touched = ((MSB << 8) | LSB); //16bits that make up the touch states for (int i=0; i < 12; i++){ // Check what electrodes were pressed if(touched & (1< baseline. set_register(0x5A, MHD_R, 0x01); set_register(0x5A, NHD_R, 0x01); set_register(0x5A, NCL_R, 0x00); set_register(0x5A, FDL_R, 0x00); // Section B - Controls filtering when data is < baseline. set_register(0x5A, MHD_F, 0x01); set_register(0x5A, NHD_F, 0x01); set_register(0x5A, NCL_F, 0xFF); set_register(0x5A, FDL_F, 0x02); // Section C - Sets touch and release thresholds for each electrode set_register(0x5A, ELE0_T, TOU_THRESH); set_register(0x5A, ELE0_R, REL_THRESH); set_register(0x5A, ELE1_T, TOU_THRESH); set_register(0x5A, ELE1_R, REL_THRESH); set_register(0x5A, ELE2_T, TOU_THRESH); set_register(0x5A, ELE2_R, REL_THRESH); set_register(0x5A, ELE3_T, TOU_THRESH); set_register(0x5A, ELE3_R, REL_THRESH); set_register(0x5A, ELE4_T, TOU_THRESH); set_register(0x5A, ELE4_R, REL_THRESH); set_register(0x5A, ELE5_T, TOU_THRESH); set_register(0x5A, ELE5_R, REL_THRESH); set_register(0x5A, ELE6_T, TOU_THRESH); set_register(0x5A, ELE6_R, REL_THRESH); set_register(0x5A, ELE7_T, TOU_THRESH); set_register(0x5A, ELE7_R, REL_THRESH); set_register(0x5A, ELE8_T, TOU_THRESH); set_register(0x5A, ELE8_R, REL_THRESH); set_register(0x5A, ELE9_T, TOU_THRESH); set_register(0x5A, ELE9_R, REL_THRESH); set_register(0x5A, ELE10_T, TOU_THRESH); set_register(0x5A, ELE10_R, REL_THRESH); set_register(0x5A, ELE11_T, TOU_THRESH); set_register(0x5A, ELE11_R, REL_THRESH); // Section D // Set the Filter Configuration // Set ESI2 set_register(0x5A, FIL_CFG, 0x04); // Section E // Electrode Configuration // Set ELE_CFG to 0x00 to return to standby mode set_register(0x5A, ELE_CFG, 0x0C); // Enables all 12 Electrodes // Section F // Enable Auto Config and auto Reconfig /*set_register(0x5A, ATO_CFG0, 0x0B); set_register(0x5A, ATO_CFGU, 0xC9); // USL = (Vdd-0.7)/vdd*256 = 0xC9 @3.3V set_register(0x5A, ATO_CFGL, 0x82); // LSL = 0.65*USL = 0x82 @3.3V set_register(0x5A, ATO_CFGT, 0xB5);*/ // Target = 0.9*USL = 0xB5 @3.3V set_register(0x5A, ELE_CFG, 0x0C); } boolean checkInterrupt(void){ return digitalRead(irqpin); } void set_register(int address, unsigned char r, unsigned char v){ Wire.beginTransmission(address); Wire.write(r); Wire.write(v); Wire.endTransmission(); } // interrupt from timer void beep(void) { digitalWrite(5, 1); int val = 0; int valadd = 0; for (int i=0; i < 12; i++){ if (touchStates[i] == 1) { // valadd = TableS1024[((int)phase[i]>>3)&0x3ff]; valadd = TableS1024[(phase[i]>>3)&0x3ff]; digitalWrite(0, 1); } else { valadd = 0; digitalWrite(0, 0); } val = val + valadd ; phase[i] = phase[i] + 2*well_tempered[i]; } //Serial.println(val); analogWrite(A14, (int)val/4); digitalWrite(5, 0); }
Download Firmware for board
Version with Telephone Keyboard