0

I am trying to write a keyboard (Key-glove) program. There are 4 buttons, and inputs should type specific keys. when the keyboard is active, I get output, but not what I am expecting for output. I get "EnE" and "EC". The Hardware is an adafruit Circuit Playground

Here is my source:

//keyboard control for TuxKart power Glove
#include <Adafruit_CircuitPlayground.h>
#include "Keyboard.h"

// set pin numbers for the five buttons:
const int Fire = 6;
const int Nitro = 9;
const int Eagle = 10;
const int _Esc = 12;

bool slideSwitch;

void setup() { // initialize the buttons' inputs:
  pinMode(Fire, INPUT);
  pinMode(Nitro, INPUT);
  pinMode(Eagle, INPUT);
  pinMode(_Esc, INPUT);

  Serial.begin(9600);
  // initialize mouse control:
  //Mouse.begin();
  Keyboard.begin();
}

void loop() {
  if (!CircuitPlayground.slideSwitch()) {
    return;
  }

  // use the pushbuttons to control the keyboard:
  if (digitalRead(Fire) == HIGH) {
    Keyboard.write('KEY_SPACE');
    Serial.println("A");
  }
  if (digitalRead(Nitro) == HIGH) {
    Keyboard.write('n');
    Serial.println("B");
  }
  if (digitalRead(Eagle) == HIGH) {
    Keyboard.write('KEY_BACKSPACE');
    Serial.println("Z");
  }
  if (digitalRead(_Esc) == HIGH) {
    Keyboard.write('KEY_ESC');
    Serial.println("Y");
  }
delay(700);
}
  • 1
    What does this have to do with Adafruit, and what board are you running it on? What program on the PC or USB host is interpreting the keystrokes, and how exactly where you expecting it to respond to the escape key? How exactly are your input switches or devices wired? Does HIGH mean active or inactive? – Chris Stratton Jul 9 '17 at 0:52
  • 3
    Remove the single quotation marks for Keyboard.write. Use Keyboard.write(KEY_SPACE); and so on. Keep them for 'n', but not for the others. – Jot Jul 9 '17 at 5:13

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.