I just want to configure my laptops keyboard buttons a,s,d,f,g,h and j. I wrote this code and it works for only a but I couldn't configure other buttons.

Code is:

#include "Keyboard.h"

const int buttonPin = 3;          // input pin for pushbutton
int previousButtonState = HIGH;   // for checking the state of a pushButton
int counter = 0;                  // button push counter

void setup() {
  // make the pushButton pin an input:
  pinMode(buttonPin, INPUT);
  // initialize control over the keyboard:

void loop() {
  // read the pushbutton:
  int buttonState = digitalRead(buttonPin);
  // if the button state has changed,
  if ((buttonState != previousButtonState)
      // and it's currently pressed:
      && (buttonState == HIGH)) {
    // increment the button counter
    // type out a message
  // save the current button state for comparison next time:
  previousButtonState = buttonState;

How can I configure other buttons s,d,f,g,h and j to pin buttons 4,5,6,7,8 and 9.

Thanks for help:)

  • 1
    You could basically duplicate your code and variables to handle each button, or you could do things with an array or even an object-oriented approach. 6 buttons is about at the point where duplication is unsophisticated, but still practical if it best fits your understanding. Also you might want to get rid of what looks like a dummy/test 'a' in the setup. May 25 '16 at 21:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.