]> git.piffa.net Git - sketchbook_andrea/blob - advanced_projects/capacitance/piezo_full_fast/piezo_full_fast.ino
Capacitance fir st commit,
[sketchbook_andrea] / advanced_projects / capacitance / piezo_full_fast / piezo_full_fast.ino
1 #include <CapacitiveSensor.h>
2 #include "pitches.h"
3 /*
4  * CapitiveSense Library Demo Sketch
5  * Paul Badger 2008
6  * Uses a high value resistor e.g. 10M between send pin and receive pin
7  * Resistor effects sensitivity, experiment with values, 50K - 50M. Larger resistor values yield larger sensor values.
8  * Receive pin is the sensor pin - try different amounts of foil/metal on this pin
9  *
10  * Schema: http://i.stack.imgur.com/FMI00.png
11  */
12
13
14
15
16 CapacitiveSensor   cs_2_3 = CapacitiveSensor(2, 3);       // 10M resistor between pins 4 & 2, pin 2 is sensor pin, add a wire and or foil if desired
17 CapacitiveSensor   cs_2_4 = CapacitiveSensor(2, 4);
18 CapacitiveSensor   cs_2_5 = CapacitiveSensor(2, 5);
19 CapacitiveSensor   cs_2_6 = CapacitiveSensor(2, 6);
20 CapacitiveSensor   cs_2_7 = CapacitiveSensor(2, 7);
21 CapacitiveSensor   cs_2_8 = CapacitiveSensor(2, 8);
22 CapacitiveSensor   cs_2_9 = CapacitiveSensor(2, 9);
23 CapacitiveSensor   cs_2_10 = CapacitiveSensor(2, 10);
24 const int led = 13;        // pin that the Led is attached to
25 int sensorMin = 50;        // minimum sensor value
26 int sensorMax = 3200;           // maximum sensor value
27
28 // Carica un file di esempio con tutte le note
29
30 int notes[] = {NOTE_C4, NOTE_E4, NOTE_G5 }; // suona una prima, quinta, ottava
31
32
33
34 const int piezo_pin = 11;
35
36
37 void setup()
38 {
39   cs_2_3.set_CS_AutocaL_Millis(0xFFFFFFFF);     // turn off autocalibrate on channel 1 - just as an example
40   Serial.begin(9600);         // Disable Serial to make it fastw
41   pinMode(led, OUTPUT);
42   pinMode(piezo_pin, OUTPUT);
43 }
44
45 void loop()
46 {
47   long total[] =  {
48   cs_2_3.capacitiveSensor(30),
49   cs_2_4.capacitiveSensor(30),
50   cs_2_5.capacitiveSensor(30),
51   cs_2_6.capacitiveSensor(30),
52   cs_2_7.capacitiveSensor(30),
53   cs_2_8.capacitiveSensor(30),
54   cs_2_9.capacitiveSensor(30),
55   cs_2_10.capacitiveSensor(30)
56   };
57
58   
59 //  long total[1] =  cs_2_4.capacitiveSensor(30);
60 //  long total[2] =  cs_2_5.capacitiveSensor(30);
61 //  long total[3] =  cs_2_6.capacitiveSensor(30);
62 //  long total[4] =  cs_2_7.capacitiveSensor(30);
63 //  long total[5] =  cs_2_8.capacitiveSensor(30);
64 //  long total[6] =  cs_2_9.capacitiveSensor(30);
65 //  long total[7] =  cs_2_10.capacitiveSensor(30);
66
67 for (int thisSensor =0; thisSensor < 8; thisSensor++) {
68   if (total[thisSensor]  > (sensorMax / 2 - sensorMin)) {
69     tone(piezo_pin, notes[thisSensor], 50); // Notes array is translated
70     Serial.println(thisSensor);
71   }
72 }
73
74 }
75