- Kód: Vybrat vše
#include <Keypad.h>
#include <EEPROM.h>
float xRes = 0.1;
float yRes = 0.1;
float zRes = 0.01;
//int toolPWM = EEPROM.read(1);
int toolPWM = 255;
int pwmRes = 5;
void(* resetFunc) (void) = 0; //declare reset function at address 0
const byte ROWS = 4; //four rows
const byte COLS = 4; //four columns
char hexaKeys[ROWS][COLS] = {
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
};
byte rowPins[ROWS] = {9, 8, 7, 6}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {5, 4, 3, 2}; //connect to the column pinouts of the keypad
Keypad keypad = Keypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);
void setup() {
Serial.begin(250000);
keypad.addEventListener(keypadEvent);
}
void loop() {
char key = keypad.getKey();
}
void keypadEvent(KeypadEvent key) {
switch (keypad.getState()) {
case PRESSED:
if (key == '*') { Serial.println("M42 P44 S255"); Serial.println("M117 Spindle ON"); } // Spindle on
else if (key == '0') { Serial.println("M42 P44 S0"); Serial.println("M117 Spindle OFF"); } // Spindle off
else if (key == '#') { Serial.println("M84"); } // Motor off
else if (key == '6') { Serial.println("G91"); Serial.print("G0 X"); Serial.println(xRes); Serial.println("G90"); } // X Plus
else if (key == '4') { Serial.println("G91"); Serial.print("G0 X-"); Serial.println(xRes); Serial.println("G90"); } // X Minus
else if (key == '2') { Serial.println("G91"); Serial.print("G0 Y"); Serial.println(yRes); Serial.println("G90"); } // Y Plus
else if (key == '5') { Serial.println("G91"); Serial.print("G0 Y-"); Serial.println(yRes); Serial.println("G90"); } // Y Minus
else if (key == '3') { Serial.println("G91"); Serial.print("G0 Z"); Serial.println(zRes); Serial.println("G90"); } // Z Plus
else if (key == '1') { Serial.println("G91"); Serial.print("G0 Z-"); Serial.println(zRes); Serial.println("G90"); } // Z Minus
else if (key == 'A') { if(xRes == 0.1) {xRes = 1;} else if(xRes == 1) {xRes = 10;} else if(xRes == 10) {xRes = 50;} else if(xRes == 50) {xRes = 0.1;} } // X Resolution
else if (key == 'B') { if(yRes == 0.1) {yRes = 1;} else if(yRes == 1) {yRes = 10;} else if(yRes == 10) {yRes = 50;} else if(yRes == 50) {yRes = 0.1;} } // Y Resolution
else if (key == 'C') { if(zRes == 0.01) {zRes = 0.1;} else if(zRes == 0.1) {zRes = 1;} else if(zRes == 1) {zRes = 10;} else if(zRes == 10) {zRes = 0.01;} } // Z Resolution
else if (key == '7') { Serial.println("G28 X0 Y0"); } // XY to MIN
else if (key == '8') { Serial.println("G92 X0 Y0 Z0"); } // Set to X0 Y0 Z0
else if (key == '9') { Serial.println("G28 Z0"); } // Z to MAX
else if (key == 'D') { for (int x=0;x<5;x++) Serial.println("M112"); } // Kill
break;
case RELEASED:
break;
case HOLD:
if (key == 'A') { xRes = 0.1; } // X Resolution
else if (key == 'B') { yRes = 0.1; } // Y Resolution
else if (key == 'C') { zRes = 0.01; } // Z Resolution
else if (key == 'D') { resetFunc(); } // Restart
break;
}
}
Netušíte někdo, co to je za destičku za klávesnicí? Mini Mega 168?
Jirka