Interactive Project – Cody Colgren and Ivan Martinez

CODE:

#include <Wire.h>
#include “Adafruit_MPR121.h”
#include “pitches.h”

#define BUZZER_PIN A0 // The output pin for the piezo buzzer
#define NUM_OF_SAMPLES 5 // Higher number whens more delay but more consistent readings

// You can have up to 4 on one i2c bus but one is enough for testing!
Adafruit_MPR121 cap = Adafruit_MPR121();

// Keeps track of the last pins touched
// so we know when buttons are ‘released’
uint16_t lasttouched = 0;
uint16_t currtouched = 0;
int note;
unsigned long lastDebounceTime = 0; // the last time the output pin was toggled
unsigned long debounceDelay = 50; // the debounce time; increase if the output flickers

// Each key corresponds to a note, which are defined here. Uncomment the scale that you want to use:
int notes[] = {NOTE_A4,NOTE_AS4,NOTE_B4,NOTE_C4, NOTE_D4, NOTE_DS4,NOTE_E4, NOTE_F4, NOTE_FS4, NOTE_G4, NOTE_C5, NOTE_D5 }; // C-Major scale
//int notes[]={NOTE_A4,NOTE_B4,NOTE_C5,NOTE_D5,NOTE_E5,NOTE_F5,NOTE_G5,NOTE_A5}; // A-Minor scale
//int notes[]={NOTE_C4,NOTE_DS4,NOTE_F4,NOTE_FS4,NOTE_G4,NOTE_AS4,NOTE_C5,NOTE_DS5}; // C Blues scale

//#include <CurieBLE.h>
//
//#define TXRX_BUF_LEN 20 //max number of bytes
//#define RX_BUF_LEN 20 //max number of bytes
//uint8_t rx_buf[RX_BUF_LEN];
//int rx_buf_num, rx_state = 0;
//uint8_t rx_temp_buf[20];
//uint8_t outBufMidi[128];

//Buffer to hold 5 bytes of MIDI data. Note the timestamp is forced
//uint8_t midiData[] = {0x80, 0x80, 0x00, 0x00, 0x00};

//Loads up buffer with values for note On
//void noteOn(char chan, char note, char vel) //channel 1
//{
// midiData[2] = 0x90 + chan;
// midiData[3] = note;
// midiData[4] = vel;
//}
//
////Loads up buffer with values for note Off
//void noteOff(char chan, char note) //channel 1
//{
// midiData[2] = 0x80 + chan;
// midiData[3] = note;
// midiData[4] = 0;
//}
//
//BLEPeripheral midiDevice; // create peripheral instance
//
//BLEService midiSvc(“03B80E5A-EDE8-4B33-A751-6CE34EC4C700”); // create service
//
//// create switch characteristic and allow remote device to read and write
//BLECharacteristic midiChar(“7772E5DB-3868-4112-A1A9-F2669D106BF3”, BLEWrite | BLEWriteWithoutResponse | BLENotify | BLERead, 5);

void setup() {
Serial.begin(9600);

// BLESetup();
// Serial.println((“Bluetooth device active, waiting for connections…”));
//
// while (!Serial) { // needed to keep leonardo/micro from starting too fast!
// delay(10);
//}
// Set the buzzer as an output:
pinMode(BUZZER_PIN, OUTPUT);
// Serial.println(“Adafruit MPR121 Capacitive Touch sensor test”);

// Default address is 0x5A, if tied to 3.3V its 0x5B
// If tied to SDA its 0x5C and if SCL then 0x5D
if (!cap.begin(0x5A)) {
Serial.println(“MPR121 not found, check wiring?”);
while (1);
}
Serial.println(“MPR121 found!”);
}

//void BLESetup()
//{
// // set the local name peripheral advertises
// midiDevice.setLocalName(“Auxren”);
// midiDevice.setDeviceName(“Auxren”);
//
// // set the UUID for the service this peripheral advertises
// midiDevice.setAdvertisedServiceUuid(midiSvc.uuid());
//
// // add service and characteristic
// midiDevice.addAttribute(midiSvc);
// midiDevice.addAttribute(midiChar);
//
// // assign event handlers for connected, disconnected to peripheral
// midiDevice.setEventHandler(BLEConnected, midiDeviceConnectHandler);
// midiDevice.setEventHandler(BLEDisconnected, midiDeviceDisconnectHandler);
//
// // assign event handlers for characteristic
// midiChar.setEventHandler(BLEWritten, midiCharacteristicWritten);
// // set an initial value for the characteristic
// midiChar.setValue(midiData, 5);
//
// // advertise the service
// midiDevice.begin();
//}

