I am using two digital buttons to make a fixed value increase or decrease, depending on which button is pressed. This is being used as a controller in another software to change throttle.
Here is my code:
#include “UnoJoy.h”
const int buttonPin = 2; // the button on the top const int buttonPin2 = 3; // the button in the front int buttonState = 0;
I have bolded everything I think is relevant to this issue. The program that’s taking the Arduino’s data is not reading the values of my buttons. Any ideas?
The way your code is written, there needs to be pull-down resistors on your buttons. Are they present? The more common way to to connect one side of the button to ground and the other to the input pin which is configured as INPUT_PULLUP. This method produces LOW when the button is pressed and HIGH when it is not pressed.
You did not provide a schematic of your circuit so only you will know for sure...
lprevs:
I have a 10k resistor connected to one side of the button and the digital pin. The other side is attached to 5V.
A bunch of useless words. Draw a picture, and post it. It sounds, from what you wrote, that you have a 3 legged resistor. That would be a potentiometer, and is NOT what you should be using.
I was able to fix it. There weren't any wiring issues. Instead, I was missing the else loop that checked when the button wasn't clicked, and kept the throttle's value steady. Also, I needed a delay on each click (delay(250)) since the loop cycles very quickly in a short time span.