Hackster is hosting Hackster Holidays, Finale: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Tuesday!Stream Hackster Holidays, Finale on Tuesday!
Elizabeth LinDennis RongFelix LiJulianne COren Berkowitz
Published

Jam 'n' Bread

Jam ‘n’ Bread aims to bring people back to the dinner table and make mealtime a fun and social event again.

Full instructions provided2,330
Jam 'n' Bread

Things used in this project

Hardware components

Wood (the quality up to you)
×1
5 Megaohm Resistor
×4
Aluminum Foil
×1
Audio Kit
×1
Speakers
×1
Arduino Mega 2560
Arduino Mega 2560
×1
Piezo Drum Sensor
×1
LED (generic)
LED (generic)
×4

Story

Read more

Schematics

Circuitsio

Code

jamnbread.ino

Plain text
jamnbread.ino
/*

 Example: Control a WTV020-SD-16P module to play voices from an Arduino board

 */



#include <Wtv020sd16p.h>





#define DRUM_THRESHOLD 40

int resetPin = 2;  // The pin number of the reset pin.

int clockPin = 3;  // ThMe pin number of the clock pin.

int dataPin = 4;  // The Mpin number of the data spin.

int busyPin = 5;  // The pin number of the busy pin.



int piano1Pin = 31;

int piano2Pin = 33;

int piano3Pin = 35;

int piano4Pin = 37;





int piezo1 = A0;

int piezo2 = A1;

int piezo3 = A2;



boolean piano = false;

boolean guitar = false;

boolean drum = false;



boolean piano1Tap = false;

boolean piano2Tap = false;

boolean piano3Tap = false;

boolean piano4Tap = false;



int drum1Pin = 39;

int drum2Pin = 41;

int drum3Pin = 43;

int drum4Pin = 45;

boolean drum1Tap = false;

boolean drum2Tap = false;

boolean drum3Tap = false;

boolean drum4Tap = false;



int guitar1Pin = 47;

int guitar2Pin = 49;

int guitar3Pin = 51;

int guitar4Pin = 53;

boolean guitar1Tap = false;

boolean guitar2Tap = false;

boolean guitar3Tap = false;

boolean guitar4Tap = false;





/*

Create an instance of the Wtv020sd16p class.

 1st parameter: Reset pin number.

 2nd parameter: Clock pin number.

 3rd parameter: Data pin number.

 4th parameter: Busy pin number.

 */

Wtv020sd16p wtv020sd16p(resetPin,clockPin,dataPin,busyPin);



void setup() {

//  pinMode(piano1Pin, INPUT);

//  pinMode(piano2Pin, INPUT);

//  pinMode(piano3Pin, INPUT);

//  pinMode(piano4Pin, INPUT);

//  

//  pinMode(drum1Pin, INPUT);

//  pinMode(drum2Pin, INPUT);

//  pinMode(drum3Pin, INPUT);

//  pinMode(drum4Pin, INPUT);

//  

//  pinMode(guitar1Pin, INPUT);

//  pinMode(guitar2Pin, INPUT);

//  pinMode(guitar3Pin, INPUT);

//  pinMode(guitar4Pin, INPUT);



  pinMode(piezo1, INPUT);

  pinMode(piezo2, INPUT);

  pinMode(piezo3, INPUT);

  pinMode(guitar3Pin, INPUT);



  

  //Initializes the module.

  wtv020sd16p.reset();

  

  Serial.begin(9600);

}



void loop() {

//  int piano1 = digitalRead(piano1Pin);

//  int piano2 = digitalRead(piano2Pin);

//  int piano3 = digitalRead(piano3Pin);

//  int piano4 = digitalRead(piano4Pin);

//  

//  int drum1 = digitalRead(drum1Pin);

//  int drum2 = digitalRead(drum2Pin);

//  int drum3 = digitalRead(drum3Pin);

//  int drum4 = digitalRead(drum4Pin);

//  

//  int guitar1 = digitalRead(guitar1Pin);

//  int guitar2 = digitalRead(guitar2Pin);

//  int guitar3 = digitalRead(guitar3Pin);

//  int guitar4 = digitalRead(guitar4Pin);

//  

  //Serial.println("Running Main Loop");

  

  int drum1_sensor =analogRead(piezo1);

  int drum2_sensor = analogRead(piezo2);

  int drum3_sensor = analogRead(piezo3);

  

  

    //wtv020sd16p.asyncPlayVoice(1);

   //delay(5000);

  

//  if (drum1_sensor > DRUM_THRESHOLD) {

//    //Serial.println("In here");

//    if (!piano) {

//      piano = true;

//      int random_number = random(0, 2);

//      wtv020sd16p.asyncPlayVoice(random_number);

//    }

//  } else {

//    piano = false;

//  }

      

  

  if (drum2_sensor > DRUM_THRESHOLD ) {

    Serial.println("In here");

      int random_number = random(3, 6);

      wtv020sd16p.asyncPlayVoice(0);

      drum = true; 

      //delay(5000); 

      //last_played =

  } 

  

  

  

//   

//   

    Serial.println(drum2_sensor);

// //   Serial.println(drum1_sensor);

  

  

// if (piano1) {

//    if (!piano1Tap) {

//      wtv020sd16p.asyncPlayVoice(0);

//      piano1Tap = true;

//      return;

//    }

//  } else {

//    piano1Tap = false;

//  }

//  

//  if (piano2) {

//    if (!piano2Tap) {

//      wtv020sd16p.asyncPlayVoice(1);

//      piano2Tap = true;

//      return;

//    }

//  } else {

//    piano2Tap = false;

//  }

//  

//  if (piano3) {

//    if (!piano3Tap) {

//      wtv020sd16p.asyncPlayVoice(2);

//      piano3Tap = true;

//      return;

//    }

//  } else {

//    piano3Tap = false;

//  }

//  

//  if (piano4) {

//    if (!piano4Tap) {

//      wtv020sd16p.asyncPlayVoice(3);

//      piano4Tap = true;

//      return;

//    }

//  } else {

//    piano4Tap = false;

//  }

//  

//  if (drum1) {

//    if (!drum1Tap) {

//      wtv020sd16p.asyncPlayVoice(4);

//      drum1Tap = true;

//      return;

//    }

//  } else {

//    drum1Tap = false;

//  }

//  

//  if (drum2) {

//    if (!drum1Tap) {

//      wtv020sd16p.asyncPlayVoice(5);

//      drum1Tap = true;

//      return;

//    }

//  } else {

//    drum1Tap = false;

//  }

//  

//  if (drum3) {

//    if (!drum3Tap) {

//      wtv020sd16p.asyncPlayVoice(6);

//      drum3Tap = true;

//      return;

//    }

//  } else {

//    drum3Tap = false;

//  }

//  

//  if (drum4) {

//    if (!drum4Tap) {

//      wtv020sd16p.asyncPlayVoice(7);

//      drum4Tap = true;

//      return;

//    }

//  } else {

//    drum4Tap = false;

//  }

//  

//  if (guitar1) {

//    if (!guitar1Tap) {

//      wtv020sd16p.asyncPlayVoice(8);

//      guitar1Tap = true;

//      return;

//    }

//  } else {

//    guitar1Tap = false;

//  }

//  

//  if (guitar2) {

//    if (!guitar2Tap) {

//      wtv020sd16p.asyncPlayVoice(9);

//      guitar2Tap = true;

//      return;

//    }

//  } else {

//    guitar2Tap = false;

//  }

//  

//  if (guitar3) {

//    if (!guitar3Tap) {

//      wtv020sd16p.asyncPlayVoice(10);

//      guitar3Tap = true;

//      return;

//    }

//  } else {

//    guitar3Tap = false;

//  }

//

//  if (guitar4) {

//    if (!guitar4Tap) {

//      wtv020sd16p.asyncPlayVoice(11);

//      guitar4Tap = true;

//      return;

//    }

//  } else {

//    guitar4Tap = false;

//  }

}

sensorcode.ino

C/C++
sensorcode.ino
#include <CapacitiveSensor.h>

#define LED 10

#define LED2 11

#define LED3 12

#define LED4 13



#define PIEZO1 A0





#define TESTLED 12

#define CAP_THRESHOLD 300

#define DRUM_THRESHOLD 8



boolean pressed1 = false;

boolean pressed2 = false;

boolean pressed3 = false;

boolean pressed4 = false;





/*

 * CapitiveSense Library Demo Sketch

 * Paul Badger 2003

 * Uses a high value resistor e.g. 10M between send pin and receive pin

 * Resistor effects sensitivity, experiment with values, 50K - 50M. Larger resistor values yield larger sensor values.

 * Receive pin is the sensor pin - try different amounts of foil/metal on this pin

 */





CapacitiveSensor   cs_0_1 = CapacitiveSensor(2,3);        // 10M resistor between pins 0 & 1, pin 2 is sensor pin, add a wire and or foil if desired

CapacitiveSensor   cs_0_2 = CapacitiveSensor(4,5);        // 10M resistor between pins 0 & 2, pin 6 is sensor pin, add a wire and or foil

