#define TONE_USE_INT
#define TONE_PITCH 440
#include <TonePitch.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <Keypad.h>
#include <EEPROM.h>
#include "config.h"
#include "stepperfunc.h"
#include "calcfunc.h"
#include "lcdfunc.h"
void(* resetFunc) (void) = 0; //declare reset function at address 0 - MUST BE ABOVE LOOP
void setup() {
Serial.begin(BAUD);
lcd.init(); // initialize the lcd
pinMode(M1_STEP, OUTPUT);
pinMode(M1_DIR, OUTPUT);
pinMode(M2_STEP, OUTPUT);
pinMode(M2_DIR, OUTPUT);
pinMode(SPEAKER_PIN, OUTPUT);
pinMode(btnSwitch, INPUT);
pinMode(MoveSpeed, INPUT);
playLevelUpSound();
MotorMoveSpeed = analogRead(MoveSpeed);
MotorMoveSpeed = map(MotorMoveSpeed, 0, 255, 1000, 25000);
intro();
back:
String prompt = "Holes Count";
num = getnumber(prompt, 0, 0);
if (num == 0) {
goto back;
}
TotalDegrees = 360 / num ;
}
void loop() {
//'if ( millis() >= 604800000 ) resetFunc(); //call reset every 7 days (1 Week).
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(">Total : ");
lcd.print(Degrees);
lcd.print((char)223);
lcd.setCursor(0, 1);
lcd.print(">Holes = ");
lcd.print(num);
lcd.setCursor(0, 2);
lcd.print(">Deg = ");
lcd.print(TotalDegrees, 1);
lcd.print((char)223);
lcd.setCursor(0, 3);
lcd.print("Enter To Start...");
key = kpd.getKey();
while (key != 'C') // C will return to start menu
{
//if ( millis() >= 60000 ) resetFunc(); //call reset every 60 seconds (1 Minute).
key = kpd.getKey();
if (key) {
beep();
}
if (key == '#') {
}
if (btnVal == 1) flag = 0;
if (key == 'A' || btnVal == 0 && flag == 0) // MOVE FORWARD
{
flag = 1;
}
if (key == 'D') {
unsigned long currentMillis = millis();
Degrees = Degrees + TotalDegrees;
if (Degrees > 360.0) // When making a full rotation, restart count at 360 degrees
{
Degrees = Degrees - 360.0;
}
for (int c = 0; c < num; c++)
{
key = kpd.getKey();
if (key == 'C') {
break;
}
lcd.setCursor(0, 0);
lcd.print("Total : ");
lcd.print(Degrees);
lcd.print((char)223);
lcd.setCursor(0, 3);
lcd.print("Move Z Axis ");
MoveZaxis();
lcd.setCursor(0, 3);
lcd.print("Move ");
lcd.print(TotalDegrees, 1);
lcd.print(" Deg.");
totalStepsToMove = ( OneDeg / 360 ) * num;
Serial.print(totalStepsToMove,4);
Serial.println("");
MoveToDegree(totalStepsToMove);
}
//lcd.setCursor(0, 3);
//lcd.print("Job Done...!");
beepFinal();
checkTime(currentMillis);
}
}
/*
Rounds = 0;
lcd.init();
setup();
*/
resetFunc();
}
void software_Reset() // Restarts program from beginning but does not reset the peripherals and registers
{
asm volatile (" jmp 0");
}
void blink() {
if ( (millis() - lastDebounceTime) >= debounceDelay) {
lastDebounceTime = millis(); //set the current time
if (ledstate == 0) {
//Serial.println("Off");
//lcd.setCursor(2, 2);
lcd.print(" ");
ledstate = 1;
} else {
//Serial.println("On");
//lcd.setCursor(2, 2);
lcd.print("-");
ledstate = 0;
}
}
}