First project, first fritz.
I have a toy that has two make-break mechanical switches (two pin). Press release the button of switch1 to increase speed a small amount. Press release the button of switch2 to decrease speed a small amount. To get the speed up to 30 for example, press release switch1 button 30 times. To bring speed back down to 0, press release switch2 button 30 times. Each switch makes 5v across its pins when its button is pressed. The two switches share a common ground. The toy internals know to speed up or slow down based on the button/switch that was pressed.
The goal is to use arduino to get those buttons to support press and hold functionality to continuously increase and decrease speed.
For testing, I took the two buttons off the toy and using Arduino I put together a simple two-button, blink-two-led setup. Press and hold button1 and LED1 will blink. Press and hold button2 and LED2 will blink. The thought being that I then replace the two LEDs with the speed up hot/ground and the slow down hot/ground wires of the toy. If Arduino can make the LED blink with a press and hold of the button, it will ‘blink’ the 5v to speed up and slow down the toy. The little arduino only setup works fine. All good on Arduino - press and hold each button and the respective LED blinks.
But it doesn’t work when I replace the LEDs with the wires of the toy. When a single of the switches is connected to Arduino and toy, it works as desired -- pressing and holding increases speed or decreases speed as desired. When both of the switches and their wires from the toy are connected, neither works.
As mentioned, I get what I want with the Arduino using the switches, and LEDs. When I replace LEDs with wires of the toy, nothing.
Any thoughts about where to head next with this are appreciated.
const int button1Pin = 2;
const int led1Pin = 3;
const int button2Pin = 7;
const int led2Pin = 8;
int button1State = 0;
int button2State = 0;
void setup() {
pinMode(button1Pin, INPUT);
pinMode(button2Pin, INPUT);
pinMode(led1Pin, OUTPUT);
pinMode(led2Pin, OUTPUT);
}
void loop() {
button1State = digitalRead(button1Pin);
button2State = digitalRead(button2Pin);
if (button1State == HIGH) {
digitalWrite(led2Pin, LOW);
digitalWrite(led1Pin, HIGH);
delay(100);
digitalWrite(led1Pin, LOW);
delay(100);
} else if (button2State == HIGH) {
digitalWrite(led1Pin, LOW);
digitalWrite(led2Pin, HIGH);
delay(100);
digitalWrite(led2Pin, LOW);
delay(100);
} else {
digitalWrite(led1Pin, LOW);
digitalWrite(led2Pin, LOW);
}
}