Yes! I believe it works just fine. Have yet to try with Mega CD though, and I wonder if the initial reset could be a problem if used with a Mega CD1 with EU or US BIOS as they eject the tray with the reset button? Not a problem for me as I use the region free JAP BIOS, but worth mentioning nonetheless.
This mod was just written how I wanted it to be. It may not suit everyones needs.
*Press the reset button for less than 200ms to reset, hold it to cycle regions (EU = Blue, US = Purple, JAP = Red).
*Each region is saved to EEPROM, so the region will remain the same after power cycling the console.
*EU mode auto switches to 60Hz after 8 seconds, because I never want to play anything in 50Hz ever again. Resetting the console in this mode will start in 50 and change to 60 every time.
The library FastLED was used to cycle the LED color every n seconds. This method was recommended several places when I was looking for a solution, and for the moment I can't figure out how to do it any other way
The only very slight issue I found with my code is that region is saved to EEPROM every time the console is in EU mode and you reset it. I don't believe this will ever be an issue, but it's an oversight due to the way I switch regions. Might be easily fixable but I highly doubt I will ever reset the console enough that the EEPROM will wear out because of this
Phantasy Star IV booting in 50Hz and auto switching to 60 (you can hear the music speed up):
Code:
//Mega Drive Switchless v1
//2019 by Martin Larsen (Konsolkongen/Bearking)
//Pinout was chosen to fit the layout of the Arduino Pro Mini, but can be modified below
#include <EEPROM.h>
#include <FastLED.h> // Used to cycle the LED color every second
const int LEDblue = 5; // PWM output - Blue LED
const int LEDred = 3; // PWM output - Red LED
const int button = 2; // Connects to the reset button. This is active low and the original reset-trace has been cut
const int resetSignal = 4; // Connects to the reset signal after the cut
const int Hz = A2; // Speed select - LOW = 50hz, HIGH = 60Hz
const int language = A3; // Language select - LOW = JAP, HIGH = ENG
int address = 16; // The address used in EEPROM to store the current setting
int region = 0; // 0 = EU, 1 = US, 2 = JAP
int tempRegion = 0; // Temporary variable for storing the region while the button is held
int buttonState = 0; // Is the button pressed?
int lastButtonState = 0; // Previous state of the button
unsigned long millis_held; // How long the button was held (milliseconds)
unsigned long firstTime; // How long since the button was first pressed
unsigned long force60Hz; // Variable to store time used to force 60Hz when EU mode is selected
void setup() {
// Serial.begin(9600);
pinMode(LEDblue, OUTPUT);
pinMode(LEDred, OUTPUT);
pinMode(button, INPUT_PULLUP);
pinMode(resetSignal, OUTPUT);
pinMode(Hz, OUTPUT);
pinMode(language, OUTPUT);
region = EEPROM.read(address);
tempRegion = EEPROM.read(address); //tempRegion and region has to match at power on, to avoid LED color/region mismatch.
// Resets the console before the loop starts, to rule out any boot problems due to the Arduinos startup time. - This may be a problem if using a Mega CD1 with EU or US BIOS, as reset ejects the tray.
digitalWrite(resetSignal, LOW);
delay(100);
digitalWrite(resetSignal, HIGH);
}
void loop() {
buttonState = digitalRead(button); // Read the state of the button and move it to the variable.
// Serial.print("Time: ");
// Serial.print(millis());
// Serial.print(" Since push: ");
// Serial.print(millis_held);
// Serial.print(" Button: ");
// Serial.print(buttonState);
// Serial.print(" Last Button: ");
// Serial.print(lastButtonState);
// Serial.print(" Temp: ");
// Serial.print(tempRegion);
// Serial.print(" Region: ");
// Serial.println(region);
// If the button is pressed. Remember the start time.
if (buttonState == LOW && lastButtonState == HIGH) {
firstTime = millis();
}
millis_held = (millis() - firstTime);
// Debounce - Button must be held for at least 20ms.
if (millis_held > 20) {
// Every second the button is held, the tempRegion variable will increase by one.
if (buttonState == LOW && millis_held >= 200) {
EVERY_N_MILLISECONDS(1000) { // Function defined in the FastLED library. Every 1000ms, do the following...
if (millis_held >= 1200) { // EVERY_N... relies on the millis counter, so this ensures that the button has been held for at least 1200ms, so that the LED doesnt switch too fast.
tempRegion++;
if (tempRegion > 2) { // If the tempRegion variable reaches 3 it will reset to 0.
tempRegion = 0;
}
}
}
force60Hz = millis(); // Time is moved into a variable used to compare times when forcing 60Hz in EU mode.
}
switch (tempRegion) { // Cycles LED color according to the tempRegion variable.
case 0: // EU - Blue
analogWrite (LEDblue, 50), analogWrite (LEDred, 0);
break;
case 1: // US - Purple
analogWrite (LEDblue, 50), analogWrite (LEDred, 50);
break;
case 2: // JAP - Red
analogWrite (LEDblue, 0), analogWrite (LEDred, 50);
break;
}
// If the tempRegion variable at this point differs from the region variable, move the tempRegion variable into region, and save to EEPROM.
if (buttonState == HIGH && lastButtonState == LOW && region != tempRegion) {
region = tempRegion;
EEPROM.write(address, region); // Stores the region setting in the EEPROM variable address
// Serial.println("Config saved!");
}
// If the region changed above, set the jumpers.
switch (region) {
case 0: // EU
digitalWrite (Hz, LOW), digitalWrite (language, HIGH);
if ((millis() - force60Hz) >= 8000) { // When 8 seconds have passsed, switch speed to 60Hz.
region = 3;
}
break;
case 1: // US
digitalWrite (Hz, HIGH), digitalWrite (language, HIGH);
break;
case 2: // JAP
digitalWrite (Hz, HIGH), digitalWrite (language, LOW);
break;
case 3: // EU forced 60Hz - A separate region to change into when auto switching to 60Hz. Is not saved in config. When reset the console will boot in 50Hz.
digitalWrite (Hz, HIGH), digitalWrite (language, HIGH);
break;
}
// If the button is released before 200ms has passed, reset the console.
if (buttonState == HIGH && lastButtonState == LOW) {
if (millis_held < 200) {
digitalWrite(resetSignal, LOW);
analogWrite (LEDblue, 0), analogWrite (LEDred, 0); // Turns off the LED for 200ms
delay(200);
digitalWrite(resetSignal, HIGH);
force60Hz = millis();
if (region == 3 && tempRegion == 0) {
region = 0;
}
}
}
}
lastButtonState = buttonState; // Save the current button state as last state.
}