#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 20, 4); // set the LCD address to 0x27 for a 16 chars and 2 line display
// pin assignments
const int STR_PIN = A3;
const int INC_PIN = A0;
const int DEC_PIN = A1;
const int STP_PIN = A2;
// Drivers Configuration
const int Y_microsteps = 400;
const int Z_microsteps = 400;
// Ball screw info
const int Y_mm_per_rev = 10;
const int Z_mm_per_rev = 10;
// Motors Configuration
float Y_spd = 50; // in mm per sec
float Z_spd = 50; // in mm per sec
float Y_acc = 25; // in mm per sec
float Z_acc = 25; // in mm per sec
// Home Configuration
const float Y_homingSpeedInMMPerSec = 10.0;
const float Z_homingSpeedInMMPerSec = 10.0;
const float Y_maxHomingDistanceInMM = 900;
const float Z_maxHomingDistanceInMM = 300;
const int Y_directionTowardHome = -1; // direction to move toward limit switch: 1 goes positive direction, -1 backward
const int Z_directionTowardHome = -1; // direction to move toward limit switch: 1 goes positive direction, -1 backward
// drill configuration in mm
int Y_step = 10;
int Z_safe = 10;
int Z_depth = 10;
int no_holes = 28;
bool moving = false;
int selection[] = {0, 0, 0};
int selection_level = 0;
void setup()
{
// Start Serial
Serial.begin(9600);
// initialize the lcd
lcd.init();
lcd.backlight();
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Main Menu");
lcd.setCursor(0, 1);
lcd.print("1: Start");
// defining button pin conditions
pinMode(STR_PIN, INPUT_PULLUP);
pinMode(INC_PIN, INPUT_PULLUP);
pinMode(DEC_PIN, INPUT_PULLUP);
pinMode(STP_PIN, INPUT_PULLUP);
}
void loop() {
// put your main code here, to run repeatedly:
// Serial.println(digitalRead(STR_PIN));
if (digitalRead(STR_PIN) == false)
{
while(digitalRead(STR_PIN) == false){}
delay(100);
change_level(1);
}
else if (digitalRead(STP_PIN) == false)
{
while(digitalRead(STP_PIN) == false){}
delay(100);
change_level(-1);
}
else if (digitalRead(INC_PIN) == false)
{
while(digitalRead(INC_PIN) == false){}
delay(100);
switch_mode(1);
}
else if (digitalRead(DEC_PIN) == false)
{
while(digitalRead(DEC_PIN) == false){}
delay(100);
switch_mode(-1);
}
}