Can someone help me out? I uploaded the script into a mega 2560. My intensions are to feed a (on, off, on) toggle switch with 5v. Then depending if the toggle forward, then 5v output from respected pin. For example, if 5v goes to pin2, then output 5v from pin11. If the toggle is pulled back, a different output of 5v. The script compiles good, but is not doing anything besides two outputs staying on. My #6output should be off if my toggle is in the middle position, but it is staying on. Where did I go wrong? Do I need to ground 5v for a input to read low or just no 5v to it?
const int buttonPinf = 2;
const int buttonPinr = 7;// the number of the pushbutton pin
const int forwardPin = 11;
const int reversePin = 6; // the number of the LED pin
int buttonPinfState = LOW;
int buttonPinrState = LOW;
I only took 5v from the board 5v and ran it to a regular (on, off, on) toggle switch. Then each leg of the ONs are going to send the 5v if the toggle is flipped.
A switch needs pull up or pull down resitors to prevent the pin from "floating" when the switch contact is open.
Easiest way is to use Arduino's buildin pull up resitors (then no external resistors are needed).
Connect the center pin of the switch to ground, and the outside pins of the switch to the two input pins.
I am going to try that. I was debating if Analog inputs would do that too, but it's been awhile and I usually do timing outputs with no inputs. I went to upload a photo, but the preview wasn't showing it. Making a didn't want a wasted look at the no photo.
Note that the Mega can't/shouldn't power more than four relays at the time on USB supply, and even less on external supply. Active relays draw about 75mA each.
Leo..
The relay strip only happened to be sitting for the project. Only two of the 8 would be used. I also would get new ones once I figure the prohect out. I have a few baseline supplies that seem to not break and then this project would probably end up on an arduino nano. I switched the script around a little, but believe I understand what everyone means by grounding the button or PULLUP, but it still seems I will need to tinker and reorganize a better presentation. Let me mess around and see what happens. I'll let everyone know.