#include <LiquidCrystal_I2C.h>
#include <Wire.h>
#include <Servo.h>
#include <PID_v1.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
Servo servo;
//Celc to Fahr: (Celcius x 1.8) + 32 = fahrenheit
int old = 0;
int New = 0;
int reading = (analogRead(A0)); // door position pot
int setTemp = (analogRead(A1));// temp position pot
int tempOld = 0;
int tempNew = 0;
void setup() {
Serial.begin(9600);
lcd.init();
lcd.backlight();
lcd.clear();
pinMode(A0, INPUT);
pinMode(A1, INPUT);
servo.attach(3);
}
void loop() {
old = reading;
tempOld = setTemp;
const float BETA = 3950; // should match the Beta Coefficient of the thermistor
int analogValue = analogRead(A3);
float celsius = 1 / (log(1 / (1023. / analogValue - 1)) / BETA + 1.0 / 298.15) - 273.15;
float fahr = (celsius * 1.8) + 32;
// reads servo pot
reading = analogRead(A0);
setTemp = analogRead(A1);
int mappedValue = map(reading, 0, 1023, 160, 320);
int servoPos = map(mappedValue, 160,320, 0, 180);
int temp = map(setTemp, 0, 1023, 160, 320);
// strings to print temp properly on screen
String testString = String(temp);
String feh = " F";
//lcd.setCursor(0, 9);
//lcd.print("CURRENT");
//lcd.setCursor(1, 10);
//lcd.print(fahr);
// compares if pot has been moved
if (old != reading)
{
switch (mappedValue) {
// 5 settings of 32
case 160 ... 192:
//lcd.clear();
lcd.setCursor(0,0);
lcd.print("FULL CURRENT:");
servo.write(servoPos);
break;
case 193 ... 224:
//lcd.clear();
lcd.setCursor(1,0);
lcd.print("3/4 OPEN ");
servo.write(servoPos);
break;
case 225 ... 256:
//lcd.clear();
lcd.setCursor(1,0);
lcd.print("HALF OPEN ");
servo.write(servoPos);
break;
case 257 ... 288:
//lcd.clear();
lcd.setCursor(1,0);
lcd.print("1/4 OPEN ");
servo.write(servoPos);
break;
case 289 ... 320:
//lcd.clear();
lcd.setCursor(1,0);
lcd.print("CLOSED ");
servo.write(servoPos);
break;
}
}
// checks if temp pot has been moved
/*if (tempOld != setTemp) {
lcd.setCursor(1, 1);
lcd.print(testString + feh); } */
}