Initial commit

This commit is contained in:
Dejvino 2021-04-04 22:16:01 +02:00
commit 8089bde9aa
2 changed files with 118 additions and 0 deletions

105
FestivalController.ino Normal file
View File

@ -0,0 +1,105 @@
/*
Connections:
- Volume control potentiometer
- +5V -> pot MAX
- A0 -> pot sweeper (center)
- GND -> pot MIN
- buttons
- +5V -> [1k ohm] -> common connection to buttons
- D2 -> button 1
-> [1M ohm] -> GND
- D3 -> button 2
-> [1M ohm] -> GND
- D4 -> button 3
-> [1M ohm] -> GND
- D5 -> button 4
-> [1M ohm] -> GND
(or drop the resistors completely and use the internal pull-down resistors)
*/
#include <DebounceEvent.h>
const int btns = 4;
const int SWITCH_DEBOUNCE_DELAY = 500;
DebounceEvent switches[btns] = {
DebounceEvent(2, BUTTON_SWITCH, SWITCH_DEBOUNCE_DELAY),
DebounceEvent(3, BUTTON_SWITCH, SWITCH_DEBOUNCE_DELAY),
DebounceEvent(4, BUTTON_SWITCH, SWITCH_DEBOUNCE_DELAY),
DebounceEvent(5, BUTTON_SWITCH, SWITCH_DEBOUNCE_DELAY)
};
const int volumePin = A0;
const int volumeRawMin = 0;
const int volumeRawMax = 850;
const int volumeStep = 5;
int volume = -1;
// === Switches ===
void switchesSetup() {
for (int i = 0; i < btns; i++) {
sendButtonEvent(i+1, switches[i].pressed());
}
}
void switchesLoop() {
for (int i = 0; i < btns; i++) {
int event = switches[i].loop();
if (event != EVENT_NONE) {
sendButtonEvent(i+1, switches[i].pressed());
}
}
}
// === Volume ===
void volumeInit() {
pinMode(volumePin, INPUT);
volume = volumeRead();
sendVolumeEvent();
}
int volumeRead() {
int volumeRaw = analogRead(volumePin);
return map(volumeRaw, volumeRawMin, volumeRawMax, 0, 255);
}
void volumeLoop() {
int newVolume = volumeRead();
if (abs(volume - newVolume) >= volumeStep) {
volume = newVolume;
sendVolumeEvent();
}
}
// === Serial Events ===
void sendEvent(char *name, int value) {
Serial.print(name);
Serial.print("=");
Serial.println(value);
}
void sendVolumeEvent() {
sendEvent("volume", volume);
}
void sendButtonEvent(int buttonNumber, int state) {
String name = "button";
name.concat(buttonNumber);
sendEvent(name.c_str(), state);
}
// === MAIN ===
void setup() {
Serial.begin(9600);
switchesSetup();
volumeInit();
}
void loop() {
switchesLoop();
volumeLoop();
delay(100);
}

13
README.md Normal file
View File

@ -0,0 +1,13 @@
# Festival Controller
Arduino code for interacting with a 50s radio (Tesla Festival in my case, hence the name). Radio controls are read and reported as events over serial to a computer.
This controller is a part of an Internet radio conversion, providing inputs to an SBC that streams music based on the inputs.
## Hardware
- volume potentiometer
- 4 button switches array (exclusive mode)
Connections are simple, see code for details.