Components and supplies
8
Resistor 1M ohm
1
Arduino Mega 2560
1
Male/Male Jumper Wires
1
Breadboard (generic)
1
Male/Female Jumper Wires
Tools and machines
1
Tape, Scotch
1
Scissor, Electrician
1
Aluminium foil
Apps and platforms
1
Arduino IDE
Project description
Code
e-flute code
arduino
1#include <CapacitiveSensor.h> 2 3CapacitiveSensor cs_1 = CapacitiveSensor(22, 23); // right number input left number output 4CapacitiveSensor cs_2 = CapacitiveSensor(24, 25); // 5CapacitiveSensor cs_3 = CapacitiveSensor(26, 27); // 6CapacitiveSensor cs_4 = CapacitiveSensor(28, 29); // 7CapacitiveSensor cs_5 = CapacitiveSensor(30, 5); // 8CapacitiveSensor cs_6 = CapacitiveSensor(32, 4); // 9CapacitiveSensor cs_7 = CapacitiveSensor(34, 3); // 10CapacitiveSensor cs_8 = CapacitiveSensor(36, 2); // 11 12long theshold = 50; 13long low_theshold = 25; 14long high_theshold = 70; 15 16int button_pressed = 2; 17int button_half_pressed = 1; 18int button_unpressed = 0; 19 20int numSamples = 5; 21int timeoutMillis = 500; 22 23 24 25void setup() 26{ 27 Serial.begin(9600); 28 pinMode(9, OUTPUT); //buzzer 29} 30void loop() 31{ 32 cs_1.set_CS_Timeout_Millis(timeoutMillis); 33 cs_2.set_CS_Timeout_Millis(timeoutMillis); 34 cs_3.set_CS_Timeout_Millis(timeoutMillis); 35 cs_4.set_CS_Timeout_Millis(timeoutMillis); 36 cs_5.set_CS_Timeout_Millis(timeoutMillis); 37 cs_6.set_CS_Timeout_Millis(timeoutMillis); 38 cs_7.set_CS_Timeout_Millis(timeoutMillis); 39 cs_8.set_CS_Timeout_Millis(timeoutMillis); 40 41 long touch1 = cs_1.capacitiveSensor(numSamples); 42 long touch2 = cs_2.capacitiveSensor(numSamples); 43 long touch3 = cs_3.capacitiveSensor(numSamples); 44 long touch4 = cs_4.capacitiveSensor(numSamples); 45 long touch5 = cs_5.capacitiveSensor(numSamples); 46 long touch6 = cs_6.capacitiveSensor(numSamples); 47 long touch7 = cs_7.capacitiveSensor(numSamples); 48 long touch8 = cs_8.capacitiveSensor(numSamples); 49 50 boolean t1 = false; if (touch1 > theshold) {t1 = true;} 51 boolean t2 = false; if (touch2 > theshold) {t2 = true;} 52 boolean t3 = false; if (touch3 > theshold) {t3 = true;} 53 boolean t4 = false; if (touch4 > theshold) {t4 = true;} 54 boolean t5 = false; if (touch5 > theshold) {t5 = true;} 55 boolean t6 = false; if (touch6 > theshold) {t6 = true;} 56 boolean t7 = false; if (touch7 > theshold) {t7 = true;} 57 58 int t8 = button_unpressed; 59 if (touch8 > low_theshold && touch8 < high_theshold) { 60 t8 = TASTO_META; 61 } else if (touch8 > high_theshold) { 62 t8 = button_pressed; 63 } 64 65 66 String values = toString(touch1)+toString(touch2)+toString(touch3)+toString(touch4)+toString(touch5)+toString(touch6)+toString(touch7)+toString(touch8); 67 68 69 String logMessage = (t1?"O":"X"); 70 logMessage += " ";logMessage +=(t2?"O":"X"); 71 logMessage += " ";logMessage +=(t3?"O":"X"); 72 logMessage += " ";logMessage +=(t4?"O":"X"); 73 logMessage += " ";logMessage +=(t5?"O":"X"); 74 logMessage += " ";logMessage +=(t6?"O":"X"); 75 logMessage += " ";logMessage +=(t7?"O":"X"); 76 logMessage += " ";logMessage +=(t8?"O":"X"); 77 78 Serial.println(values); 79 80// combination button setup 81 82 if ( t1 && t2 && t3 && t4 && t5 && t6 && t7 && t8==button_pressed) { 83 tone(9, 262); // C low 84 } else if ( !t1 && t2 && t3 && t4 && t5 && t6 && t7 && t8==button_pressed) { 85 tone(9, 294); // D 86 } else if ( !t1 && !t2 && t3 && t4 && t5 && t6 && t7 && t8==button_pressed){ 87 tone (9, 330); // E 88 } else if ( !t1 && !t2 && !t3 && t4 && t5 && t6 && t7 && t8==button_pressed){ 89 tone (9, 349); // F 90 } else if ( !t1 && !t2 && !t3 && !t4 && t5 && t6 && t7 && t8==button_pressed){ 91 tone (9, 392); // G 92 } else if ( !t1 && !t2 && !t3 && !t4 && !t5 && t6 && t7 && t8==button_pressed){ 93 tone (9, 440); // A 94 } else if ( !t1 && !t2 && !t3 && !t4 && !t5 && !t6 && t7 && t8==button_pressed){ 95 tone (9, 494); // B 96 } else if ( !t1 && !t2 && !t3 && !t4 && !t5 && t6 && !t7 && t8==button_pressed){ 97 tone (9, 523); // C high 98 } else if ( !t1 && !t2 && !t3 && !t4 && !t5 && t6 && !t7 && t8==button_unpressed){ 99 tone (9, 587); // D high 100 } else if ( !t1 && !t2 && t3 && t4 && t5 && t6 && t7 && t8==button_half_pressed){ 101 tone (9, 659); // E high 102 } else if ( !t1 && !t2 && !t3 && t4 && t5 && t6 && t7 && t8==button_half_pressed){ 103 tone (9, 698); // F high 104 } else if ( !t1 && !t2 && !t3 && !t4 && t5 && t6 && t7 && t8==button_half_pressed){ 105 tone (9, 784); // G high 106 } else { 107 noTone (9); 108 } 109 110 111} 112 113//serial monitor 114String toString(long value) { 115 if (value >= 100000) {return " "+String(value);} 116 if (value >= 10000) {return " "+String(value);} 117 if (value >= 1000) {return " "+String(value);} 118 if (value >= 100) {return " "+String(value);} 119 if (value >= 10) {return " "+String(value);} 120 if (value >= 0) {return " "+String(value);} 121 122 return ""; 123} 124
Downloadable files
untitled
untitled
Comments
Only logged in users can leave comments