Seite 1 von 1

CNC Tastatur

Verfasst: So 29. Apr 2018, 19:31
von Hannes
Hallo,

Da die Positionierung meiner CNC Fräse von der nebenstehenden Tastatur immer etwas umständlich ist, habe ich mir eine kleine CNC Tastatur gebaut. Abgehängt von der Decke, direkt bei der CNC Fräse, doch sehr praktisch bei der Positionierung. Anschluss über USB und Plug&Play.

Realisiert mittels eines Arduino Leonardo, programmiert als HID Eingabegerät und somit universell einsetzbar.
Bei Interesse an dieser oder ähnlichen Lösung, einfach melden. :D

20180429_192250.jpg
20180429_192307.jpg
20180430_083800.jpg

Hier stelle ich euch den Code für den Arduino Leonardo zur Verfügung. Bei Fragen melden ...

Code: Alles auswählen

//Tastatur Simulation mit Pfeiltasten usw.
//Hannes Dobersberger
//28.04.2018

#include "Keyboard.h"

// Input Definition für die Taster

const int buttonPin2 = 2;
const int buttonPin3 = 3;
const int buttonPin4 = 4;
const int buttonPin5 = 5;
const int buttonPin6 = 6;
const int buttonPin7 = 7;
const int buttonPin8 = 8;
const int buttonPin9 = 9;
const int buttonPin10 = 10;
const int buttonPin11 = 11;
const int buttonPin12 = 12;

// Zum Überprüfen des Status der einzelnen Taster

int previousButtonState2 = LOW;
int previousButtonState3 = LOW;
int previousButtonState4 = LOW;
int previousButtonState5 = LOW;
int previousButtonState6 = LOW;
int previousButtonState7 = LOW;
int previousButtonState8 = LOW;
int previousButtonState9 = LOW;
int previousButtonState10 = LOW;
int previousButtonState11 = LOW;
int previousButtonState12 = LOW;

//Aus den Tastern einen Input machen.
//Pullup ist für Verbindung zu Ground und nicht zu 5V.

void setup() {
  pinMode(buttonPin2, INPUT_PULLUP);
  pinMode(buttonPin3, INPUT_PULLUP);
  pinMode(buttonPin4, INPUT_PULLUP);
  pinMode(buttonPin5, INPUT_PULLUP);
  pinMode(buttonPin6, INPUT_PULLUP);
  pinMode(buttonPin7, INPUT_PULLUP);
  pinMode(buttonPin8, INPUT_PULLUP);
  pinMode(buttonPin9, INPUT_PULLUP);
  pinMode(buttonPin10, INPUT_PULLUP);
  pinMode(buttonPin11, INPUT_PULLUP);
  pinMode(buttonPin12, INPUT_PULLUP);

  //Keyboard Steuerung wird inizialisiert, gestartet.

  Keyboard.begin();
}

//Definition der einzelnen Taster.

