-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFlexDrummer.ino
59 lines (51 loc) · 1.7 KB
/
FlexDrummer.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/*
* FlexDrummer
* Contributor - Amogh Matt
*
* Reads 5 analog input on pins 0,1,2,3,4, and sends the result to the serial monitor.
* Connect the Flex sensorPin to the +5V and Ground and read the sensorValue from the positive terminal.
*
*/
// Declaring the sensorPins
static const int sensorPinThumb = A0;
static const int sensorPinIndex = A1;
static const int sensorPinMiddle = A2;
static const int sensorPinRing = A3;
static const int sensorPinPinky = A4;
/* Declaring the code for each finger.
*
* H - Hihat
* K - Kick
* S - Snare
* T - Floor Toms
* R - Ride/Cymbal
*/
const char outputValueThumb = 'H';
const char outputValueIndex = 'K';
const char outputValueMiddle = 'S';
const char outputValueRing = 'T';
const char outputValuePinky = 'R';
// Declaring variables for reading the sensor values.
int sensorValueThumb;
int sensorValueIndex;
int sensorValueMiddle;
int sensorValueRing;
int sensorValuePinky;
void setup() {
// initialize serial communication at 115200 bits per second:
Serial.begin(115200);
}
void loop() {
// Call detectMovement for each finger.
detectMovement(sensorValueThumb, sensorPinThumb, outputValueThumb);
detectMovement(sensorValueIndex, sensorPinIndex, outputValueIndex);
detectMovement(sensorValueMiddle, sensorPinMiddle, outputValueMiddle);
detectMovement(sensorValueRing, sensorPinRing, outputValueRing);
detectMovement(sensorValuePinky, sensorPinPinky, outputValuePinky);
}
// Function to read the sensorValue and output it onto the serial port.
// Along with the code for the finger.
void detectMovement(int sensorValue, int sensorPin, char outputValue) {
sensorValue = analogRead(sensorPin);
Serial.print(outputValue);Serial.println(sensorValue);
}