1 const int NUMBER_OF_MARACAS = 2;
2 const int MARACAS_PINS[] = {6, 7};
3 const int MARACAS_DELAY = 5000;
5 const int NUMBER_OF_DRUMS= 4;
6 const int DRUM_PINS[] = {8, 9, 10, 11};
7 const int DRUM_DELAY = 2500;
9 const int GUITAR_THRESHOLD = 20;
10 const int GUITAR_PIN = A0;
11 const int GUITAR_DELAY = 5000;
13 int maracas_states[] = {-1,-1};
14 int maracas_delays[] = {0, 0};
16 int drum_delays[] = {0, 0, 0, 0};
21 for (int i = 0; i < NUMBER_OF_MARACAS; i++) {
22 pinMode(MARACAS_PINS[i], INPUT);
24 for (int i = 0; i < NUMBER_OF_DRUMS; i++) {
25 pinMode(DRUM_PINS[i], INPUT);
39 for (int i = 0; i < NUMBER_OF_MARACAS; i++) {
40 int newState = digitalRead(MARACAS_PINS[i]);
41 if (newState != maracas_states[i] && maracas_delays[i] < 1) {
42 Serial.print("maracas,");
45 maracas_states[i] = newState;
46 maracas_delays[i] = MARACAS_DELAY;
52 for (int i = 0; i < NUMBER_OF_DRUMS; i++) {
53 if (digitalRead(DRUM_PINS[i]) == HIGH && drum_delays[i] < 1) {
54 Serial.print("drum,");
57 drum_delays[i] = DRUM_DELAY;
63 int pitch = analogRead(GUITAR_PIN);
64 if (pitch >= GUITAR_THRESHOLD && guitar_delay < 1) {
65 Serial.print("guitar,");
68 guitar_delay = GUITAR_DELAY;
72 void update_delays() {
73 for (int i = 0; i < NUMBER_OF_MARACAS; i++) {
74 if (maracas_delays[i] > 0) {
75 maracas_delays[i] -= 1;
78 for (int i = 0; i < NUMBER_OF_DRUMS; i++) {
79 if (drum_delays[i] > 0) {
83 if (guitar_delay > 0) {