Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.pio/
40 changes: 40 additions & 0 deletions include/Banks.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#ifndef BANKS_H
#define BANKS_H

#include <Arduino.h>

class Banks {
public:
Banks(int topPin, int bottomPin, int resetPin);
void begin();
void update(); // Reads joystick and updates banks

int getTopBank();
int getBottomBank();
int getTopNoteStart();
int getBottomNoteStart();

bool hasChanged(); // Returns true if bank changed, requiring display update
void clearChanged();

// Accessors for notes calculation
int getTopRowOffset();
int getBottomRowOffset();

private:
int _topPin;
int _bottomPin;
int _resetPin;

int _topBank;
int _bottomBank;

const int _topNoteStart = 30;
const int _bottomNoteStart = 75;

bool _changed;

void setBanks();
};

#endif
27 changes: 27 additions & 0 deletions include/Battery.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#ifndef BATTERY_H
#define BATTERY_H

#include <Arduino.h>
#include <AnalogSmooth.h>

class Battery {
public:
Battery(int pin);
void begin();
void update();
bool shouldUpdateDisplay();
void resetDisplayTimer();

int getPercentage();
float getVoltage();
bool isUsbPowered();

private:
int _pin;
AnalogSmooth _smoother;
float _currentLevel;
unsigned long _lastReading;
bool _usbOn;
};

#endif
32 changes: 32 additions & 0 deletions include/Display.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#ifndef DISPLAY_H
#define DISPLAY_H

#include <Arduino.h>
#include <Adafruit_SSD1306.h>
#include <Wire.h>
#include "Banks.h"

class Display {
public:
Display();
void begin();
void showBootMessage();
void drawInterface();
void clear();

// Updates specific areas
void updatePotValue(int value, int note, int potIndex, bool isMic, bool isVol);
void clearPotValue();

void printBankInfo(Banks& banks);

void showUsbStatus();
void showBatteryStatus(int percent, float voltage);

private:
Adafruit_SSD1306 _display;

void drawLines();
};

#endif
27 changes: 27 additions & 0 deletions include/Potentiometer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#ifndef POTENTIOMETER_H
#define POTENTIOMETER_H

#include <Arduino.h>
#include <ResponsiveAnalogRead.h>
#include <Mux.h>

class Potentiometer {
public:
Potentiometer(int index, int pinOrChannel, bool isMux, admux::Mux* muxPtr = nullptr);

void update();
bool hasChanged();
int getValue();
int getIndex();

private:
int _index;
int _pinOrChannel;
bool _isMux;
admux::Mux* _mux;

ResponsiveAnalogRead _rar;
int _val;
};

#endif
12 changes: 12 additions & 0 deletions lib/AnalogSmooth/AnalogSmooth.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#ifndef ANALOGSMOOTH_H
#define ANALOGSMOOTH_H

#include <Arduino.h>

class AnalogSmooth {
public:
AnalogSmooth(int windowSize) {}
float analogReadSmooth(int pin) { return analogRead(pin); }
};

#endif
17 changes: 17 additions & 0 deletions lib/ResponsiveAnalogRead/ResponsiveAnalogRead.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#ifndef RESPONSIVEANALOGREAD_H
#define RESPONSIVEANALOGREAD_H

#include <Arduino.h>

class ResponsiveAnalogRead {
public:
ResponsiveAnalogRead(int pin, bool sleepEnable, float snapMultiplier) {}
void update(int val) { _val = val; }
void setActivityThreshold(float val) {}
bool hasChanged() { return true; } // Always return true for mock to simulate activity if needed, or false.
int getValue() { return _val; } // Helper if needed
private:
int _val = 0;
};

#endif
9 changes: 9 additions & 0 deletions platformio.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[env:ATmega1284P]
platform = atmelavr
board = ATmega1284P
framework = arduino
lib_deps =
adafruit/Adafruit SSD1306 @ ^2.5.7
adafruit/Adafruit GFX Library @ ^1.11.5
fortyseveneffects/MIDI Library @ ^5.0.2
stechio/Analog-Digital Multiplexers @ ^3.0.0
71 changes: 71 additions & 0 deletions src/Banks.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#include "Banks.h"

Banks::Banks(int topPin, int bottomPin, int resetPin)
: _topPin(topPin), _bottomPin(bottomPin), _resetPin(resetPin),
_topBank(0), _bottomBank(0), _changed(false) {
}

void Banks::begin() {
pinMode(_topPin, INPUT);
pinMode(_bottomPin, INPUT);
pinMode(_resetPin, INPUT);
}

void Banks::update() {
int topVal = analogRead(_topPin);
int bottomVal = analogRead(_bottomPin);
int resetVal = digitalRead(_resetPin);

bool localChange = false;

// Logic from bankShift()
if (topVal == 1023 && bottomVal < 550 && bottomVal > 450) { // Joystick up
_topBank++;
localChange = true;
}

if (topVal == 0 && bottomVal < 550 && bottomVal > 450) { // Joystick down
_topBank--;
localChange = true;
}

if (bottomVal == 0 && topVal < 550 && topVal > 450) { // Joystick right
_bottomBank++;
localChange = true;
}

if (bottomVal == 1023 && topVal < 550 && topVal > 450) { // Joystick left
_bottomBank--;
localChange = true;
}

if (resetVal == HIGH) {
_topBank = 0;
_bottomBank = 0;
localChange = true;
}

if (localChange) {
setBanks();
_changed = true;
}
}

void Banks::setBanks() {
if (_topBank > 8) _topBank = 0;
if (_topBank < 0) _topBank = 8;

if (_bottomBank > 8) _bottomBank = 0;
if (_bottomBank < 0) _bottomBank = 8;
}

int Banks::getTopBank() { return _topBank; }
int Banks::getBottomBank() { return _bottomBank; }
int Banks::getTopNoteStart() { return _topNoteStart; }
int Banks::getBottomNoteStart() { return _bottomNoteStart; }

bool Banks::hasChanged() { return _changed; }
void Banks::clearChanged() { _changed = false; }

int Banks::getTopRowOffset() { return _topNoteStart + (_topBank * 5); }
int Banks::getBottomRowOffset() { return _bottomNoteStart + (_bottomBank * 5); }
47 changes: 47 additions & 0 deletions src/Battery.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#include "Battery.h"

Battery::Battery(int pin)
: _pin(pin), _smoother(400), _currentLevel(0), _lastReading(-20000), _usbOn(false) {
}

void Battery::begin() {
// Check for USB power (logic from original code)
// "If it reads under 613 (3.0v) it's on USB power."
// Note: The original code used analogRead(A4) in setup, while passing battPin=4 to smoother.
// We assume _pin is the correct pin (A4).
if (analogRead(_pin) <= 613) {
_usbOn = true;
}
}

void Battery::update() {
_currentLevel = _smoother.analogReadSmooth(_pin);
}

bool Battery::shouldUpdateDisplay() {
if (_usbOn) return false;

if (millis() - _lastReading >= 20000) {
return true;
}
return false;
}

void Battery::resetDisplayTimer() {
_lastReading = millis();
}

int Battery::getPercentage() {
int voltagePerc = (int)_currentLevel;
voltagePerc = map(voltagePerc, 602, 813, 0, 100);
voltagePerc = constrain(voltagePerc, 0, 100);
return voltagePerc;
}

float Battery::getVoltage() {
return _currentLevel * (5.09 / 1023.0);
}

bool Battery::isUsbPowered() {
return _usbOn;
}
Loading