robgmsn / gmsn

SDIY
2 stars 2 forks source link

Pure Quantiser - Keep settings when power is cycled. #3

Open robgmsn opened 7 years ago

robgmsn commented 7 years ago

Every time the Pure Quantiser is powered on, it resets to have all notes selected. It's possible to have the ATMEGA328 remember these settings when the power is cycled.

acobley commented 7 years ago

See the new ADSR code here for an example of saving to EEPROM

https://github.com/acobley/gmsn/blob/0.95/puremodular/pureADSR/GMSN_ADSR_Code_20161023/GMSN_ADSR_Code_20161023.ino

However, see this note:

https://www.arduino.cc/en/Reference/EEPROMWrite

"An EEPROM write takes 3.3 ms to complete. The EEPROM memory has a specified life of 100,000 write/erase cycles, so you may need to be careful about how often you write to it."

biednick commented 7 years ago

What about replacing the momentary buttons with latching ones? I'm going to look into editing tge code tonight, but it seems like an easy fix without adding parts.

robgmsn commented 7 years ago

So the ADSR would write to the EEPROM when the button is triggered? I think it would be okay to have the quantiser write just when a button is pressed. I think that warning is intended to steer people away from having it in the main loop?

Latching buttons is an alternative, would need to check the price difference.

biednick commented 7 years ago

I'll look for some latching buttons tonight. If they're comparable in price, we would be able to use the same schematic and all, just change the code. I haven't gotten a chance to check the code yet, but I assume you use a bool array for each one. Instead of changing value when the button is pressed, we would just need it to be true if there's voltage on the pin. It might be cleaner too since the code would just be array[n]=buttonState.

robgmsn commented 7 years ago

There's an array that holds the state of the LEDs...

byte LEDs[2] =
{
  B11111111, B00001111,
};

At the end of every loop it does.. frame(counter); buttonRead(counter);

frame() reads LEDs[] and lights the relevant buttons buttonRead() reads the buttons and updates LEDs[]

If you had latching switches, you could probably replace both of these with a single function that reads the switch state, rather than the LEDs[].