Use toggle switch to send one time keystoke

Hi, I’m a complete noob and willing to use a toggle switch (ON-OFF) to send keystroke,
for the moment I found and made work with a LED (goes red when ON and green when OFF)
but as the code is in the loop() it goes for ever, and made it blink.
i want to make it blink one time until the state (ON -OFF) change from one to another with always one time blink (or keystroke and the end of the project) for ever.
here is my code

#include <HID-Project.h>
#include <HID-Settings.h>

int switch_pin = A6;
int ledR = 16;
int ledG = 14;

void setup() {
  pinMode(switch_pin, INPUT);
  pinMode(ledR, OUTPUT);
  pinMode(ledG, OUTPUT);
}

void loop() {
                       
  if (digitalRead(switch_pin) == HIGH) {
    digitalWrite(ledR, HIGH);
    delay(300);
    digitalWrite(ledR, LOW);
    //Keyboard.write('D');
    delay(700);
  }

  if (digitalRead(switch_pin) == LOW) {
    digitalWrite(ledG, HIGH);
    delay(300);
    digitalWrite(ledG, LOW);
    //Keyboard.write('E');
    delay(700);
  }
}


Thanks for any support !

When an event happens, set a boolean Flag variable.

When your code sees the Flag set, you blink your LED then reset the Flag.

The key is to set the Flag , for example when a switch goes from HIGH to LOW.


BTW, never ever use delay() in you code.

thanks for the fast reply !
but I’ll be honest, I don’t have any clue to do this :grimacing: and also don’t know what I could use instead of delay()…

The following sketch is not exactly what you want but it should give you some ideas of what you can do.

Note, the Arduino pins are different than in your sketch.

//Version 1.0

//#include <HID-Project.h>
//#include <HID-Settings.h>

//const byte switch_pin               = A6;
//const byte ledR                     = 16;
//const byte ledG                     = 14;

const byte switch_pin               = 8;
const byte ledR                     = 9;
const byte ledG                     = 10;
const byte heartbeatLed             = 13;

//0 = waiting for red   switch push, 1 = red ON timing, 2 = red OFF timing,
//3 = waiting for green switch push, 4 = green ON timing, 5 = green OFF timing
byte myFlag                         = 0;

byte lastSwitchState;

//timing stuff
unsigned long heartbeatMillis;
unsigned long blinkMillis;

unsigned long blinkItervalHigh      = 300;
unsigned long blinkItervalLow       = 700;



//***************************************************************************
void setup()
{
  pinMode(switch_pin, INPUT_PULLUP);  //switch connected to GND, cloed = LOW = pushed
  lastSwitchState = digitalRead(switch_pin);

  pinMode(heartbeatLed, OUTPUT);
  pinMode(ledR, OUTPUT);
  pinMode(ledG, OUTPUT);

} //END of setup()

//***************************************************************************
void loop()
{
  //********************************
  //time to toggle the heartbeat LED ?
  if(millis() - heartbeatMillis >= 500)
  {
    heartbeatMillis = millis();

    //toggle the heartbeat LED
    digitalWrite(heartbeatLed, !digitalRead(heartbeatLed));
  }
  
  //********************************
  //Change in switch state
  byte state = digitalRead(switch_pin);
  if (lastSwitchState != state)
  {
    //update to the new state
    lastSwitchState = state;

    //if we are not Timing, did the switch close ?
    if ((myFlag == 0 || myFlag == 3) && state == LOW)
    {
      //enable Timer
      myFlag++;

      //turn the RED LED ON ?
      if (myFlag == 1)
      {
        digitalWrite(ledR, HIGH);
      }

      //turn the GREEN LED ON ?
      else if (myFlag == 4)
      {
        digitalWrite(ledG, HIGH);
      }

      //restart the Timer
      blinkMillis = millis();
    }
  }

  //********************************
  //RED LED stuff
  if (myFlag == 1 && millis() - blinkMillis >= blinkItervalHigh)
  {
    //change to LED OFF timing
    myFlag = 2;

    //turn the red LED OFF
    digitalWrite(ledR, LOW);

    //restart the Timer
    blinkMillis = millis();
  }

  //**********
  if (myFlag == 2 && millis() - blinkMillis >= blinkItervalLow)
  {
    //change to green switch waiting
    myFlag = 3;

  }

  //********************************
  //GREEN LED stuff
  if (myFlag == 4 && millis() - blinkMillis >= blinkItervalHigh)
  {
    //change to LED OFF timing
    myFlag = 5;

    //turn the green LED OFF
    digitalWrite(ledG, LOW);

    //restart the Timer
    blinkMillis = millis();
  }

  //**********
  if (myFlag == 5 && millis() - blinkMillis >= blinkItervalLow)
  {
    //disable timing
    myFlag = 0;
  }

} //END of loop()

