0% found this document useful (0 votes)
23 views4 pages

KEYPAD Problems

arduibo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views4 pages

KEYPAD Problems

arduibo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 4

//didn't copy the stepper library but I am using AccelStepper Library

#include <Keypad.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>

//LCD
LiquidCrystal_I2C lcd = LiquidCrystal_I2C(0x3F, 16, 2);

//keypad
const byte ROWS = 4; //four rows
const byte COLS = 4; //four columns
char keys[ROWS][COLS] = {
{'1', '2', '3', 'A'},
{'4', '5', '6', 'B'},
{'7', '8', '9', 'C'},
{'*', '0', '#', 'D'}
};

byte rowPins[ROWS] = {32, 30, 28, 26}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {40, 38, 36, 34}; //connect to the column pinouts of the
keypad

Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

void setup() {
lcd.init();
lcd.backlight();
Serial.begin(9600);
}

void loop() {
char key;
startup();

do {
key = keypad.getKey();
} while (key == NO_KEY);
if (key == 'A') {
delay(500);
Manual();
}
if (key == 'B') {
delay(500);
Automatic();
}
}

void startup()

{
char key;
lcd.setCursor(0, 0);
lcd.print ("Manual = A");
lcd.setCursor(0, 1);
lcd.print ("Auto = B");
delay(100);
}

void Manual()
{
//bunch of codes for Manual function of the program calibration and etc
}

void Automatic()
{

//bunch of codes getting user torque and load torque


program();
}

void program()
{

while (UserTorque < LoadTorque)


{
if (percentage == 0)
break;
Serial.println (location);
lcd.clear();
stepper.setCurrentPosition(0);
while (stepper.currentPosition() != 259)
{
lcd.setCursor(0, 0);
lcd.print("Closing Valve");
stepper.setSpeed(300);
stepper.runSpeed();
}
location = (location) - 259;
percentage = (float)location / 4144 * 100;
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Percentage:");
lcd.setCursor(0, 1);
lcd.print (percentage);
RPM();
LoadSensor();
delay(1000);
control();
}
while (UserTorque > LoadTorque)
{
if (percentage == 100)
break;
lcd.clear();
stepper.setCurrentPosition(0);
while (stepper.currentPosition() != -259)
{
lcd.setCursor(0, 0);
lcd.print("Open Valve");
stepper.setSpeed(-300);
stepper.runSpeed();
}
location = (location) + 259;
percentage = (float)location / 4144 * 100;
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Percentage:");
lcd.setCursor(0, 1);
lcd.print (percentage);
RPM();
LoadSensor();
delay(1000);
control();
}

void control()
{
lcd.clear();
lcd.print ("# to stop");
char key;
do {
key = keypad.getKey();
} while (key == NO_KEY);

delay(2000);

if (key == '#')
Reset();

if (key == NO_KEY)
program();
}

void Reset()
{
while (percentage != 0)
{
Serial.println (location);
lcd.clear();
stepper.setCurrentPosition(0);
while (stepper.currentPosition() != 259)
{
lcd.setCursor(0, 0);
lcd.print("Closing Valve");
stepper.setSpeed(50);
stepper.runSpeed();
}
location = (location) - 259;
percentage = (float)location / 4144 * 100;
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Percentage:");
lcd.setCursor(0, 1);
lcd.print (percentage);
delay(1000);
RPM();
LoadSensor();

if (percentage == 0)
break;
}

return 0;

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy