forked from W4D/soundcube-firmware
soso
This commit is contained in:
@ -1,23 +1,52 @@
|
||||
#include <TCA9555.h>
|
||||
#include <Adafruit_NeoPixel.h>
|
||||
#include <PWMAudio.h>
|
||||
#include <I2S.h>
|
||||
|
||||
#define HAPTIC 0
|
||||
#define HAPTIC 1
|
||||
#define AURAL 1
|
||||
#define UI_SAMPLERATE 22050
|
||||
|
||||
I2S i2s(INPUT_PULLUP);
|
||||
|
||||
TCA9555 TCA(0x20, &Wire1);
|
||||
|
||||
//PWMAudio ui_snd(8);
|
||||
PWMAudio ui_snd(8);
|
||||
|
||||
Adafruit_NeoPixel edge_pixels(8, 4, NEO_GRB + NEO_KHZ800);
|
||||
Adafruit_NeoPixel ui_pixels(72, 5, NEO_GRB + NEO_KHZ800);
|
||||
|
||||
volatile bool flag = false;
|
||||
volatile bool click = false;
|
||||
volatile bool amp = false;
|
||||
|
||||
void tca_irq()
|
||||
{
|
||||
int counter = 0;
|
||||
|
||||
int16_t beep[UI_SAMPLERATE];
|
||||
|
||||
void pwm_audio_callback() {
|
||||
while (ui_snd.availableForWrite()) {
|
||||
if(click) {
|
||||
ui_snd.write(beep[counter]);
|
||||
} else {
|
||||
ui_snd.write(0);
|
||||
}
|
||||
counter++;
|
||||
if(counter == UI_SAMPLERATE) counter = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void tca_irq() {
|
||||
flag = true;
|
||||
}
|
||||
|
||||
void setup() {
|
||||
|
||||
for(int i = 0; i < UI_SAMPLERATE; i++){
|
||||
float sine_pos = (2.0f * M_PI * 8000.0f * (float)i) / (float)UI_SAMPLERATE;
|
||||
beep[i] = (int16_t)(sin(sine_pos) * 8000.0f);
|
||||
}
|
||||
|
||||
Serial.begin();
|
||||
delay(2000);
|
||||
|
||||
@ -41,10 +70,29 @@ void setup() {
|
||||
pinMode(6, OUTPUT); // Vibration Motor
|
||||
pinMode(7, OUTPUT); // UI Amp Enable
|
||||
|
||||
//ui_snd.begin(44100);
|
||||
ui_snd.onTransmit(pwm_audio_callback);
|
||||
ui_snd.begin(UI_SAMPLERATE);
|
||||
|
||||
digitalWrite(7, LOW);
|
||||
|
||||
edge_pixels.begin(); // INITIALIZE NeoPixel strip object (REQUIRED)
|
||||
ui_pixels.begin(); // INITIALIZE NeoPixel strip object (REQUIRED)
|
||||
|
||||
i2s.setDOUT(14);
|
||||
i2s.setDIN(15);
|
||||
i2s.setBCLK(16); //
|
||||
i2s.swapClocks();
|
||||
i2s.setMCLK(18);
|
||||
i2s.setBitsPerSample(16);
|
||||
i2s.setFrequency(48000);
|
||||
i2s.setSysClk(48000)
|
||||
i2s.begin();
|
||||
|
||||
while (1) {
|
||||
int16_t l, r;
|
||||
i2s.read16(&l, &r);
|
||||
i2s.write16(l, r);
|
||||
}
|
||||
}
|
||||
|
||||
void loop() {
|
||||
@ -57,7 +105,16 @@ void loop() {
|
||||
flag = false;
|
||||
if (HAPTIC) {
|
||||
digitalWrite(6, HIGH);
|
||||
}
|
||||
if (AURAL) {
|
||||
digitalWrite(7, HIGH);
|
||||
click = true;
|
||||
delay(50);
|
||||
click = false;
|
||||
digitalWrite(7, LOW);
|
||||
}
|
||||
if(HAPTIC){
|
||||
if(!AURAL) delay(50);
|
||||
digitalWrite(6, LOW);
|
||||
}
|
||||
}
|
||||
@ -86,5 +143,6 @@ void loop() {
|
||||
|
||||
edge_pixels.show(); // Set all pixel colors to 'off'
|
||||
ui_pixels.show(); // Set all pixel colors to 'off'
|
||||
|
||||
delay(1);
|
||||
}
|
||||
Reference in New Issue
Block a user