]> git.piffa.net Git - sketchbook_andrea/blob - advanced_projects/capacitance/piezo_triple_fast/piezo_triple_fast.ino
Capacitance fir st commit,
[sketchbook_andrea] / advanced_projects / capacitance / piezo_triple_fast / piezo_triple_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
20 const int led = 13;        // pin that the Led is attached to
21 int sensorMin = 50;        // minimum sensor value
22 int sensorMax = 3200;           // maximum sensor value
23
24 // Carica un file di esempio con tutte le note
25
26  int notes[] = {NOTE_C4, NOTE_E4,NOTE_G5 }; // suona una prima, quinta, ottava
27
28
29
30 const int piezo_pin = 9;
31
32
33 void setup()
34 {
35   cs_2_3.set_CS_AutocaL_Millis(0xFFFFFFFF);     // turn off autocalibrate on channel 1 - just as an example
36   //Serial.begin(9600);         // Disable Serial to make it fastw
37   pinMode(led, OUTPUT);
38   pinMode(piezo_pin, OUTPUT);
39 }
40
41 void loop()
42 {
43   long start = millis();
44   long total1 =  cs_2_3.capacitiveSensor(30);
45   long total2 =  cs_2_4.capacitiveSensor(30);
46   long total3 =  cs_2_5.capacitiveSensor(30);
47
48   if (total1 > (sensorMax / 2 - sensorMin)) {
49     tone(piezo_pin, notes[0], 50); // Notes array is translated
50     Serial.println("Primo");
51   }
52
53   if (total2 > (sensorMax / 2 - sensorMin)) {
54     tone(piezo_pin, notes[1], 50); // Notes array is translated
55     Serial.println("Secondo");
56   }
57
58   if (total3 > (sensorMax / 2 - sensorMin)) {
59     tone(piezo_pin, notes[2], 50); // Notes array is translated
60     Serial.println("terzo");
61   }
62
63   Serial.print(millis() - start);        // check on performance in milliseconds
64   Serial.print("\t Capacitance 1: ");                    // tab character for debug windown spacing
65
66   Serial.print(total1);                  // print sensor output 1
67   Serial.print("\t 2: ");                    // tab character for debug windown spacing
68
69   Serial.print(total2);                  // print sensor output 1
70   Serial.print("\t 3: ");                    // tab character for debug windown spacing
71   Serial.println(total3);                  // print sensor output 1
72
73 }
74