#include <Bounce2.h>#include <avr/eeprom.h>#define ADDR_13 A0 // Address Pin 13 of the EPROM#define ADDR_14 A1 // Address Pin 14 of the EPROM#define ADDR_15 A2 // Address Pin 15 of the EPROM#define BTN_BNK 10 // Bank Switcher Button Pin#define PIN_RST 13 // Host Device Reset Pin#define RST_DELAY 100 // Host Device Reset DelayBounce switchBank = Bounce(); // Create switchBank DeBouncer Classbyte currentBank; // Initialize Current Bank Global Variablevoid setup(){ pinMode(PIN_RST, OUTPUT); // Configure Host Device Reset Pin as OUTPUT digitalWrite(PIN_RST, LOW); // Pull Host Device Reset Pin LOW so that it doesn't startup while we are preparing pinMode(ADDR_13, OUTPUT); // Configure Address Pin 13 of the EPROM as OUTPUT pinMode(ADDR_14, OUTPUT); // Configure Address Pin 14 of the EPROM as OUTPUT pinMode(ADDR_15, OUTPUT); // Configure Address Pin 15 of the EPROM as OUTPUT pinMode(BTN_BNK, INPUT_PULLUP); // Configure Bank Switcher Button Pin as INPUT_PULLUP switchBank.attach(BTN_BNK); // Attach Bank Switcher Button Pin to switchBank DeBouncer switchBank.interval(5); // Set interval of the switchBank DeBouncer currentBank = eeprom_read_byte((uint8_t*)0); // Read Current Bank value from EPROM if (currentBank == 0xFF) currentBank = 0; // If there is no value make it 0 digitalWrite(ADDR_13, bitRead(currentBank, 0)); // Set Address Pin 13 of the EPROM from bit 0 of the Current Bank value digitalWrite(ADDR_14, bitRead(currentBank, 1)); // Set Address Pin 14 of the EPROM from bit 1 of the Current Bank value digitalWrite(ADDR_15, bitRead(currentBank, 2)); // Set Address Pin 15 of the EPROM from bit 2 of the Current Bank value delay(RST_DELAY); // Delay some time to finish Host Device Reset operation digitalWrite(PIN_RST, HIGH); // Pull Host Device Reset Pin HIGH so that it starts up as preparing is done}void loop(){ switchBank.update(); // Check switchBank DeBouncer State if (switchBank.fell()) // If button is pressed { digitalWrite(PIN_RST, LOW); // Pull Host Device Reset Pin LOW so that it resets while we switch banks currentBank++; // Select next bank if (currentBank > 7) currentBank = 0; // In case of overflow make it 0 eeprom_write_byte((uint8_t*)0, currentBank); // Write new Current Bank value to EPROM digitalWrite(ADDR_13, bitRead(currentBank, 0)); // Set Address Pin 13 of the EPROM from bit 0 of the new Current Bank value digitalWrite(ADDR_14, bitRead(currentBank, 1)); // Set Address Pin 14 of the EPROM from bit 1 of the new Current Bank value digitalWrite(ADDR_15, bitRead(currentBank, 2)); // Set Address Pin 15 of the EPROM from bit 2 of the new Current Bank value } if (switchBank.rose()) // If button is released { delay(RST_DELAY); // Delay some time to finish Host Device Reset operation digitalWrite(PIN_RST, HIGH); // Pull Host Device Reset Pin HIGH so that it starts up as switching banks is done }}