//***************************************************************************

thanks again ! I’ll studies that right now ! :+1:

thank you so much ! it works ! so I manage to add 2 more switch, by declaring other “lastSwitchState2” and 3 but 2 of them work correctly, and the first one does not work anymore :laughing: it’s acting like a normal ON OFF with led switching red to green when it’s ON and nothing OFF
I’m pretty sure there must be a better way than duplicate but as I don’t know how to do better …
here is what I changed

//Version 1.0

#include <HID-Project.h>
#include <HID-Settings.h>

const byte switch1_pin               = 5;
const byte switch2_pin               = A7;
const byte switch3_pin               = 7;
const byte ledR                     = 16;
const byte ledG                     = 14;

//const byte switch_pin               = 8;
//const byte ledR                     = 9;
//const byte ledG                     = 10;
const byte heartbeatLed             = 15;

//0 = waiting for red   switch push, 1 = red ON timing, 2 = red OFF timing,
//3 = waiting for green switch push, 4 = green ON timing, 5 = green OFF timing
byte myFlag                         = 0;

byte lastSwitchState1;
byte lastSwitchState2;
byte lastSwitchState3;


//timing stuff
unsigned long heartbeatMillis;
unsigned long blinkMillis;

unsigned long blinkIntervalHigh      = 300;
unsigned long blinkIntervalLow       = 700;



//***************************************************************************
void setup()
{
  pinMode(switch1_pin, INPUT);  //switch connected to GND, cloed = LOW = pushed
  lastSwitchState1 = digitalRead(switch1_pin);
  pinMode(switch2_pin, INPUT);  //switch connected to GND, cloed = LOW = pushed
  lastSwitchState2 = digitalRead(switch2_pin);
  pinMode(switch3_pin, INPUT);  //switch connected to GND, cloed = LOW = pushed
  lastSwitchState3 = digitalRead(switch3_pin);

  pinMode(heartbeatLed, OUTPUT);
  pinMode(ledR, OUTPUT);
  pinMode(ledG, OUTPUT);

} //END of setup()

//***************************************************************************
void loop()
{
  //********************************
  //time to toggle the heartbeat LED ?
  if (millis() - heartbeatMillis >= 500)
  {
    heartbeatMillis = millis();

    //toggle the heartbeat LED
    digitalWrite(heartbeatLed, !digitalRead(heartbeatLed));
  }

  //********************************
  //Change in switch1 state
 byte state1 = digitalRead(switch1_pin);
  if (lastSwitchState1 != state1)
  {
    //update to the new state
    lastSwitchState1 = state1;

    //if we are not Timing, did the switch close ?
    if ((myFlag == 0 || myFlag == 3) && state1 == LOW)
    {
      //enable Timer
      myFlag++;

      //turn the RED LED ON ?
      if (myFlag == 1)
      {
        digitalWrite(ledR, HIGH);
        Keyboard.write('D');
      }

      //turn the GREEN LED ON ?
      else if (myFlag == 4)
      {
        digitalWrite(ledG, HIGH);
        Keyboard.write('D');
      }

      //restart the Timer
      blinkMillis = millis();
    }
  }
  //----------------------
  //Change in switch2 state
  byte state2 = digitalRead(switch2_pin);
  if (lastSwitchState2 != state2)
  {
    //update to the new state
    lastSwitchState2 = state2;

    //if we are not Timing, did the switch close ?
    if ((myFlag == 0 || myFlag == 3) && state2 == LOW)
    {
      //enable Timer
      myFlag++;

      //turn the RED LED ON ?
      if (myFlag == 1)
      {
        digitalWrite(ledR, HIGH);
        Keyboard.write('E');
      }

      //turn the GREEN LED ON ?
      else if (myFlag == 4)
      {
        digitalWrite(ledG, HIGH);
        Keyboard.write('E');
      }

      //restart the Timer
      blinkMillis = millis();
    }
  }

  //----------------------
  //Change in switch3 state
  byte state3 = digitalRead(switch3_pin);
  if (lastSwitchState3 != state3)
  {
    //update to the new state
    lastSwitchState3 = state3;

    //if we are not Timing, did the switch close ?
    if ((myFlag == 0 || myFlag == 3) && state3 == LOW)
    {
      //enable Timer
      myFlag++;

      //turn the RED LED ON ?
      if (myFlag == 1)
      {
        digitalWrite(ledR, HIGH);
        Keyboard.write('Z');
      }

      //turn the GREEN LED ON ?
      else if (myFlag == 4)
      {
        digitalWrite(ledG, HIGH);
        Keyboard.write('Z');
      }

      //restart the Timer
      blinkMillis = millis();
    }
  }
  //********************************
  //RED LED stuff
  if (myFlag == 1 && millis() - blinkMillis >= blinkIntervalHigh)
  {
    //change to LED OFF timing
    myFlag = 2;

    //turn the red LED ON
    digitalWrite(ledR, LOW);


    //restart the Timer
    blinkMillis = millis();
  }

  //**********
  if (myFlag == 2 && millis() - blinkMillis >= blinkIntervalLow)
  {
    //change to green switch waiting
    myFlag = 3;

  }

  //********************************
  //GREEN LED stuff
  if (myFlag == 4 && millis() - blinkMillis >= blinkIntervalHigh)
  {
    //change to LED OFF timing
    myFlag = 5;

    //turn the green LED OFF
    digitalWrite(ledG, LOW);


    //restart the Timer
    blinkMillis = millis();
  }

  //**********
  if (myFlag == 5 && millis() - blinkMillis >= blinkIntervalLow)
  {
    //disable timing
    myFlag = 0;
  }

} //END of loop()

