+++ /dev/null
-
-const int NUMBER_OF_DRUMS = 4;
-const int DELAY = 500;
-
-const int PINS[4] = { 8, 9, 10, 11 };
-int pinDelays[4] = { 0, 0, 0, 0 };
-
-void setup() {
- for (int i = 0; i < NUMBER_OF_DRUMS; i++) {
- pinMode(PINS[i], INPUT);
- }
- Serial.begin(9600);
-}
-
-void loop() {
- for (int i = 0; i < NUMBER_OF_DRUMS; i++) {
- if (digitalRead(PINS[i]) == HIGH && pinDelays[i] < 1) {
- Serial.print("drum,");
- Serial.println(i);
- pinDelays[i] = DELAY;
- }
- if (pinDelays[i] > 0) {
- pinDelays[i] -= 1;
- }
- }
-}
-
+++ /dev/null
-
-const int THRESHOLD = 10;
-const int GUITAR_PIN = A0;
-const int PINLIMIT = 5000;
-
-int val;
-int pinDelay;
-
-void setup() {
- Serial.begin(9600);
-}
-
-void loop() {
- val = analogRead(GUITAR_PIN);
-
- if (val >= THRESHOLD && pinDelay < 1) {
- Serial.print("guitar,");
- Serial.println(val);
- pinDelay = PINLIMIT;
- }
-
- if (pinDelay > 0) {
- pinDelay = pinDelay - 1;
- }
-}
-
--- /dev/null
+const int NUMBER_OF_MARACAS = 2;
+const int MARACAS_PINS[] = {6, 7};
+const int MARACAS_DELAY = 5000;
+
+const int NUMBER_OF_DRUMS= 4;
+const int DRUM_PINS[] = {8, 9, 10, 11};
+const int DRUM_DELAY = 2500;
+
+const int GUITAR_THRESHOLD = 20;
+const int GUITAR_PIN = A0;
+const int GUITAR_DELAY = 5000;
+
+int maracas_states[] = {-1,-1};
+int maracas_delays[] = {0, 0};
+
+int drum_delays[] = {0, 0, 0, 0};
+
+int guitar_delay = 0;
+
+void setup() {
+ for (int i = 0; i < NUMBER_OF_MARACAS; i++) {
+ pinMode(MARACAS_PINS[i], INPUT);
+ }
+ for (int i = 0; i < NUMBER_OF_DRUMS; i++) {
+ pinMode(DRUM_PINS[i], INPUT);
+ }
+ Serial.begin(9600);
+}
+
+void loop() {
+ maracas();
+ drums();
+ guitar();
+ update_delays();
+}
+
+
+void maracas() {
+ for (int i = 0; i < NUMBER_OF_MARACAS; i++) {
+ int newState = digitalRead(MARACAS_PINS[i]);
+ if (newState != maracas_states[i] && maracas_delays[i] < 1) {
+ Serial.print("maracas,");
+ Serial.print(i);
+ Serial.println();
+ maracas_states[i] = newState;
+ maracas_delays[i] = MARACAS_DELAY;
+ }
+ }
+}
+
+void drums() {
+ for (int i = 0; i < NUMBER_OF_DRUMS; i++) {
+ if (digitalRead(DRUM_PINS[i]) == HIGH && drum_delays[i] < 1) {
+ Serial.print("drum,");
+ Serial.print(i);
+ Serial.println();
+ drum_delays[i] = DRUM_DELAY;
+ }
+ }
+}
+
+void guitar() {
+ int pitch = analogRead(GUITAR_PIN);
+ if (pitch >= GUITAR_THRESHOLD && guitar_delay < 1) {
+ Serial.print("guitar,");
+ Serial.print(pitch);
+ Serial.println();
+ guitar_delay = GUITAR_DELAY;
+ }
+}
+
+void update_delays() {
+ for (int i = 0; i < NUMBER_OF_MARACAS; i++) {
+ if (maracas_delays[i] > 0) {
+ maracas_delays[i] -= 1;
+ }
+ }
+ for (int i = 0; i < NUMBER_OF_DRUMS; i++) {
+ if (drum_delays[i] > 0) {
+ drum_delays[i] -= 1;
+ }
+ }
+ if (guitar_delay > 0) {
+ guitar_delay -= 1;
+ }
+}
--- /dev/null
+const int NUMBER_OF_MARACAS = 2;
+const int MARACAS_PINS[] = {6, 7};
+const int MARACAS_DELAY = 5000;
+
+int maracas_states[] = {-1,-1};
+int maracas_delays[] = {0, 0};
+
+void setup() {
+ for (int i = 0; i < NUMBER_OF_MARACAS; i++) {
+ pinMode(MARACAS_PINS[i], INPUT);
+ }
+ Serial.begin(9600);
+}
+
+void loop() {
+ maracas();
+ update_delays();
+}
+
+
+void maracas() {
+ for (int i = 0; i < NUMBER_OF_MARACAS; i++) {
+ int newState = digitalRead(MARACAS_PINS[i]);
+ if (newState != maracas_states[i] && maracas_delays[i] < 1) {
+ Serial.print("maracas,");
+ Serial.print(i);
+ Serial.println();
+ maracas_states[i] = newState;
+ maracas_delays[i] = MARACAS_DELAY;
+ }
+ }
+}
+
+void update_delays() {
+ for (int i = 0; i < NUMBER_OF_MARACAS; i++) {
+ if (maracas_delays[i] > 0) {
+ maracas_delays[i] -= 1;
+ }
+ }
+}
--- /dev/null
+const int NUMBER_OF_MARACAS = 2;
+const int MARACAS_PINS[] = {6, 7};
+const int MARACAS_DELAY = 5000;
+
+const int NUMBER_OF_DRUMS= 4;
+const int DRUM_PINS[] = {8, 9, 10, 11};
+const int DRUM_DELAY = 2500;
+
+int maracas_states[] = {-1,-1};
+int maracas_delays[] = {0, 0};
+
+int drum_delays[] = {0, 0, 0, 0};
+
+void setup() {
+ for (int i = 0; i < NUMBER_OF_MARACAS; i++) {
+ pinMode(MARACAS_PINS[i], INPUT);
+ }
+ for (int i = 0; i < NUMBER_OF_DRUMS; i++) {
+ pinMode(DRUM_PINS[i], INPUT);
+ }
+ Serial.begin(9600);
+}
+
+void loop() {
+ maracas();
+ drums();
+ update_delays();
+}
+
+
+void maracas() {
+ for (int i = 0; i < NUMBER_OF_MARACAS; i++) {
+ int newState = digitalRead(MARACAS_PINS[i]);
+ if (newState != maracas_states[i] && maracas_delays[i] < 1) {
+ Serial.print("maracas,");
+ Serial.print(i);
+ Serial.println();
+ maracas_states[i] = newState;
+ maracas_delays[i] = MARACAS_DELAY;
+ }
+ }
+}
+
+void drums() {
+ for (int i = 0; i < NUMBER_OF_DRUMS; i++) {
+ if (digitalRead(DRUM_PINS[i]) == HIGH && drum_delays[i] < 1) {
+ Serial.print("drum,");
+ Serial.print(i);
+ Serial.println();
+ drum_delays[i] = DRUM_DELAY;
+ }
+ }
+}
+
+void update_delays() {
+ for (int i = 0; i < NUMBER_OF_MARACAS; i++) {
+ if (maracas_delays[i] > 0) {
+ maracas_delays[i] -= 1;
+ }
+ }
+ for (int i = 0; i < NUMBER_OF_DRUMS; i++) {
+ if (drum_delays[i] > 0) {
+ drum_delays[i] -= 1;
+ }
+ }
+}
--- /dev/null
+const int NUMBER_OF_MARACAS = 2;
+const int MARACAS_PINS[] = {6, 7};
+const int MARACAS_DELAY = 5000;
+
+const int NUMBER_OF_DRUMS= 4;
+const int DRUM_PINS[] = {8, 9, 10, 11};
+const int DRUM_DELAY = 2500;
+
+const int GUITAR_THRESHOLD = 20;
+const int GUITAR_PIN = A0;
+const int GUITAR_DELAY = 5000;
+
+int maracas_states[] = {-1,-1};
+int maracas_delays[] = {0, 0};
+
+int drum_delays[] = {0, 0, 0, 0};
+
+int guitar_delay = 0;
+
+void setup() {
+ for (int i = 0; i < NUMBER_OF_MARACAS; i++) {
+ pinMode(MARACAS_PINS[i], INPUT);
+ }
+ for (int i = 0; i < NUMBER_OF_DRUMS; i++) {
+ pinMode(DRUM_PINS[i], INPUT);
+ }
+ Serial.begin(9600);
+}
+
+void loop() {
+ maracas();
+ drums();
+ guitar();
+ update_delays();
+}
+
+
+void maracas() {
+ for (int i = 0; i < NUMBER_OF_MARACAS; i++) {
+ int newState = digitalRead(MARACAS_PINS[i]);
+ if (newState != maracas_states[i] && maracas_delays[i] < 1) {
+ Serial.print("maracas,");
+ Serial.print(i);
+ Serial.println();
+ maracas_states[i] = newState;
+ maracas_delays[i] = MARACAS_DELAY;
+ }
+ }
+}
+
+void drums() {
+ for (int i = 0; i < NUMBER_OF_DRUMS; i++) {
+ if (digitalRead(DRUM_PINS[i]) == HIGH && drum_delays[i] < 1) {
+ Serial.print("drum,");
+ Serial.print(i);
+ Serial.println();
+ drum_delays[i] = DRUM_DELAY;
+ }
+ }
+}
+
+void guitar() {
+ int pitch = analogRead(GUITAR_PIN);
+ if (pitch >= GUITAR_THRESHOLD && guitar_delay < 1) {
+ Serial.print("guitar,");
+ Serial.print(pitch);
+ Serial.println();
+ guitar_delay = GUITAR_DELAY;
+ }
+}
+
+void update_delays() {
+ for (int i = 0; i < NUMBER_OF_MARACAS; i++) {
+ if (maracas_delays[i] > 0) {
+ maracas_delays[i] -= 1;
+ }
+ }
+ for (int i = 0; i < NUMBER_OF_DRUMS; i++) {
+ if (drum_delays[i] > 0) {
+ drum_delays[i] -= 1;
+ }
+ }
+ if (guitar_delay > 0) {
+ guitar_delay -= 1;
+ }
+}
+++ /dev/null
-int newState;
-int states[] = {-1,-1};
-const int pins[] = {6, 7};
-const int wait = 500;
-
-void setup() {
- for (int i = 0; i < 2; i++) {
- pinMode(pins[i], INPUT);
- }
- Serial.begin(9600);
-}
-
-void loop() {
- for (int i = 0; i < 2; i++) {
- newState = digitalRead(pins[i]);
- if (newState != states[i]) {
- Serial.print("maracas,");
- Serial.print(i);
- Serial.println();
- states[i] = newState;
- delay(wait);
- }
- }
-}
-
DEFAULT_HOST = '127.0.0.1'
BUFFER_SIZE = 240 #used to be 100
SOCKET_TIMEOUT = 1
-DEVICES = ['/dev/ttyACM0', '/dev/ttyACM1','/dev/ttyACM3']
+DEVICES = ['/dev/ttyACM3']
+#DEVICES = ['/dev/ttyACM0', '/dev/ttyACM1','/dev/ttyACM3']
ARDUINO_BAUD_RATE = 9600
BROADCAST_NAMES = {'guitar': 'guitar',