#include <SPI.h>
#include <SD.h>
File root;
#include <Keypad.h>
const uint8_t ROWS = 4;
const uint8_t COLS = 4;
char keys[ROWS][COLS] = {
{ '1', '2', '3', 'A' },
{ '4', '5', '6', 'B' },
{ '7', '8', '9', 'C' },
{ '*', '0', '#', 'D' }
};
// Pins connected to LED1, LED2, LED3, ...LED12
uint8_t rowPins[ROWS] = { 26, 22, 21, 20 }; // Pins connected to R1, R2, R3, R4
uint8_t colPins[COLS] = { 9, 8, 7, 6 }; // Pins connected to C1, C2, C3, C4
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
#include <AccelStepper.h>
// Pin de commande du moteur pas à pas (broche STEP)
const int stepPin =2; // Connecté à la broche STEP du moteur
const int dirPin = 3; // Connecté à la broche STEP du moteur
// Pin du capteur d'eau connecté au Raspberry Pi Pico
// Crée une instance de la classe AccelStepper
AccelStepper stepper(AccelStepper::DRIVER, stepPin,dirPin); // type de pilote = 1 (driver A4988, DRV8825, etc.)
bool hesapmakinasidurum=true;
String input = "";
float result = 0;
bool calculated = false;
float operandsStack[50];
char operatorsStack[50];
int operandIndex = 0;
int operatorIndex = 0;
bool clearScreen = true;
char key = ' '; // Tuş okuma için geçici değişken
long initial_homing = -1;
// Variables to hold values
float DEGER_ORANTI = 20.00;
int homingPosizyon = 10;
float maxSpeed = 1000.0;
float acceleration = 600.0;
int siperBaslangic = 1;
int siperBitis = 1200;
int hafizaButton1 = 340;
int hafizaButton2 = 40;
int hafizaButton3 = 500;
//int hafizaButton4 = 120;
// EEPROM addresses
const int addrMaxSpeed = 0;
const int addrAcceleration = 4;
const int addrDEGER_ORANTI = 8;
const int addrHomingPosizyon = 12;
const int addrsiperBaslangic = 16;
const int addrsiperBitis = 20;
const int addrhafizaButton0 = 24;
const int addrhafizaButton1 = 28;
const int addrhafizaButton2 = 32;
const int addrhafizaButton3 = 36;
unsigned long lastKeyPressTime = 0;
int currentPos;
int menuIndex = -1; // Variable to keep track of the menu state
int stepPosition = 0; // Target position for the stepper motor
String inputString = ""; // String to hold the input from the keypad
unsigned long previousMillis = 0; // Zamanı takip etmek için değişken
const long interval = 900000; // 30 dakika (milisaniye cinsinden)
void setup() {
Acilis(); // varsayılan kurulum fonksiyonu
stepper.setMaxSpeed(2500); // Maksimum hız
stepper.setAcceleration(2000); // Hızlanma değeri
}
void loop() {
// Add keypad reading
char key = keypad.getKey();
if (key) {
// lastKeyPressTime = millis(); // Update last interaction time
// Handle key press
if (isdigit(key) || key == '.') { // Added decimal point support
// Handle numeric input
inputString += key;
lcd.print(key);
}
else {
// Handle special keys (A-D, *, #)
switch(key) {
case 'A':
// Convert string to position and move stepper
if (inputString.length() > 0) {
long targetPosition = inputString.toInt(); // or toFloat() if needed
stepper.moveTo(targetPosition);
lcd.clear();
lcd.print("Moving to:");
lcd.setCursor(0, 1);
lcd.print(targetPosition);
inputString = ""; // Clear input after use
}
break;
case 'B':
// Stop motor immediately
stepper.stop();
stepper.setCurrentPosition(0); // Optional: reset position
lcd.clear();
lcd.print("Stopped");
inputString = "";
break;
case 'C':
// Example: Move to home position
inputString="";
lcd.clear();
lcd.print("Going home");
break;
case 'D':
// Example: Clear input
inputString = "";
lcd.clear();
break;
// ... other cases for *,#, etc.
}
}
}
stepper.run();
// Stepper control - move only if needed
// if (stepper.distanceToGo() != 0) {
// stepper.run();
// }
/*
// Add timeout functionality (return to home after inactivity)
if (millis() - lastKeyPressTime > interval) {
// Return to home position or safe state
stepper.moveTo(homingPosizyon);
lastKeyPressTime = millis(); // Reset timer
lcd.clear();
lcd.print("Timeout: Going home");
}
*/
}