Documentos de Académico
Documentos de Profesional
Documentos de Cultura
h>
void setup()
{
cs_2_3.set_CS_AutocaL_Millis(0xFFFFFFFF); // turn off autocalibrate on cha
nnel 1 - just as an example
// Arduino start communicate with computer.
Serial.begin(9600);
}
void loop()
{
// Set a timer.
long start = millis();
// Set the sensitivity of the sensors.
long total1 = cs_2_3.capacitiveSensor(30);
long total2 = cs_2_4.capacitiveSensor(30);
long total3 = cs_2_5.capacitiveSensor(30);
long total4 = cs_2_6.capacitiveSensor(30);
long total5 = cs_2_7.capacitiveSensor(30);
long total6 = cs_2_8.capacitiveSensor(30);
long total7 = cs_2_9.capacitiveSensor(30);
// When hand is touched the sensor, the speaker will produce a tone.
// I set a threshold for it, so that the sensor won't be too sensitive.
int fre1;
int fre2;
int fre3;
int fre4;
int fre5;
int fre6;
int fre7;
int k;
int n;
pin = analogRead(analog);
Serial.print(pin);
Serial.print("\t");
//Serial.println(n);
// delay(200); //pausa de 200 milisegundos
if(pin <= 128){n=1;}
if(128<pin && pin<=256){n=2;}
if(256<pin && pin<=384){n=3;}
if(384<pin && pin<=512){n=4;}
if(512<pin && pin<=640){n=5;}
if(640<pin && pin<=768){n=6;}
if(768<pin && pin<=896){n=7;}
if(896<pin && pin<=1023){n=8;}
Serial.println(n);
//n = 5;//octava
k = pow(2,n-1);
fre1 = 33*k;
fre2 = 37*k;
fre3 = 41*k;
fre4 = 44*k;
fre5 = 49*k;
fre6 = 55*k;
fre7 = 62*k;
if (total1 > 150) tone(speaker,fre1);
if (total2 > 150) tone(speaker,fre2);
if (total3 > 150) tone(speaker,fre3);
if (total4 > 150) tone(speaker,fre4);
if (total5 > 150) tone(speaker,fre5);
if (total6 > 150) tone(speaker,fre6);
if (total7 > 150) tone(speaker,fre7);