Hii,
I am having a PID Project in which i want to give the setpoint from keypad . I am using 4 push buttons .
Values are getting scrolled. But the " key " variable is not getting the edited value.
fresh_display1.ino (4.77 KB)
Hii,
I am having a PID Project in which i want to give the setpoint from keypad . I am using 4 push buttons .
Values are getting scrolled. But the " key " variable is not getting the edited value.
fresh_display1.ino (4.77 KB)
Pl guide and help ... my situation has became very critical as I am trying for the same from last 2 weeks.
Hello Friends. I am having a PID Project with LCD (I TO C Type). In it I want to implement Keys (push buttons ) to give the set point .
Pl guide me to how to add keys .
Key 1 shall be set
Key 2 shall be up scrolling of digits.
Key 3 shall be down scrolling of the digits.
I have checked your Arduino code and there you have initialized key as double, but in the code you are using this:
key=(parameters);
why the parenthesis ??? while the parameters in initialized as:
int parameters[numOfScreens];
So your code must be something like this:
key=parameters[0];
Now it depends on your requirements, which parameter value you wanna save in key.
Hello,"
1.Pl see my attached revised program. I made change" key=parameters[0];"I want to edit key parameter . ITS Editing on screen but is it actually editing in program i am nt able to verify. As serial.print is not working.
2.Also , i want to use A3 pin for Analog Input . Or A0/A1/A2.
But when we assign "sensorValue=analogInPin " , the buttons stop working.They dont scroll or work.
Hello,"
1.Pl see my attached revised program. I made change" key=parameters[0];"I want to edit key parameter . ITS Editing on screen but is it actually editing in program i am nt able to verify. As serial.print is not working.
2.Also , i want to use A3 pin for Analog Input . Or A0/A1/A2.
But when we assign "sensorValue=analogInPin " , the buttons stop working.They dont scroll or work.
#include <LiquidCrystal.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,20,4);
#include <PID_v1.h>
//Input & Button Logic
const int numOfInputs = 4;
const int inputPins[numOfInputs] = {8,9,10,11};
int inputState[numOfInputs];
int lastInputState[numOfInputs] = {LOW,LOW,LOW,LOW};
bool inputFlags[numOfInputs] = {LOW,LOW,LOW,LOW};
long lastDebounceTime[numOfInputs] = {0,0,0,0};
long debounceDelay = 5;
//LCD Menu Logic
const int numOfScreens = 2;
int currentScreen = 0;
String screens[numOfScreens][2] = {{"pmfs","Ar"}, {"Set point", "key"}};
int parameters[numOfScreens];
//pid//Define Variables we'll be connecting to
double key;
double Input;
double Output;
const int analogInPin = A3;
int sensorValue = 0;
double Kp=0, Ki=1, Kd=0;
PID myPID(&Input, &Output, &key, Kp, Ki, Kd, DIRECT);
float s ;
float m ;
float x;
float k;
float aI =1.20; float aO=0;
float bI =1.40; float bO=100;
float cI = 1.80; float cO=120;
float dI =3.62; float dO=150;
float eI =3.64; float eO=175;
float fI = 3.70; float fO=245;
float gI =3.79; float gO=280;
float hI = 3.88; float hO=385;
float iI = 3.90; float iO=455;
float jI = 3.95; float jO=500;
void setup() {
for(int i = 0; i < numOfInputs; i++) {
pinMode(inputPins*, INPUT);*
_ digitalWrite(inputPins*, HIGH);*_
* // pull-up 20k*
myPID.SetMode(AUTOMATIC);
myPID.SetTunings (Kp, Ki, Kd);
s = (5./1023.)*sensorValue;
}
key=parameters[0];
Serial.begin(9600);
lcd.init(); // initialize the lcd
lcd.init();
lcd.begin(16,2);
// Print a message to the LCD.
lcd.backlight();
}
void loop() {
setInputFlags();
resolveInputFlags();
}
void setInputFlags() {
for(int i = 0; i < numOfInputs; i++) {
_ int reading = digitalRead(inputPins*);
if (reading != lastInputState) {
lastDebounceTime = millis();
}
if ((millis() - lastDebounceTime) > debounceDelay) {
if (reading != inputState) {
inputState = reading;
if (inputState == HIGH) {
inputFlags = HIGH;
}
}
}
lastInputState = reading;
}
}
void resolveInputFlags() {
for(int i = 0; i < numOfInputs; i++) {
if(inputFlags == HIGH) {
inputAction(i);
inputFlags = LOW;
printScreen();
}
}
}
void inputAction(int input) {
if(input == 0) {
if (currentScreen == 0) {
currentScreen = numOfScreens-1;
}else{
currentScreen--;
}
}else if(input == 1) {
if (currentScreen == numOfScreens-1) {
currentScreen = 0;
}else{
currentScreen++;
}
}else if(input == 2) {
parameterChange(0);
}else if(input == 3) {
parameterChange(1);
}
}
void parameterChange(int key) {
if(key == 0) {
parameters[currentScreen]++;
}else if(key == 1) {
parameters[currentScreen]--;
}
}
void printScreen() {
lcd.clear();
lcd.print(screens[currentScreen][0]);
lcd.setCursor(0,1);
lcd.print(parameters[currentScreen]);
lcd.print(" ");
lcd.print(screens[currentScreen][1]);
s = (5./1023.)*sensorValue;
Serial.println("sensor voltage");
Serial.println ( s);
if (s>=aI && s<=bI)
{
m= aO+(bO-aO)(s-aI)/(bI-aI);
k= (51) m;
Serial.println (m);
analogWrite (3,k);
}
else if (s>=bI && s<=cI)
{
m= bO+(cO-bO)(s-bI)/(cI-bI);
k= (51) m;
Serial.println (m);
analogWrite (3,k);
}
else if (s>=cI && s<=dI)
{
m= cO+(dO-cO)(s-cI)/(dI-cI);
k= (51) m;
Serial.println (m);
analogWrite (3,k);
}
else if (s>=dI && s<=eI)
{
m= dO+(eO-dO)(s-dI)/(eI-dI);
k= (51) m;
Serial.println (m);
analogWrite (3,k);
}
else if (s>=eI && s<=fI)
{
m= eO+(fO-eO)(s-eI)/(fI-eI);
k= (51) m;
Serial.println (m);
analogWrite (3,k);
}
else if (s>=fI && s<=gI)
{
m= fO+(gO-fO)(s-fI)/(gI-fI);
* Serial.println (m);
k= (51) m;
analogWrite (3,k);
* }
else if (s>=gI && s<=hI)
{
m= gO+(hO-gO)(s-gI)/(hI-gI);
k= (51) m;
Serial.println (m);
analogWrite (3,k);
}
else if (s>=hI && s<=iI)
{
m= hO+(iO-hO)(s-hI)/(iI-hI);
* Serial.println (m);
k= (51) m;
analogWrite (3,k);
* }
else if (s>=iI && s<=jI)
{
m= iO+(jO-iO)(s-iI)/(jI-iI);
* Serial.println (m);
k= (51) m;
analogWrite (3,k);
* Input = map ( m,0,255,0,255);
myPID.Compute();
analogWrite(5, Output);
Serial.begin(9600);
Serial.println(s);
Serial.println(Output);
Serial.println(key);
delay(1000);*_
} }