//***************************************************************************

i was assuming that the Flag could work for all the switch I add, is there some limitation i did not see ?

My bad the switch was defective, a soon I change for an other one evetihing went well ! thanks for all the support ! wish you the best @LarryD !

As I planned I add other part of my project, along this part of code, but a weird issue is coming now.

Along the 3 switch i add :

  • a 12 button keypad
  • a rotary encoder
  • 5 more button
  • a joystick

Every thing works well except when I inserted the joystick code : all switch get randomly detected and the joystick work normally, if i put the Joystick parts of code in comment, all switch work as intended again.
Here is my code again if somebody can spot the culprit

/*
   Links:
    Keyboard Library documentation: https://github.com/arduino-libraries/Keyboard/blob/master/src/Keyboard.h
    HID-Project library documentation: https://github.com/NicoHood/HID/wiki/Consumer-API
*/
#include <HID-Project.h>
#include <HID-Settings.h>


// GENERAL PART

#define ledStatus 15

//ROTARY PART

// Rotary Encoder Inputs
#define inputCLK A1
#define inputDT A2
#define inputSW A3

int currentStateCLK;
int previousStateCLK;
int mode = 1;
int maxModes = 3;

// BUTTON PART

#define inputBT1 2
#define inputBT2 3
#define inputBT3 18
#define inputBT4 16
#define inputBT5 10


//JOYSTICK PART


//int horzPin = A0;  // Analog output of horizontal joystick pin
//int vertPin = A8;  // Analog output of vertical joystick pin
//int selPin = 14;  // select button pin of joystick
const int pinLed = LED_BUILTIN;
const int pinButton = 14;
const int pinY = A8;
const int pinX = A6;
bool action = false;


// JOYSTICK MOUSE PART

int vertZero, horzZero;  // Stores the initial value of each axis, usually around 512
int vertValue, horzValue;  // Stores current analog output of each axis
const int sensitivity = 150;  // Higher sensitivity value = slower mouse, should be <= about 500
int mouseClickFlag = 0;


//KEYPAD PART

char KEYS[] = { '1', '2', '3', '4', '5', '6', '7', '8', '9', '*', '0', '#'
              };
int keypress = 0;
int keypressold = 0;
int button = 0;
int oldbutton = 0; boolean change = false; int cptkeypad = 0;

//SWITCH PART

int ledR = 0;
int ledG = 0;
const byte switch1_pin               = 5;
const byte switch2_pin               = A7;
const byte switch3_pin               = 7;
const byte heartbeatLed               = 0;

//0 = waiting for red   switch push, 1 = red ON timing, 2 = red OFF timing,
//3 = waiting for green switch push, 4 = green ON timing, 5 = green OFF timing
byte myFlag                         = 0;