CapacitiveSensor   cs_0_3 = CapacitiveSensor(6,7);        // 10M resistor between pins 0 & 3, pin 3 is sensor pin, add a wire and or foil

CapacitiveSensor   cs_0_4 = CapacitiveSensor(8,9);        // 10M resistor between pins 4 & 10, pin 10 is sensor pin, add a wire and or foil



//Previous value for cap1

long previous1 = 0;

long previous2 = 0;

long previous3 = 0;

long previous4 = 0;



 

void setup()                    

{

   pinMode(LED,OUTPUT);

   pinMode(LED2, OUTPUT);

   pinMode(LED3,OUTPUT);

   pinMode(LED4, OUTPUT);

   pinMode(TESTLED, OUTPUT);

   

   pinMode(PIEZO1, INPUT);

   

   digitalWrite(TESTLED, HIGH);

   

   digitalWrite(LED, LOW);

   digitalWrite(LED2, LOW);

   digitalWrite(LED3, LOW);

   digitalWrite(LED4, LOW);

 

 

   cs_0_1.set_CS_AutocaL_Millis(0xFFFFFFFF);

   cs_0_2.set_CS_AutocaL_Millis(0xFFFFFFFF);

   cs_0_3.set_CS_AutocaL_Millis(0xFFFFFFFF);

   cs_0_4.set_CS_AutocaL_Millis(0xFFFFFFFF);    // turn off autocalibrate on channel 1 - just as an example

    Serial.begin(9600);

}



void turnOn(int led) {

  switch(led) {

    case 0:  {

       digitalWrite(LED, HIGH);

       break; 

    }

  

    case 1:  {

       digitalWrite(LED2, HIGH);

       break; 

    }

    

    case 2:  {

       digitalWrite(LED3, HIGH);

       break; 

    }

    

    case 3:  {

       digitalWrite(LED4, HIGH);

       break; 

    }

  }

  

  delay(100);

  cs_0_1.reset_CS_AutoCal();

  cs_0_2.reset_CS_AutoCal();

  cs_0_3.reset_CS_AutoCal();

  cs_0_4.reset_CS_AutoCal();

  

}



void loop()                    

{

  

    int drum = analogRead(PIEZO1);

    

    long start = millis();

    long total1 =  cs_0_1.capacitiveSensor(10);

    long total2 =  cs_0_2.capacitiveSensor(10);

    long total3 =  cs_0_3.capacitiveSensor(30);

    long total4 =  cs_0_4.capacitiveSensor(30);

 

    long maxi = 0;

    

    long diff1 = total1 - previous1;

    long diff2 = total2 - previous2;

    long diff3 = total3 - previous3;

    long diff4 = total4 - previous4;

 

    long difference[4] = {diff1,diff2,diff3,diff4};

   

    int max_index = 0;

    for (int i=0; i<4;i++){

      maxi = max(maxi,difference[i]);

      if (maxi == difference[i]) {

        max_index = i;        

      }

    }

    

    

  

    if (drum > DRUM_THRESHOLD) {

     if (maxi > CAP_THRESHOLD) {

        turnOn(max_index);

     //   Serial.println("max:" + String(maxi));   

      }  

    }

    digitalWrite(LED,LOW);

    digitalWrite(LED2,LOW);

    digitalWrite(LED3,LOW);

    digitalWrite(LED4,LOW);

 

    

    //Serial.print(millis() - start);        // check on performance in milliseconds

    //Serial.print("\t");                    // tab character for debug windown spacing

     

     if (diff1 > CAP_THRESHOLD) {

       

       Serial.println("Cap1:" + String(diff1));      // print sensor output 1

       Serial.print("\t");

     }

//    Serial.println("Cap2:" + String(diff2));                  // print sensor output 2

//    Serial.print("\t");

//    Serial.print(diff3);                // print sensor output 3

//    Serial.print("\t");

//    Serial.println(diff4);

//    Serial.println("max:" + String(maxi));

//    Serial.println("PIezo:" + String(drum));

     previous1 = total1;

     previous2 = total2;

     previous3 = total3;

     previous4 = total4;

    

     //delay(10);                             // arbitrary delay to limit data to serial port 

}

Credits

Elizabeth Lin
4 projects • 0 followers
Designer + Aspiring Princess
Dennis Rong
4 projects • 1 follower
Felix Li
4 projects • 2 followers
I'm dope, yo.
Julianne C
3 projects • 1 follower
Oren Berkowitz
4 projects • 3 followers

Comments