speaker function added

This commit is contained in:
2025-06-05 12:30:51 +02:00
parent e58b4ff968
commit 120a802840

View File

@ -47,13 +47,15 @@ int lut_matrix[13] = {56,55,57,58,59,62,61,60,63,64,65,67,66};
int active = 0;
int active_led_ring = 0;
bool speakerToggle = false;
uint32_t lastTime = 0;
int32_t position = 0;
CRGB ui_leds[74];
CRGB edge_leds[11];
volatile bool flag = false;
volatile bool buttonChanged = false;
volatile bool click = false;
volatile bool amp = false;
@ -141,7 +143,12 @@ void pwm_audio_callback() {
}
void tca_irq() {
flag = true;
buttonChanged = true;
}
void speaker(bool state){
digitalWrite(12, state ? HIGH : LOW);
digitalWrite(13, state ? HIGH : LOW);
}
void setup() {
@ -160,8 +167,7 @@ void setup() {
pinMode(12, OUTPUT);
pinMode(13, OUTPUT);
digitalWrite(12, HIGH);
digitalWrite(13, HIGH);
speaker(false);
pinMode(21, INPUT_PULLUP);
sd_card_detected = !digitalRead(21);
@ -288,7 +294,6 @@ void setup() {
// }
// }
digitalWrite(6, HIGH);
delay(50);
digitalWrite(6, LOW);
@ -301,21 +306,6 @@ void loop() {
if(sd_card_detected) edge_leds[8] = CRGB(0,10,0);
if(!sd_card_detected) edge_leds[8] = CRGB(10,0,0);
// for (int i = 0; i < NSTREAMS; i++) {
// if(!ringbuffer[i].isFull()){
// int cnt = 0;
// while (!ringbuffer[i].isFull() && cnt < 10000) {
// uint8_t samplebyte[2];
// streams[i].read(samplebyte, 2);
// if(!streams[i].available()) streams[i].seek(44, SeekSet);
// int16_t sample = (samplebyte[1] << 8) + samplebyte[0];
// ringbuffer[i].push(sample);
// cnt++;
// }
// }
// }
// EDGE LEDs
for (int i = 0; i < 8; i++) {
edge_leds[i] = CRGB(config.edge_color_r, config.edge_color_g, config.edge_color_b);
@ -331,23 +321,37 @@ void loop() {
ui_leds[1] = CRGB(0, 0, 0);
ui_leds[2] = CRGB(0, 0, 0);
// flag = true when a button is pushed
if (flag) {
int val = TCA.read16();
// buttonChanged = true when a button is pushed
if (buttonChanged) {
int buttonValues = TCA.read16();
bool buttonsNew[16] = {false};
int buttonsDir[16] = {0};
bool buttonUp = false;
bool buttonDown = false;
for(int i = 0; i < 16; i++){
buttons[i] = ~(val >> i) & 0x01;
buttonsNew[i] = ~(buttonValues >> i) & 0x01;
if(buttonsNew[i] == true && buttons[i] == false) {
buttonsDir[i] = 1;
buttonDown = true;
}
if(buttonsNew[i] == false && buttons[i] == true) {
buttonsDir[i] = -1;
buttonUp = true;
}
buttons[i] = buttonsNew[i];
}
// Make vibration
if (HAPTIC) {
if (HAPTIC && buttonDown) {
digitalWrite(6, HIGH);
delay(50);
digitalWrite(6, LOW);
}
// Make beep
if (AURAL) {
if (AURAL && buttonDown) {
digitalWrite(7, HIGH);
click = true;
}
@ -363,7 +367,12 @@ void loop() {
if(active == 13) active = 0;
if(active == -1) active = 12;
flag = false;
if(buttons[DEBUG3]) {
speakerToggle = !speakerToggle;
speaker(speakerToggle);
}
buttonChanged = false;
}
// empty LED matrix