byte lastSwitchState1;
byte lastSwitchState2;
byte lastSwitchState3;


//timing stuff
unsigned long heartbeatMillis;
unsigned long blinkMillis;
unsigned long blinkIntervalHigh      = 3;
unsigned long blinkIntervalLow       = 7;


//***************************************************************************
void setup() {

  //GENERAL PART

  Consumer.begin();
  Keyboard.begin();
  Mouse.begin();
  pinMode(ledStatus, OUTPUT);

  //ROTARY PART

  // Set encoder pins as inputs
  pinMode (inputCLK, INPUT);
  pinMode (inputDT, INPUT);
  pinMode(inputSW, INPUT_PULLUP);
  // Read the initial state of inputCLK
  // Assign to previousStateCLK variable
  previousStateCLK = digitalRead(inputCLK);

  //KEYPAD PART

  pinMode(ledR, OUTPUT);
  pinMode(ledG, OUTPUT);
  pinMode(A9, INPUT);

  // BUTTONS PART
  pinMode(inputBT1, INPUT_PULLUP);
  pinMode(inputBT2, INPUT_PULLUP);
  pinMode(inputBT3, INPUT_PULLUP);
  pinMode(inputBT4, INPUT_PULLUP);
  pinMode(inputBT5, INPUT_PULLUP);

  //JOYSTICK PART

  pinMode(pinLed, OUTPUT);
  pinMode(pinX, INPUT);  // Set both analog pins as inputs
  pinMode(pinY, INPUT);
  pinMode(pinButton, INPUT_PULLUP);  // set button select pin as input
  digitalWrite(pinButton, HIGH);  // Pull button select pin high
  vertZero = analogRead(pinX);  // get the initial values
  horzZero = analogRead(pinY);  // Joystick should be in neutral position when reading these


  //JOYSTICK TO ARROW PART

  // Sends a clean report to the host. This is important on any Arduino type.
  BootKeyboard.begin();

  // SWITCH PART

  pinMode(switch1_pin, INPUT);  //switch connected to GND, cloed = LOW = pushed
  lastSwitchState1 = digitalRead(switch1_pin);
  pinMode(switch2_pin, INPUT);  //switch connected to GND, cloed = LOW = pushed
  lastSwitchState2 = digitalRead(switch2_pin);
  pinMode(switch3_pin, INPUT);  //switch connected to GND, cloed = LOW = pushed
  lastSwitchState3 = digitalRead(switch3_pin);

  pinMode(heartbeatLed, OUTPUT);


}//END of setup()

//***************************************************************************


