Hi, I'm pretty new to using Arduino IDE and was wondering whether I could get some help with the coding of this project. Using an Adafruit Flora, I have made an e-textile piano with seven capacitive touchpads made from conductive fabric connected to the Flora pins (0, 1, 2, 3, 9, 10, 12) with conductive thread, and a Piezo buzzer is attached to 6 and the ground/GND. I have lifted this code from a tutorial which I have attempted to modify:
/*
Capacitive-Touch Arduino Keyboard Piano
Plays piano tones through a buzzer when the user taps touch-sensitive piano "keys"
Created 18 May 2013
Modified 23 May 2013
by Tyler Crumpton and Nicholas Jones
This code is released to the public domain. For information about the circuit,
visit the Instructable tutorial at http://www.instructables.com/id/Capacitive-Touch-Arduino-Keyboard-Piano/
*/
#include <CapacitiveSensor.h>
#include "pitches.h"
#define BUZZER_PIN 6 // The output pin for the piezo buzzer
#define NUM_OF_SAMPLES 10 // Higher number whens more delay but more consistent readings
#define CAP_THRESHOLD 150 // Capactive reading that triggers a note (adjust to fit your needs)
#define NUM_OF_KEYS 7 // Number of keys that are on the keyboard
// This macro creates a capacitance "key" sensor object for each key on the piano keyboard:
#define CS(Y) CapacitiveSensor(2, Y)
// Each key corresponds to a note, which are defined here. Uncomment the scale that you want to use:
int notes[]={NOTE_C4,NOTE_D4,NOTE_E4,NOTE_F4,NOTE_G4,NOTE_A4,NOTE_B4}; // C-Major scale
//int notes[]={NOTE_A4,NOTE_B4,NOTE_C5,NOTE_D5,NOTE_E5,NOTE_F5,NOTE_G5}; // A-Minor scale
//int notes[]={NOTE_C4,NOTE_DS4,NOTE_F4,NOTE_FS4,NOTE_G4,NOTE_AS4,NOTE_C5}; // C Blues scale
// Defines the pins that the keys are connected to:
CapacitiveSensor keys[] = {CS(3), CS(2), CS(0), CS(1), CS(12), CS(9), CS(10)};
void setup() {
// Turn off autocalibrate on all channels:
for(int i=0; i<8; ++i) {
keys[i].set_CS_AutocaL_Millis(0xFFFFFFFF);
}
// Set the buzzer as an output:
pinMode(BUZZER_PIN, OUTPUT);
}
void loop() {
// Loop through each key:
for (int i = 0; i < 8; ++i) {
// If the capacitance reading is greater than the threshold, play a note:
if(keys[i].capacitiveSensor(NUM_OF_SAMPLES) > CAP_THRESHOLD) {
tone(BUZZER_PIN, notes[i]); // Plays the note corresponding to the key pressed
}
}
}
I have pitches.h on the other tab and I installed the CapacitiveSensor library with the IDE manager, and I'm sure it's not the hardware itself, but nothing is happening when the pads are touched. I don't know half of what this code does aside from guesswork and what I've picked up from similar tutorials, etc.
Basically, if someone can help me pick this apart and work out what needs changing, that would be great. I can add images of the piece so far etc. if need be. Thanks!
EDIT: Forgot to say, I assume the issue stems from not having a "common pin" as the original code/tutorial did, or something going on in the setup/loop part. Maybe.
