Go Down

Topic: Button State controlling other funcitions of buttons (Read 647 times) previous topic - next topic


Hello y'all.

I have done some searching for the answer to my problem, and have yet to find a suitable answer.

I want to create a foot pedal that basically acts as a keyboard with my computer.
I have found numerous examples that demonstrate that, but I have found most of the designs lacking something.  long story short I want leds to display the status of buttons that have been pressed, and be able to have one button act as a 'shift key' and make it so the buttons are able to be used twice.
does that make sense?

and so far I have been able to write the code that reads my button press, sends a keystroke, and turns on a led. when pressed again led turns off, and the keystroke is sent again. perfect.

but my problem lies in the 'shift key', or 'bank', switch. I have tried making the keystroke on one of the buttons 'hold shift', and it works, but the program is clever enough to keep the state of the other keystrokes their original size.

more to come - I can't save to post here later?


Can you upload the sketch (between code tags).

Do you use the press and release functions ? or just the write function ?

You could send a SHIFT to the PC, or you can make some kind of 'shift'-alike code in the Arduino and change the code sent for the other buttons.


yeah here is the code

#include <Bounce.h>

Bounce button2 = Bounce(PIN_B2, 10);
Bounce button3 = Bounce(PIN_B3, 10);
int led2Pin = PIN_B4;
int led3Pin = PIN_B5;

int state2 = HIGH;     
int reading2;         
int previous2 = LOW;   
int state3 = HIGH;     
int reading3;         
int previous3 = LOW;   
long time = 0;       
long debounce = 200; 

void setup() {

  pinMode(PIN_B2, INPUT_PULLUP);
pinMode(PIN_B4, OUTPUT);
pinMode(PIN_B5, OUTPUT);
void loop() {

reading2 = digitalRead(PIN_B2);
  if (reading2 == HIGH && previous2 == LOW && millis() - time > debounce) {
    if (state2 == HIGH)
      state2 = LOW;
    state2 = HIGH;
time = millis();   
digitalWrite(PIN_B4, state2);
previous2 = reading2;

if (button2.fallingEdge()) {
    ledPin2 = HIGH;

reading3 = digitalRead(PIN_B3);
  if (reading3 == HIGH && previous3 == LOW && millis() - time > debounce) {
    if (state3 == HIGH)
      state3 = LOW;
    state3 = HIGH;
time = millis();   
digitalWrite(PIN_B5, state3);
previous3 = reading3;

if (button3.fallingEdge()) {
    ledPin3 = HIGH;

gotta go now, but this doesn't reveal the extent that I have tried.
but any help y'all can offer in the meantime (at work now, can get more into it afterwards)



That's not Arduino Leonardo code.
Are you using a Teensy ? Are the keyboard functions with a library of the Teensy ?


yes, I have a teensy, and I meant to mention that. good deduction

Go Up