Sfoglia il codice sorgente

First commit

quite working in fact
Etienne Landon 7 anni fa
commit
376f30dd56
2 ha cambiato i file con 147 aggiunte e 0 eliminazioni
  1. 93 0
      evtActions.h
  2. 54 0
      soundTrigger.ino

+ 93 - 0
evtActions.h

@@ -0,0 +1,93 @@
+#include <Eventually.h>
+
+EvtManager mgr;
+
+
+bool play0() {
+  trigSound("0.wav");
+  return true;
+}
+
+bool play1() {
+  trigSound("1.wav");
+  return true;
+}
+
+bool play2() {
+  trigSound("2.wav");
+  return true;
+}
+
+bool play3() {
+  trigSound("3.wav");
+  return true;
+}
+
+bool play4() {
+  trigSound("4.wav");
+  return true;
+}
+
+bool play5() {
+  trigSound("5.wav");
+  return true;
+}
+
+bool play6() {
+  trigSound("6.wav");
+  return true;
+}
+
+bool play7() {
+  trigSound("7.wav");
+  return true;
+}
+
+bool play8() {
+  trigSound("8.wav");
+  return true;
+}
+
+bool play9() {
+  trigSound("9.wav");
+  return true;
+}
+
+bool play10() {
+  trigSound("10.wav");
+  return true;
+}
+
+void trigSound(String filename ) {
+  eventuallyContext();
+  playWav1.play(filename.c_str());
+  delay(5);
+}
+
+bool checkVolume() {
+  
+  float vol = analogRead(15);
+  vol = vol / 1024;
+  sgtl5000_1.volume(vol);
+}
+
+void eventuallyContext () {
+  mgr.resetContext();
+  mgr.addListener(new EvtTimeListener(10, true, (EvtAction)checkVolume));
+  mgr.addListener(new EvtPinListener(buttonPins[0], (EvtAction)play0));
+  mgr.addListener(new EvtPinListener(buttonPins[1], (EvtAction)play1));
+  mgr.addListener(new EvtPinListener(buttonPins[2], (EvtAction)play2));
+  mgr.addListener(new EvtPinListener(buttonPins[3], (EvtAction)play3));
+  mgr.addListener(new EvtPinListener(buttonPins[4], (EvtAction)play4));
+  mgr.addListener(new EvtPinListener(buttonPins[5], (EvtAction)play5));
+  mgr.addListener(new EvtPinListener(buttonPins[6], (EvtAction)play6));
+  mgr.addListener(new EvtPinListener(buttonPins[7], (EvtAction)play7));
+  mgr.addListener(new EvtPinListener(buttonPins[8], (EvtAction)play8));
+  mgr.addListener(new EvtPinListener(buttonPins[9], (EvtAction)play9));
+  mgr.addListener(new EvtPinListener(buttonPins[10], (EvtAction)play10));
+}
+
+
+
+
+

+ 54 - 0
soundTrigger.ino

@@ -0,0 +1,54 @@
+#include <Audio.h>
+#include <Wire.h>
+#include <SPI.h>
+#include <SD.h>
+#include <SerialFlash.h>
+
+
+AudioPlaySdWav           playWav1;
+AudioOutputI2S           audioOutput;
+AudioConnection          patchCord1(playWav1, 0, audioOutput, 0);
+AudioConnection          patchCord2(playWav1, 1, audioOutput, 1);
+AudioControlSGTL5000     sgtl5000_1;
+
+// Use these with the Teensy Audio Shield
+#define SDCARD_CS_PIN    10
+#define SDCARD_MOSI_PIN  7
+#define SDCARD_SCK_PIN   14
+
+int buttonPins[11] = { 0, 1, 2, 3, 4, 5, 8, 16, 17, 20, 21 } ;
+//int buttonPin1 = 0 ;
+//int buttonPin2 = 1 ;
+
+//function prototypes
+void eventuallyContext();
+void trigSound(String);
+#include "evtActions.h"
+
+void setup() {
+//  Serial.begin(9600) ;
+//  Serial.println("started");
+
+  AudioMemory(8);
+  sgtl5000_1.enable();
+  sgtl5000_1.volume(0.5);
+
+  SPI.setMOSI(SDCARD_MOSI_PIN);
+  SPI.setSCK(SDCARD_SCK_PIN);
+  if (!(SD.begin(SDCARD_CS_PIN))) {
+    // stop here, but print a message repetitively
+    while (1) {
+//      Serial.println("Unable to access the SD card");
+      delay(500);
+    }
+  }
+  
+  for (int i ; i<sizeof(buttonPins) ; i++ ) {
+    pinMode(buttonPins[i], INPUT_PULLUP);
+  }
+  
+  eventuallyContext();
+  
+}
+
+USE_EVENTUALLY_LOOP(mgr)