void loop() {



  //ROTARY PART

  // Read the current state of inputCLK
  currentStateCLK = digitalRead(inputCLK);

  // If the previous and the current state of the inputCLK are different then a pulse has occured
  if (currentStateCLK != previousStateCLK) {
    // If the inputDT state is different than the inputCLK state then
    // the encoder is rotating counterclockwise
    if (digitalRead(inputDT) != currentStateCLK) {
      rotateRight();
    } else {
      rotateLeft();
    }
  }
  // Update previousStateCLK with the current state
  previousStateCLK = currentStateCLK;


  if (!digitalRead(inputSW)) {
    changeMode();
    delay(300);
  }


  //KEYPAD PART

  keypress = analogRead(A9);
  if (keypress == 0) {
    // si j’appuye 2 fois de suite sur le meme bouton, il faut que je reinitialise // le boolean change pour detecter un nouvel appui
    // j’ attends ton la reception de 5 valeurs 0 avant de changer l’etat. cptkeypad++;
    if (cptkeypad == 500) {
      change = false; cptkeypad = 0; button = 0;
    }
  }
  else {
    if (oldbutton != button) {
      Serial.print(cptkeypad); Serial.print (" : "); Serial.print(keypress); Serial.print (" - "); Serial.println(button);
    }
  }
  if (keypress < 1030 && keypress > 1000) {
    button = 1;
    Keyboard.write(KEYPAD_1);
    delay(200);
  }
  if (keypress < 940 && keypress > 920) {
    button = 2;
    Keyboard.write(KEYPAD_2);
    delay(200);
  }
  if (keypress < 860 && keypress > 840) {
    button = 3;
    Keyboard.write(KEYPAD_3);
    delay(200);
  }
  if (keypress < 800 && keypress > 780) {
    button = 4;
    Keyboard.write(KEYPAD_4);
    delay(200);
  }
  if (keypress < 740 && keypress > 720) {
    button = 5;
    Keyboard.write(KEYPAD_5);
    delay(200);
  }
  if (keypress < 690 && keypress > 670) {
    button = 6;
    Keyboard.write(KEYPAD_6);
    delay(200);
  }
  if (keypress < 650 && keypress > 630) {
    button = 7;
    Keyboard.write(KEYPAD_7);
    delay(200);
  }
  if (keypress < 610 && keypress > 590) {
    button = 8;
    Keyboard.write(KEYPAD_8);
    delay(200);
  }
  if (keypress < 580 && keypress > 560) {
    button = 9;
    Keyboard.write(KEYPAD_9);
    delay(200);
  }
  if (keypress < 550 && keypress > 530) {
    button = 10;
    Keyboard.write(KEY_SPACE);
    delay(200);
  }
  if (keypress < 520 && keypress > 500 ) {
    button = 11;
    Keyboard.write(KEYPAD_0);
    delay(200);
  }
  if (keypress < 495 && keypress > 480) {
    button = 12;
    Keyboard.write(KEY_RETURN);
    delay(200);
  }
  if (button != oldbutton) {
    Serial.print (button);
    Serial.println (" is pressed"); change = true;
  }

  oldbutton = button;



  // BUTTON PART

  if (!digitalRead(inputBT1)) {
    Keyboard.write('E');
    //Keyboard.write(KEY_SPACE);
    delay(200);

  }
  if (!digitalRead(inputBT2)) {
    Keyboard.write('D');
    //Mouse.click(MOUSE_RIGHT);
    delay(200);

  }
  if (!digitalRead(inputBT3)) {
    Keyboard.write('C');
    delay(200);

  }
  if (!digitalRead(inputBT4)) {
    Keyboard.write('B');
    delay(200);

  }
  if (!digitalRead(inputBT5)) {
    Keyboard.write('Q');
    //Keyboard.write(KEY_ESC);
    delay(200);

  }
/*
  //JOYSTICK TO MOUSE PART 1

  vertValue = analogRead(pinY) - vertZero;  // read vertical offset
  horzValue = analogRead(pinX) - horzZero;  // read horizontal offset

  if (vertValue != 0)
    Mouse.move(0, vertValue / sensitivity, 0); // move mouse on y axis
  if (horzValue != 0)
    Mouse.move(horzValue / sensitivity, 0, 0); // move mouse on x axis

  if ((digitalRead(pinButton) == 0) && (!mouseClickFlag))  // if the joystick button is pressed
  {
    mouseClickFlag = 1;
    Mouse.press(MOUSE_LEFT);  // click the left button down
  }
  else if ((digitalRead(pinButton)) && (mouseClickFlag)) // if the joystick button is not pressed
  {
    mouseClickFlag = 0;
    Mouse.release(MOUSE_LEFT);  // release the left button
  }

 */

      //JOYSTICK TO MOUSE 2 PART

 
  /*
       //JOYSTICK TO ARROW PART

    if (BootKeyboard.getProtocol() == HID_BOOT_PROTOCOL)
      digitalWrite(pinLed, HIGH);
    else
      digitalWrite(pinLed, LOW);

    int valueY = analogRead(pinY);
    int valueX = analogRead(pinX);
    int button = digitalRead(pinButton);

    // Send actions
    if (!button) {
      BootKeyboard.write(KEY_ENTER);
      action = true;
    }

    if (valueX > 1000 ) {
      BootKeyboard.write(KEY_RIGHT);
      action = true;
    }

    if (valueX < 24 ) {
      BootKeyboard.write(KEY_LEFT);
      action = true;
    }

    if (valueY > 1000 ) {
      BootKeyboard.write(KEY_DOWN);
      action = true;
    }

    if (valueY < 24 ) {
      BootKeyboard.write(KEY_UP);
      action = true;
    }

    if (action) {
      // Simple debounce
      delay(200);
      //action = false;
    }

    delay(10);
  */
  //SWITCH PART

  //********************************
  //time to toggle the heartbeat LED ?
  if (millis() - heartbeatMillis >= 1)
  {
    heartbeatMillis = millis();

    //toggle the heartbeat LED
    digitalWrite(heartbeatLed, !digitalRead(heartbeatLed));
  }

  //********************************
  //Change in switch1 state
  byte state1 = digitalRead(switch1_pin);
  if (lastSwitchState1 != state1)
  {
    //update to the new state
    lastSwitchState1 = state1;

    //if we are not Timing, did the switch close ?
    if ((myFlag == 0 || myFlag == 3) && state1 == LOW)
    {
      //enable Timer
      myFlag++;

      //turn the RED LED ON ?
      if (myFlag == 1)
      {
        digitalWrite(ledR, HIGH);
        Keyboard.write('H');
      }

      //turn the GREEN LED ON ?
      else if (myFlag == 4)
      {
        digitalWrite(ledG, HIGH);
        Keyboard.write('H');
      }

      //restart the Timer
      blinkMillis = millis();
    }
  }
  //----------------------
  //Change in switch2 state
  byte state2 = digitalRead(switch2_pin);
  if (lastSwitchState2 != state2)
  {
    //update to the new state
    lastSwitchState2 = state2;

    //if we are not Timing, did the switch close ?
    if ((myFlag == 0 || myFlag == 3) && state2 == LOW)
    {
      //enable Timer
      myFlag++;

      //turn the RED LED ON ?
      if (myFlag == 1)
      {
        digitalWrite(ledR, HIGH);
        Keyboard.write('G');
      }

      //turn the GREEN LED ON ?
      else if (myFlag == 4)
      {
        digitalWrite(ledG, HIGH);
        Keyboard.write('G');
      }

      //restart the Timer
      blinkMillis = millis();
    }
  }

  //----------------------
  //Change in switch3 state
  byte state3 = digitalRead(switch3_pin);
  if (lastSwitchState3 != state3)
  {
    //update to the new state
    lastSwitchState3 = state3;

    //if we are not Timing, did the switch close ?
    if ((myFlag == 0 || myFlag == 3) && state3 == LOW)
    {
      //enable Timer
      myFlag++;

      //turn the RED LED ON ?
      if (myFlag == 1)
      {
        digitalWrite(ledR, HIGH);
        Keyboard.write('F');
      }

      //turn the GREEN LED ON ?
      else if (myFlag == 4)
      {
        digitalWrite(ledG, HIGH);
        Keyboard.write('F');
      }

      //restart the Timer
      blinkMillis = millis();
    }
  }
  //********************************
  //RED LED stuff
  if (myFlag == 1 && millis() - blinkMillis >= blinkIntervalHigh)
  {
    //change to LED OFF timing
    myFlag = 2;

    //turn the red LED ON
    //digitalWrite(ledR, LOW);


    //restart the Timer
    blinkMillis = millis();
  }

  //**********
  if (myFlag == 2 && millis() - blinkMillis >= blinkIntervalLow)
  {
    //change to green switch waiting
    myFlag = 3;

  }

  //********************************
  //GREEN LED stuff
  if (myFlag == 4 && millis() - blinkMillis >= blinkIntervalHigh)
  {
    //change to LED OFF timing
    myFlag = 5;

    //turn the green LED OFF
    //digitalWrite(ledG, LOW);


    //restart the Timer
    blinkMillis = millis();
  }

  //**********
  if (myFlag == 5 && millis() - blinkMillis >= blinkIntervalLow)
  {
    //disable timing
    myFlag = 0;
  }

}//END of loop()

//***************************************************************************

// ROTARY PART
void changeMode() {
  mode = (mode % maxModes) + 1;
  digitalWrite(ledStatus, HIGH);
  delay(500);
  digitalWrite(ledStatus, LOW);
}


void rotateRight() {
  switch (mode) {

    case 1:
      // Increase the volume.
      Consumer.write(MEDIA_VOLUME_UP);
      break;

    case 2:
      // Mouse whell DOWN.
      Mouse.move(0, 0, 1);
      break;

    case 3:
      Keyboard.write(KEY_UP_ARROW);
      break;

  }
}

void rotateLeft() {
  switch (mode) {

    case 1:
      // Increase the volume.
      Consumer.write(MEDIA_VOLUME_DOWN);
      break;

    case 2:
      // Mouse whell DOWN.
      Mouse.move(0, 0, -1);
      break;

    case 3:
      Keyboard.write(KEY_DOWN_ARROW);
      break;

  }
}

Also I use a Arduino pro micro

Thanks again for the support !

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.