marcogambini
Published

E-Flute

A normal flute, modified with capacitive sensors

IntermediateFull instructions provided244
E-Flute

Things used in this project

Hardware components

Arduino Mega 2560
Arduino Mega 2560
×1
Resistor 1M ohm
Resistor 1M ohm
×8
Breadboard (generic)
Breadboard (generic)
×1
Male/Male Jumper Wires
×1
Male/Female Jumper Wires
Male/Female Jumper Wires
×1

Software apps and online services

Arduino IDE
Arduino IDE

Hand tools and fabrication machines

Scissor, Electrician
Scissor, Electrician
Tape, Scotch
Tape, Scotch
Aluminium foil

Story

Read more

Schematics

eflute_zZs0DKpvSY.kicad_sch

e-flute_OJsCTi8xT4.png

Code

e-flute code

Arduino
#include <CapacitiveSensor.h>

CapacitiveSensor cs_1 = CapacitiveSensor(22, 23); //  right number input left number output  
CapacitiveSensor cs_2 = CapacitiveSensor(24, 25); // 
CapacitiveSensor cs_3 = CapacitiveSensor(26, 27); // 
CapacitiveSensor cs_4 = CapacitiveSensor(28, 29); // 
CapacitiveSensor cs_5 = CapacitiveSensor(30, 5);  // 
CapacitiveSensor cs_6 = CapacitiveSensor(32, 4);  // 
CapacitiveSensor cs_7 = CapacitiveSensor(34, 3);  // 
CapacitiveSensor cs_8 = CapacitiveSensor(36, 2);  // 

long theshold = 50;
long low_theshold = 25;
long high_theshold = 70;

int button_pressed = 2;
int button_half_pressed = 1;
int button_unpressed = 0;

int numSamples = 5;
int timeoutMillis = 500;



void setup()
{
  Serial.begin(9600);
  pinMode(9,  OUTPUT); //buzzer
}
void loop()                    
{ 
  cs_1.set_CS_Timeout_Millis(timeoutMillis);
  cs_2.set_CS_Timeout_Millis(timeoutMillis);
  cs_3.set_CS_Timeout_Millis(timeoutMillis);
  cs_4.set_CS_Timeout_Millis(timeoutMillis);
  cs_5.set_CS_Timeout_Millis(timeoutMillis);
  cs_6.set_CS_Timeout_Millis(timeoutMillis);
  cs_7.set_CS_Timeout_Millis(timeoutMillis);
  cs_8.set_CS_Timeout_Millis(timeoutMillis);

  long touch1 = cs_1.capacitiveSensor(numSamples); 
  long touch2 = cs_2.capacitiveSensor(numSamples); 
  long touch3 = cs_3.capacitiveSensor(numSamples); 
  long touch4 = cs_4.capacitiveSensor(numSamples); 
  long touch5 = cs_5.capacitiveSensor(numSamples); 
  long touch6 = cs_6.capacitiveSensor(numSamples); 
  long touch7 = cs_7.capacitiveSensor(numSamples); 
  long touch8 = cs_8.capacitiveSensor(numSamples); 

  boolean t1 = false; if (touch1 > theshold) {t1 = true;}
  boolean t2 = false; if (touch2 > theshold) {t2 = true;}
  boolean t3 = false; if (touch3 > theshold) {t3 = true;}
  boolean t4 = false; if (touch4 > theshold) {t4 = true;}
  boolean t5 = false; if (touch5 > theshold) {t5 = true;}
  boolean t6 = false; if (touch6 > theshold) {t6 = true;}
  boolean t7 = false; if (touch7 > theshold) {t7 = true;}

  int     t8 = button_unpressed;     
  if (touch8 > low_theshold && touch8 < high_theshold) {
    t8 = TASTO_META;
  } else if (touch8 > high_theshold) {
    t8 = button_pressed;
  }


  String values = toString(touch1)+toString(touch2)+toString(touch3)+toString(touch4)+toString(touch5)+toString(touch6)+toString(touch7)+toString(touch8);
 

  String logMessage = (t1?"O":"X");
  logMessage += "  ";logMessage +=(t2?"O":"X");
  logMessage += "  ";logMessage +=(t3?"O":"X");
  logMessage += "  ";logMessage +=(t4?"O":"X");
  logMessage += "  ";logMessage +=(t5?"O":"X");
  logMessage += "  ";logMessage +=(t6?"O":"X");
  logMessage += "  ";logMessage +=(t7?"O":"X");
  logMessage += "  ";logMessage +=(t8?"O":"X");

  Serial.println(values);

// combination button setup
  
  if (         t1 &&  t2 &&  t3 &&  t4 &&  t5 &&  t6 &&  t7 &&  t8==button_pressed) {
    tone(9, 262); // C low
  } else if ( !t1 &&  t2 &&  t3 &&  t4 &&  t5 &&  t6 &&  t7 &&  t8==button_pressed) {
    tone(9, 294); // D
  } else if ( !t1 && !t2 &&  t3 &&  t4 &&  t5 &&  t6 &&  t7 &&  t8==button_pressed){
    tone (9, 330); // E
  } else if ( !t1 && !t2 && !t3 &&  t4 &&  t5 &&  t6 &&  t7 &&  t8==button_pressed){
    tone (9, 349); // F
  } else if ( !t1 && !t2 && !t3 && !t4 &&  t5 &&  t6 &&  t7 &&  t8==button_pressed){
    tone (9, 392); // G
  } else if ( !t1 && !t2 && !t3 && !t4 && !t5 &&  t6 &&  t7 &&  t8==button_pressed){
    tone (9, 440); // A
  } else if ( !t1 && !t2 && !t3 && !t4 && !t5 && !t6 &&  t7 &&  t8==button_pressed){
    tone (9, 494); // B
  } else if ( !t1 && !t2 && !t3 && !t4 && !t5 &&  t6 && !t7 &&  t8==button_pressed){
    tone (9, 523); // C high
  } else if ( !t1 && !t2 && !t3 && !t4 && !t5 &&  t6 && !t7 && t8==button_unpressed){
    tone (9, 587); // D high
  } else if ( !t1 && !t2 && t3 && t4 && t5 &&  t6 && t7 && t8==button_half_pressed){
    tone (9, 659); // E high
  } else if ( !t1 && !t2 && !t3 && t4 && t5 &&  t6 && t7 && t8==button_half_pressed){
    tone (9, 698); // F high
  } else if ( !t1 && !t2 && !t3 && !t4 && t5 &&  t6 && t7 && t8==button_half_pressed){
    tone (9, 784); // G high
  }  else {
    noTone (9);
  }

  
}

//serial monitor
String toString(long value) {
  if (value >= 100000) {return " "+String(value);}
  if (value >= 10000)  {return "  "+String(value);}
  if (value >= 1000)   {return "   "+String(value);}
  if (value >= 100)    {return "    "+String(value);}
  if (value >= 10)     {return "     "+String(value);}
  if (value >= 0)      {return "      "+String(value);}
  
  return "";
}

Credits

marcogambini

marcogambini

0 projects • 0 followers

Comments