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!