void loop() {
// Get the currently touched pads
currtouched = cap.touched();

for (uint8_t i = 0; i < 12; i++) {
// if it *is* touched and *wasnt* touched before, alert!
if ((currtouched & _BV(i)) && !(lasttouched & _BV(i)) ) {
Serial.print(i); Serial.println(” touched”);
tone(BUZZER_PIN, notes[i]); // Plays the note corresponding to the key pressed
// note = map(i, 0, 11, 30, 100);
// noteOn(0, note, 127); //loads up midiData buffer
// midiChar.setValue(midiData, 5);//midiData); //posts 5 bytes
// delay(8);
//
}
// if it *was* touched and now *isnt*, alert!
if (!(currtouched & _BV(i)) && (lasttouched & _BV(i)) ) {
Serial.print(i); Serial.println(” released”);
noTone(BUZZER_PIN);
// noteOff(0, note);
// midiChar.setValue(midiData, 5);//midiData); //posts 5 bytes
// delay(8);
}
}
// reset our state
//Serial.println(currtouched);
lasttouched = currtouched;
// buttonState = reading;
delay(100);

//int note = map(currtouched, 0, 4096, 0, 127) + 50);
//int note = random(((currtouched*10)-10), ((currtouched+10)*5));
// Serial.println(note);
//readMIDI();
}

//void midiDeviceConnectHandler(BLECentral& central) {
// // central connected event handler
// Serial.print(“Connected event, central: “);
// Serial.println(central.address());
//}
//
//void midiDeviceDisconnectHandler(BLECentral& central) {
// // central disconnected event handler
// Serial.print(“Disconnected event, central: “);
// Serial.println(central.address());
//}
//
//void midiCharacteristicWritten(BLECentral& central, BLECharacteristic& characteristic) {
// // central wrote new value to characteristic, update LED
// Serial.print(“Characteristic event, written: “);
//}

 

PARTS:

  • Adafruit Mpr121 12-key capacitive touch sensor breakout ~ 8$
    • https://www.adafruit.com/product/1982?gclid=Cj0KCQiAoJrfBRC0ARIsANqkS_6RuPNdRHs-B-2Smzg_qLApG69EhU9lueRRtaQl0zpRjjnzIk3-ktQaAjuoEALw_wc
  • Tiny Breadboard ~ $4
    • https://www.adafruit.com/product/65?gclid=Cj0KCQiAoJrfBRC0ARIsANqkS_7583EOOKbulMzT_VzLYCXfUURQI5ujpfFvYcexZ9aEle9JkgzBEzoaAoPPEALw_wcB
  • Aurduino UNO r3 Board ~
    • https://www.newegg.com/Product/Product.aspx?Item=9SIA7BF2K19064&ignorebbr=1&nm_mc=KNC-GoogleMKP-PC&cm_mmc=KNC-GoogleMKP-PC-_-pla-1Panda+Tech+LTD-_-Gadgets-_-9SIA7BF2K19064&gclid=Cj0KCQiAoJrfBRC0ARIsANqkS_6kU8JsUGRJIKEucdCc2_XBJ4Ur8XAK1DlI_JTgv4z0m2sN463NZKMaAg51EALw_wcB&gclsrc=aw.ds
  • Copper Tape ~$3
    • https://www.target.com/p/scotch-r-expressions-washi-tape-59-in-x-275-in-copper-foil/-/A-17088871?ref=tgt_adv_XS000000&AFID=google_pla_df&fndsrc=tgtao&CPNG=PLA_Seasonal%2BShopping_Local&adgroup=SC_Seasonal&LID=700000001170770pgs&network=g&device=c&location=9021717&gclsrc=aw.ds&ds_rl=1246978&ds_rl=1246978&ds_rl=1246978&ref=tgt_adv_XS000000&AFID=google_pla_df&CPNG=PLA_Seasonal+Shopping_Local&adgroup=SC_Seasonal&LID=700000001170770pgs&network=g&device=c&location=9021717&gclid=Cj0KCQiAw5_fBRCSARIsAGodhk8HahIcbg4V-at5PhJKhUIPc57SDvZd2vIhd9YGbRMtQRmdOJJA44EaAhQBEALw_wcB&gclsrc=aw.ds
  • Guitar Hero Guitar ~ $20
    • https://www.unbeatablesale.com/dcgrl21360.html?gclid=Cj0KCQiAw5_fBRCSARIsAGodhk9PY8IEOBZROcuY6T5zPqCAJNLLdz12G5FKj9rODRG7ZJ-IlbYx-hwaAvoHEALw_wcB
  • Buzzer 5V ~ $1
    • https://www.adafruit.com/product/1536?gclid=Cj0KCQiAw5_fBRCSARIsAGodhk86j7fvbq9ldVpN2VWYlqm0f77Ga6hNxG4he1jm_wYYQlXJBbJk6F4aAg5aEALw_wcB

 

PICTURES: