THis momentary buttion is on when pressed and have to be held and when released it turns off.
what are the 3 middle pins for? im guessing the 2 outside are for + and -
THis momentary buttion is on when pressed and have to be held and when released it turns off.
what are the 3 middle pins for? im guessing the 2 outside are for + and -
Best to check with multimeter, but my guess is that the center is common and the outer terminals are Normally Open and Normally Closed.
The two other pins are probably +/- for a led light in the switch.
If you have it you can look it up on the web with the model number and make.
If you look closely, there are letters on the switch... the 2 outer are for a light, and the middle ones, as positioned in the picture are top=NC, middle=NO, bottom is Common
ahh yea that makes sence
alr thx
So, I have 2 buttons (the 2 red buttons) and when I press the button all the way down I want the button to type 1 letter(a) no matter how long I hold it (stays in the on position) and will turn off as so as I let go writing only one letter.
So far I have this, this is written for a toggle switch and when flipped up stays in the up/on position till I flip it back to the off position and writes a single letter(for the on or off position). This code cant work with the momentary button. I would like to add this momentary code to this but i keep getting stuck and need Some guidance on how to code this and how to add the code to what i have. ( in advance thanks for the advice(could be what topics I could focus on to learn to code this, and such) I also have it all wired correctly for this
ps: using a arduino Leonardo and nano for this
#include "Keyboard.h"
boolean states[] = {false, false, false, false, false, false, false, false, false, false, false, false, false, false};
char hotkeysOn[] = {'g', 'c', 'q', 'a', 'b', 'w', 'd', 'l', 's', 'j', 'k', 'm', 'x', 'z'};
char hotkeysOff[] = {'g', 'c', 'q', 'a', 'b', 'w', 'd', 'l', 's', 'j', 'k', 'm', 'x', 'z'};
void setup() {
for (int i = 0; i <= 13; i++) {
pinMode(i, INPUT);
}
Keyboard.begin();
Serial.begin(9600);
}
void loop() {
for (int i = 0; i <= 13; i++) {
if (digitalRead(i) == HIGH && !states[i]) {
states[i] = !states[i];
Keyboard.write(hotkeysOn[i]);
if(i==12){
Keyboard.write(hotkeysOn[i]);
Keyboard.write(hotkeysOn[i]);
}
}
else if (digitalRead(i) == LOW && states[i]) {
states[i] = !states[i];
Keyboard.write(hotkeysOff[i]);
}
}
delay(10);
}
Simple solution : You could use a button library like Button in easyRun or OneButton or Toggle
@Delta_G I honestly have no idea, i tryed writing with this idea in mind but wond work idk why
i wired it too the two outside( + and -) maybe i wired it wrong? but i dont think
so the code is correct, its a mechanical problem? @Delta_G
look this over
recognizes button presses (going from off to on)
// check multiple buttons and toggle LEDs
enum { Off = HIGH, On = LOW };
byte pinsLed [] = { 10, 11, 12 };
byte pinsBut [] = { A1, A2, A3 };
#define N_BUT sizeof(pinsBut)
byte butState [N_BUT];
// -----------------------------------------------------------------------------
int
chkButtons ()
{
for (unsigned n = 0; n < sizeof(pinsBut); n++) {
byte but = digitalRead (pinsBut [n]);
if (butState [n] != but) {
butState [n] = but;
delay (10); // debounce
if (On == but)
return n;
}
}
return -1;
}
// -----------------------------------------------------------------------------
void
loop ()
{
switch (chkButtons ()) {
case 2:
digitalWrite (pinsLed [2], ! digitalRead (pinsLed [2]));
break;
case 1:
digitalWrite (pinsLed [1], ! digitalRead (pinsLed [1]));
break;
case 0:
digitalWrite (pinsLed [0], ! digitalRead (pinsLed [0]));
break;
}
}
// -----------------------------------------------------------------------------
void
setup ()
{
Serial.begin (9600);
for (unsigned n = 0; n < sizeof(pinsBut); n++) {
pinMode (pinsBut [n], INPUT_PULLUP);
butState [n] = digitalRead (pinsBut [n]);
}
for (unsigned n = 0; n < sizeof(pinsLed); n++) {
digitalWrite (pinsLed [n], Off);
pinMode (pinsLed [n], OUTPUT);
}
}
@gcjr @Delta_G so i got it to work the pins on the outside are LED and inside are NO,NC,C(normaly closed etc)
buttons are typically connected between the pin and ground, the pin configured as INPUT_PULLUP to use the internal pullup resistor which pulls the pin HIGH and when pressed, the button pulls the pin LOW.
connect button using NO and Common
duplicate thread
https://forum.arduino.cc/t/momentary-push-button-wiring/1146286/2
Threads merged.
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.