I can not find a code to use a 5 way tactile switch with a pro micro board and output Up, Down, Left, Right as buttons 1,2,3,4. To get even more specific I am trying to use a 5 way tactile switch to create certain inputs in my game when I press the stick up, down, left, and right. I believe the easiest way would be to turn them into buttons 1,2,3,4 and tell my game what they mean.
mattdehn:
I can not find a code to use a 5 way tactile switch and output Up, Down, Left, Right as buttons 1,2,3,4. To get even more specific I am trying to use a 5 way tactile switch to create certain inputs in my game when I press the stick up, down, left, and right. I believe the easiest way would be to turn them into buttons 1,2,3,4 and tell my game what they mean.
I have attached pictures
In the picture the buttons are working fine just not the 5 way switch.
You only list 4 directions, so I guess all off is the 5th. How is your switch wired? Does it have a common wire and then one wire for each of the 4 directions you listed? Is the switch designed to close one switch for one direction, or does it open a connection for a direction?
Why don't you try your suggestion once you decide how the switch operates. If it closes a contact, then define the pin as input pullup and ground the common switch connection. Then when you read the pins, a 0 indicated the switch is connected.
Do your switch contacts need debouncing? You will soon know when you begin to test your code.
Thank you for the quick reply. The way the switch wants to be wired is a positive, a negative, then has pins for u,d,l,r and c. So wiring as a simple switch I tried the negative to A3 on my board and U to 8 and that didn't work. So I tried positive to A3 on my board and u to 8 and that didn't work. I tried using a matrix code because the switch vendor said to wire it like a simple button but it has 5 buttons in one. I don't think I am being clear am I.
mattdehn:
Thank you for the quick reply. The way the switch wants to be wired is a positive, a negative, then has pins for u,d,l,r and c. So wiring as a simple switch I tried the negative to A3 on my board and U to 8 and that didn't work. So I tried positive to A3 on my board and u to 8 and that didn't work. I tried using a matrix code because the switch vendor said to wire it like a simple button but it has 5 buttons in one. I don't think I am being clear am I.
Forget what the vendor said!
Wire the "C" to the Arduino ground.
Wire each of the others, u,d,l,r to individual digital pins on the Arduino.
In your code, set each of the pins you wired to as "input pullup".
Then write a program to read the pins and tell you what you get. Should be a 1 for not-pressed and a 0 when pressed u, d,l,r.