esp32 soundboard project
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

77 lines
1.6 KiB

/**
8 years ago
* ESP32 Soundboard
*
8 years ago
* Hendriks Projekt
*
8 years ago
* https://dev.xd0.de/hendrik/soundboard
*/
#include "Arduino.h"
8 years ago
#include "keyboard.h"
8 years ago
#include "sdcard.h"
#include "sound.h"
8 years ago
#define VERSION "0.0"
#define LED_PIN 21
8 years ago
Keyboard keyboard;
8 years ago
SDCard sdcard;
Sound sound;
8 years ago
8 years ago
uint16_t buffer[2048];
void setup()
{
// initialize LED digital pin as an output.
pinMode(LED_PIN, OUTPUT);
Serial.begin(115200);
Serial.println("-------------------------------------");
Serial.print("Soundboard v.");
Serial.println(VERSION);
Serial.println("https://dev.xd0.de/hendrik/soundboard");
Serial.println("-------------------------------------");
keyboard.init();
8 years ago
sdcard.mount();
sound.init();
8 years ago
sdcard.open("/sabaton.wav");
int num_bytes_i = 0;
int num_bytes_o = 0;
while (sdcard.available()) {
num_bytes_i += sdcard.read(buffer, 2048);
num_bytes_o += sound.render_sample_block(buffer, buffer, 2048);
Serial.print(".");
}
sdcard.close();
Serial.println("");
Serial.print(num_bytes_i,DEC);
Serial.println(" bytes read from file");
Serial.print(num_bytes_o,DEC);
Serial.println(" bytes written to i2s");
delay(1000);
}
void loop()
{
8 years ago
bool touched = false;
for(int i=0; i<=9; i++) {
if (keyboard.getTouchDetected(i) == true) {
8 years ago
touched = true;
}
8 years ago
}
8 years ago
if (touched == true) {
// turn the LED on (HIGH is the voltage level)
digitalWrite(LED_PIN, HIGH);
sound.play();
8 years ago
} else {
// turn the LED off by making the voltage LOW
digitalWrite(LED_PIN, LOW);
sound.stop();
8 years ago
}
8 years ago
// wait for a second
8 years ago
delay(50);
}