Toggling 5v to 2 x NES PPU IC's

Hi

I have a NES.

I have piggybacked an ntsc nes ppu onto a pal ppu on the nes motherboard.

So effectively each of the 2 ppu's is connected to the motherboard in parallel.

I have lifted the 5v (pin40) of each chip.

I have run the 5v from the motherboard through a physical toggle switch and then to pin 40(5v) of each chip.

So I can toggle power going to each chip, i.e turn one chip at a time.


What I want to do is simple:

Instead of using a physical toggle switch I want to toggle the power using the arduino.

A separate push button switch connected to the arduino will toggle the 5v going to each chip and an rgb led indicating which ppu is powered.

Red for PPU1
Blue for PPU2

I've solved most of this problem, I have the pushbutton and led indicator part worked out, I just need to know how I can toggle the 5v going to each ppu via the arduino?

Here is the code I've worked out so far:

int red_led_state = !HIGH;     //the current state of the output pin
int blue_led_state = !LOW;     //the current state of the output pin

int button_state;             //the current reading from the input pin
int last_button_state = LOW;   //the previous reading from the input pin

long last_debounce_time = 0;  //the last time the output pin was toggled
long debounce_delay = 50;    //the debounce time; increase if the output flickers

const int button_pin = 2;      //the number of the pushbutton pin

const int red_led_pin = 13;
const int blue_led_pin = 11;


/**------------------------------**/

void setup() { //this sets the output pins

  digitalWrite(red_led_pin,red_led_state); //set initial LED state

  pinMode(button_pin, INPUT);
  pinMode(red_led_pin, OUTPUT);
  pinMode(blue_led_pin, OUTPUT);

  digitalWrite(red_led_pin,red_led_state);
  digitalWrite(blue_led_pin,blue_led_state);
  }

void loop() {

  int reading = digitalRead(button_pin); //read the state of the switch into a local variable:

  if (reading != last_button_state) {
    
    last_debounce_time = millis();    //calls number of milliseconds program has been running

  }
  
  if ((millis() - last_debounce_time) > debounce_delay) {
    
    if (reading != button_state) { //if the button state has changed:
      button_state = reading;

      if (button_state == HIGH) { //only toggle the LED if the new button state is HIGH
        red_led_state = !red_led_state;
        blue_led_state = !blue_led_state;
      }
    }
  }
  


  digitalWrite(red_led_pin, red_led_state); //set red led
  digitalWrite(blue_led_pin, blue_led_state); //set red led

  last_button_state = reading;  //save the reading.  Next time through the loop,
                //it'll be the lastButtonState:
}

Another question is if there is anyway I can make this code a bit tidier?

For example, can a put the switch debounce part into a subroutine to make it easier to work with?

Much Appreciated!

I think you should toggle the +5v to the chips using two transistors (even one might suffice since only one can be on at any given time), since they will probably source more current than an Arduino pin can provide (40 mA). Then you can just toggle them with an output pin, exactly like you do for the led.

BTW, I'm pretty sure you also need to switch between the NTSC and PAL CPUs (including the crystal, since they run at slightly different speeds), switching the PPU is not enough.

Thank you for your reply.

I know I need to the do the cpu and crystal as well, I was just trying to simplify the question.

OK, so I need to use a transistor.

What transistor would work well for this ?

I'm not sure if this would be the right solution:

I don't want to power the ppu's directly from my arduino.

I want to use the 5v from the nes motherboard.

The arduino just has to direct the 5v to one or the other ppu from the motherboard.

Is this definitely the way to acheive that?