Add Arduino drums and guitar
authorJamie White <jamie@jgwhite.co.uk>
Sun, 9 Dec 2012 11:18:09 +0000 (11:18 +0000)
committerJamie White <jamie@jgwhite.co.uk>
Sun, 9 Dec 2012 11:18:09 +0000 (11:18 +0000)
arduino/drums.ino [new file with mode: 0644]
arduino/guitar.ino [new file with mode: 0644]

diff --git a/arduino/drums.ino b/arduino/drums.ino
new file mode 100644 (file)
index 0000000..4b3c18c
--- /dev/null
@@ -0,0 +1,32 @@
+
+#define THRESHOLD 64
+#define PADNUM 4
+#define PINLIMIT 500
+
+int val;
+int pinDelay;
+int pinDelays[4] = { 0, 0, 0, 0 };
+
+void setup() {
+  Serial.begin(57600);
+}
+
+void loop() {
+  for(int i = 0; i < PADNUM; i++) {
+    val = analogRead(i);
+    pinDelay = pinDelays[i];
+    
+    if(val >= THRESHOLD && pinDelay < 1) {
+      Serial.print(i);
+      Serial.print(",");
+      Serial.print(val);
+      Serial.println();
+      pinDelays[i] = PINLIMIT;
+    }
+    
+    if (pinDelay > 0) {
+      pinDelays[i] = pinDelay - 1;
+    }
+  }
+}
+  
diff --git a/arduino/guitar.ino b/arduino/guitar.ino
new file mode 100644 (file)
index 0000000..874a163
--- /dev/null
@@ -0,0 +1,32 @@
+
+#define THRESHOLD 16
+#define PADNUM 1
+#define PINLIMIT 5000
+
+int val;
+int pinDelay;
+int pinDelays[4] = { 0, 0, 0, 0 };
+
+void setup() {
+  Serial.begin(57600);
+}
+
+void loop() {
+  for(int i = 0; i < PADNUM; i++) {
+    val = analogRead(i);
+    pinDelay = pinDelays[i];
+    
+    if (val >= THRESHOLD && pinDelay < 1) {
+      Serial.print(i);
+      Serial.print(",");
+      Serial.print(val);
+      Serial.println();
+      pinDelays[i] = PINLIMIT;
+    }
+    
+    if (pinDelay > 0) {
+      pinDelays[i] = pinDelay - 1;
+    }
+  }
+}
+