Arduino nano is not working with programing

So, I was originally using a Arduino Leonardo and this code worked just fine but right as i switch to a nano is goes beserk and tells me "keyboard" is not included. I need help figuring out what i need to fix or add

dcs-bios-arduino-library-0.2.11 (1).zip (24.5 KB) --This is the libary for DCS Bios if needed

#include "Keyboard.h"
#define DCSBIOS_IRQ_SERIAL
#include "DcsBios.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'};
char hotkeysOff[] = {'g', 'c', 'q', 'a', 'b', 'w', 'd', 'l', 's', 'j', 'k', 'm', 'x'};

void setup() {
  DcsBios::setup();
  for (int i = 0; i <= 13; i++) {
    pinMode(i, INPUT);
  }
  Keyboard.begin();
  Serial.begin(9600);
}

void loop() {
  DcsBios::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);
}

The keyboard library will not work on a Nano or other atmega328 based board, it needs a processor with native USB support (USB hardware built into the processor itself).

Note the following from the Keyboard reference page:

So i need to change my programming? @david_2018 or do i need another libary?

The programming is not the problem, the problem is that the Nano uses a USB-to-serial chip, not the native USB hardware built into the atmega32u4 used on a Leonardo. If you need a smaller board, use an arduino Micro or Pro Micro (NOT a Mini/Pro Mini).

well i have only a nano and nano is one of the few that works with DCS bios, so if i dont switch i have to change my code?

Sorry, I'm not familiar with DCS Bios, someone else will have to help you with that.

The "classic" Nano cannot emulate a USB keyboard. What do you really want to do?

I click a switch and it corresponds in game, to an action

Fascinating!

If the game expects the input from a USB keyboard, it follows that the nano won't be useful.

well that was the old code not following DCS bios, i used a leonardo and that code to imitate a keyboard and replace the buttons with switches but i want to a a rotary dial and LED's and the leonardo wont support it with the game, so i got the nano because it works with DCS bios and such. But my guess is i have to write new code and it will work @Delta_G

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