void loop() {
  // read the pushbutton:
  int buttonState2 = digitalRead(buttonPin2);
  // if the button state has changed,
  while ((buttonState2 != previousButtonState2)
         // and it's currently pressed:
         && (buttonState2 == LOW)) {

    // type out a message
    Keyboard.press(KEY_LEFT_ARROW);
    delay(30);
    Keyboard.release(KEY_LEFT_ARROW);
    delay(30);
    buttonState2 = digitalRead(buttonPin2);
  }

  // read the pushbutton:
  int buttonState3 = digitalRead(buttonPin3);
  // if the button state has changed,
  while ((buttonState3 != previousButtonState3)
         // and it's currently pressed:
         && (buttonState3 == LOW)) {

    // type out a message
    Keyboard.press(KEY_RIGHT_ARROW);
    delay(30);
    Keyboard.release(KEY_RIGHT_ARROW);
    delay(31);
    buttonState3 = digitalRead(buttonPin3);
  }

  // read the pushbutton:
  int buttonState4 = digitalRead(buttonPin4);
  // if the button state has changed,
  while ((buttonState4 != previousButtonState4)
         // and it's currently pressed:
         && (buttonState4 == LOW)) {

    // type out a message
    Keyboard.press(KEY_UP_ARROW);
    delay(30);
    Keyboard.release(KEY_UP_ARROW);
    delay(31);
    buttonState4 = digitalRead(buttonPin4);
  }

  // read the pushbutton:
  int buttonState5 = digitalRead(buttonPin5);
  // if the button state has changed,
  while ((buttonState5 != previousButtonState5)
         // and it's currently pressed:
         && (buttonState5 == LOW)) {

    // type out a message
    Keyboard.press(KEY_DOWN_ARROW);
    delay(30);
    Keyboard.release(KEY_DOWN_ARROW);
    delay(31);
    buttonState5 = digitalRead(buttonPin5);
  }

  //Ab hier die Pfeiltasten mit Linker ALT

  // read the pushbutton:
  int buttonState6 = digitalRead(buttonPin6);
  // if the button state has changed,
  while ((buttonState6 != previousButtonState6)
         // and it's currently pressed:
         && (buttonState6 == LOW)) {

    // type out a message
    Keyboard.press(KEY_LEFT_ALT);
    delay(30);
    Keyboard.press(KEY_LEFT_ARROW);
    delay(30);
    Keyboard.releaseAll();
    delay(30);
    buttonState6 = digitalRead(buttonPin6);
  }

  // read the pushbutton:
  int buttonState7 = digitalRead(buttonPin7);
  // if the button state has changed,
  while ((buttonState7 != previousButtonState7)
         // and it's currently pressed:
         && (buttonState7 == LOW)) {

    // type out a message
    Keyboard.press(KEY_LEFT_ALT);
    delay(30);
    Keyboard.press(KEY_RIGHT_ARROW);
    delay(30);
    Keyboard.releaseAll();
    delay(30);
    buttonState7 = digitalRead(buttonPin7);
  }

  // read the pushbutton:
  int buttonState8 = digitalRead(buttonPin8);
  // if the button state has changed,
  while ((buttonState8 != previousButtonState8)
         // and it's currently pressed:
         && (buttonState8 == LOW)) {

    // type out a message
    Keyboard.press(KEY_LEFT_ALT);
    delay(30);
    Keyboard.press(KEY_UP_ARROW);
    delay(30);
    Keyboard.releaseAll();
    delay(30);
    buttonState8 = digitalRead(buttonPin8);
  }

  // read the pushbutton:
  int buttonState9 = digitalRead(buttonPin9);
  // if the button state has changed,
  while ((buttonState9 != previousButtonState9)
         // and it's currently pressed:
         && (buttonState9 == LOW)) {

    // type out a message
    Keyboard.press(KEY_LEFT_ALT);
    delay(30);
    Keyboard.press(KEY_DOWN_ARROW);
    delay(30);
    Keyboard.releaseAll();
    delay(30);
    buttonState9 = digitalRead(buttonPin9);
  }

  //Ab hier die Bild auf/ab und F Tasten


  // read the pushbutton:
  int buttonState10 = digitalRead(buttonPin10);
  // if the button state has changed,
  if ((buttonState10 != previousButtonState10)
      // and it's currently pressed:
      && (buttonState10 == LOW)) {

    // type out a message
    Keyboard.press(KEY_PAGE_UP);
    delay(30);
    Keyboard.release(KEY_PAGE_UP);
    delay(30);
    buttonState10 = digitalRead(buttonPin10);
  }

  // read the pushbutton:
  int buttonState11 = digitalRead(buttonPin11);
  // if the button state has changed,
  if ((buttonState11 != previousButtonState11)
      // and it's currently pressed:
      && (buttonState11 == LOW)) {

    // type out a message
    Keyboard.press(KEY_PAGE_DOWN);
    delay(30);
    Keyboard.release(KEY_PAGE_DOWN);
    delay(30);
    buttonState11 = digitalRead(buttonPin11);
  }

  // read the pushbutton:
  int buttonState12 = digitalRead(buttonPin12);
  // if the button state has changed,
  if ((buttonState12 != previousButtonState12)
      // and it's currently pressed:
      && (buttonState12 == LOW)) {

    // type out a message
    Keyboard.press(KEY_F4);
    delay(30);
    Keyboard.release(KEY_F4);
    delay(30);
    buttonState12 = digitalRead(buttonPin12);
  }

  //Speichert aktuellen Status der Taster für den nächsten Vergleich.

  previousButtonState2 = buttonState2;
  previousButtonState3 = buttonState3;
  previousButtonState4 = buttonState4;
  previousButtonState5 = buttonState5;
  previousButtonState6 = buttonState6;
  previousButtonState7 = buttonState7;
  previousButtonState8 = buttonState8;
  previousButtonState9 = buttonState9;
  previousButtonState10 = buttonState10;
  previousButtonState11 = buttonState11;
  previousButtonState12 = buttonState12;
}

//Richtige Schreibweise der Tastenbefehle, als Muster angehängt.

/*
  KEY_LEFT_CTRL
  KEY_LEFT_SHIFT
  KEY_LEFT_ALT
  KEY_LEFT_GUI
  KEY_RIGHT_CTRL
  KEY_RIGHT_SHIFT
  KEY_RIGHT_ALT
  KEY_RIGHT_GUI
  KEY_UP_ARROW
  KEY_DOWN_ARROW
  KEY_LEFT_ARROW
  KEY_RIGHT_ARROW
  KEY_BACKSPACE
  KEY_TAB
  KEY_RETURN
  KEY_ESC
  KEY_INSERT
  KEY_DELETE
  KEY_PAGE_UP
  KEY_PAGE_DOWN
  KEY_HOME
  KEY_END
  KEY_CAPS_LOCK
  KEY_F1
  KEY_F2
  KEY_F3
  KEY_F4
  KEY_F5
  KEY_F6
  KEY_F7
  KEY_F8
  KEY_F9
  KEY_F10
  KEY_F11
  KEY_F12
*/