Hi everyone.
i need some help with my project.
iam trying to make a cnc pedant that work with the hid function with mach3.
I found a code that i like to use and from there to expand it to my needs.
the code use the basic futures.
a mpg handwheel to jog and one 3 position switch to select the X or Y Or Z axis.
this is the code i find:
// bCNC Pendant
// https://github.com/mprochnow/CNC-Engraver
// Original author: Martin J. Prochnow <email@martin-prochnow.de>
// License: CC BY-SA 4.0 (Attribution-ShareAlike 4.0 International, http://creativecommons.org/licenses/by-sa/4.0/)
#include <Keyboard.h>
#define pinA 2 // Arduino Pin 2 => ATmega32u4 PD1
#define pinB 3 // Arduino Pin 3 => ATmega32u4 PD0
#define pinX 4
#define pinY 5
#define pinZ 6
#define debounceThreshold 700 // microseconds
volatile unsigned long debounceLast = 0;
volatile char step = 0;
void setup() {
pinMode(pinA, INPUT);
pinMode(pinB, INPUT);
pinMode(pinX, INPUT_PULLUP);
pinMode(pinY, INPUT_PULLUP);
pinMode(pinZ, INPUT_PULLUP);
attachInterrupt(1, readEncoder, RISING);
Keyboard.begin();
}
void loop() {
if (step == -1) {
if (digitalRead(pinX) == LOW) {
Keyboard.press(KEY_LEFT_ARROW);
Keyboard.release(KEY_LEFT_ARROW);
} else if (digitalRead(pinY) == LOW) {
Keyboard.press(KEY_DOWN_ARROW);
Keyboard.release(KEY_DOWN_ARROW);
} else if (digitalRead(pinZ) == LOW) {
Keyboard.press(KEY_PAGE_DOWN);
Keyboard.release(KEY_PAGE_DOWN);
}
step = 0;
} else if (step == 1) {
if (digitalRead(pinX) == LOW) {
Keyboard.press(KEY_RIGHT_ARROW);
Keyboard.release(KEY_RIGHT_ARROW);
} else if (digitalRead(pinY) == LOW) {
Keyboard.press(KEY_UP_ARROW);
Keyboard.release(KEY_UP_ARROW);
} else if (digitalRead(pinZ) == LOW) {
Keyboard.press(KEY_PAGE_UP);
Keyboard.release(KEY_PAGE_UP);
}
step = 0;
}
}
void readEncoder() {
if (micros() - debounceLast > debounceThreshold) {
debounceLast = micros();
// PIND = Port D Input Pins Address
// Check if PD1 is set
if (PIND & B00000010) {
// Check if PD0 is set
if (PIND & B00000001) {
step = -1; // CCW
}
else {
step = 1; // CW
}
}
}
}
but it give me some faults but i think i have all the libraries that i need.
i try to copy past the error readings i get from my IDE
C:\Users\Trial\Documents\Arduino\bCNC_Pendant\bCNC_Pendant.ino: In function 'void setup()':
C:\Users\Trial\Documents\Arduino\bCNC_Pendant\bCNC_Pendant.ino:28:3: error: 'Keyboard' was not declared in this scope
Keyboard.begin();
^~~~~~~~
C:\Users\Trial\Documents\Arduino\bCNC_Pendant\bCNC_Pendant.ino: In function 'void loop()':
C:\Users\Trial\Documents\Arduino\bCNC_Pendant\bCNC_Pendant.ino:34:7: error: 'Keyboard' was not declared in this scope
Keyboard.press(KEY_LEFT_ARROW);
^~~~~~~~
C:\Users\Trial\Documents\Arduino\bCNC_Pendant\bCNC_Pendant.ino:34:22: error: 'KEY_LEFT_ARROW' was not declared in this scope
Keyboard.press(KEY_LEFT_ARROW);
^~~~~~~~~~~~~~
C:\Users\Trial\Documents\Arduino\bCNC_Pendant\bCNC_Pendant.ino:37:7: error: 'Keyboard' was not declared in this scope
Keyboard.press(KEY_DOWN_ARROW);
^~~~~~~~
C:\Users\Trial\Documents\Arduino\bCNC_Pendant\bCNC_Pendant.ino:37:22: error: 'KEY_DOWN_ARROW' was not declared in this scope
Keyboard.press(KEY_DOWN_ARROW);
^~~~~~~~~~~~~~
C:\Users\Trial\Documents\Arduino\bCNC_Pendant\bCNC_Pendant.ino:40:7: error: 'Keyboard' was not declared in this scope
Keyboard.press(KEY_PAGE_DOWN);
^~~~~~~~
C:\Users\Trial\Documents\Arduino\bCNC_Pendant\bCNC_Pendant.ino:40:22: error: 'KEY_PAGE_DOWN' was not declared in this scope
Keyboard.press(KEY_PAGE_DOWN);
^~~~~~~~~~~~~
C:\Users\Trial\Documents\Arduino\bCNC_Pendant\bCNC_Pendant.ino:47:7: error: 'Keyboard' was not declared in this scope
Keyboard.press(KEY_RIGHT_ARROW);
^~~~~~~~
C:\Users\Trial\Documents\Arduino\bCNC_Pendant\bCNC_Pendant.ino:47:22: error: 'KEY_RIGHT_ARROW' was not declared in this scope
Keyboard.press(KEY_RIGHT_ARROW);
^~~~~~~~~~~~~~~
C:\Users\Trial\Documents\Arduino\bCNC_Pendant\bCNC_Pendant.ino:50:7: error: 'Keyboard' was not declared in this scope
Keyboard.press(KEY_UP_ARROW);
^~~~~~~~
C:\Users\Trial\Documents\Arduino\bCNC_Pendant\bCNC_Pendant.ino:50:22: error: 'KEY_UP_ARROW' was not declared in this scope
Keyboard.press(KEY_UP_ARROW);
^~~~~~~~~~~~
C:\Users\Trial\Documents\Arduino\bCNC_Pendant\bCNC_Pendant.ino:53:7: error: 'Keyboard' was not declared in this scope
Keyboard.press(KEY_PAGE_UP);
^~~~~~~~
C:\Users\Trial\Documents\Arduino\bCNC_Pendant\bCNC_Pendant.ino:53:22: error: 'KEY_PAGE_UP' was not declared in this scope
Keyboard.press(KEY_PAGE_UP);
^~~~~~~~~~~
Multiple libraries were found for "Keyboard.h"
Used: C:\Users\Trial\Documents\Arduino\libraries\Keyboard
Not used: C:\Users\Trial\AppData\Local\Arduino15\libraries\Keyboard
exit status 1
Compilation error: 'Keyboard' not found. Does your sketch include the line '#include <Keyboard.h>'?
hope i missing something why i cant upload it to my arduino and can go further with the project.
Rolf Koedam