hello everyone, this is my code. there is lots wrong with it. professor is no help. any help is appropriated.
#include <Wire.h>
#include <LiquidCrystal_PCF8574.h>
LiquidCrystal_PCF8574 lcd(0x27);
const int CLK_NUM = 2;
const int DT_NUM = 3;
const int SW_NUM = 4;
const int DC_MOTOR_1ST = 5;
const int DC_MOTOR_2ND = 6;
const int FAN_CONTROL = 7;
const int AUTO_LED = 8;
const int COOLING_LED = 9;
const int HEATING_LED = 10;
const int intTHERMISTOR = A0;
int rotaryEncoderPos = 0;
int currenEncoderVal = 0;
int lastEncoderVal = 0;
int desiredTemp = 70;
int dispTemp = 70;
int currentTemp;
int climateContorlAdj = 0;
int hiMode = 0;
int lowMode = 0;
int tempTooCold = 0;
int tempTooHot = 0;
long nextTemp;
long currentTime;
//Read analog pin number connected to the thermistor pin and save the value
//read from the pin to the local variable that stores the value read from the thermistor pin.
int thermistorPinVal; //thermistorPinVal = analogRead(THERMISTOR); function measureTempfun()
//int motorPin = 0;
void setup()
{
Serial.begin(9600);
showTempinLCD (); // Call the user-defined Show Temperature on LCD function to display the temperature on LCD.
Serial.println (" Show Temp on LCD");
showTempinLCD();
// till here
pinMode(FAN_CONTROL, INPUT);
digitalWrite(FAN_CONTROL, HIGH);
pinMode(AUTO_LED, OUTPUT);
pinMode(COOLING_LED, OUTPUT);
pinMode(HEATING_LED, OUTPUT);
pinMode(DC_MOTOR_1ST,OUTPUT);
pinMode(DC_MOTOR_2ND,OUTPUT);
pinMode(CLK_NUM,INPUT_PULLUP);
pinMode(DT_NUM, INPUT_PULLUP);
pinMode(SW_NUM,INPUT_PULLUP);
attachInterrupt(0,CHANGE); // digitalPinToInterrupt(pin) why not this ln ?(0,CHANGE)
int errorFindingLCD; // LCD ERROR Val
Wire.begin();
Wire.beginTransmission(0x27); //0x27 I2C positive A0=1 A1=1 A2=1
Wire.endTransmission(errorFindingLCD);
Serial.print(9600);
Serial.println("errorFindingLCD");
lcd.begin(16x2);
lcd.clear();
//digitalWrite(currentTemp, HIGH);
measureTempfun(); // Measure Temperature function to measure the current temperature.
//millis();
//waitting 6 seccons or 60000 mili secs
nextTemp = millis(nextTemp);
delay(60000);
//Read from digital pin number connected to the fan control button pin and
//save the value in the local variable that stores the fan control button
//value.
//digitalWrite(FAN_CONTROL, HIGH);
}
void loop()
{
int rotaryEncoderSw;
int fanContButt;
rotaryEncoderSw = digitalRead(SW_NUM);
if (rotaryEncoderSw = 0)
{
climateContorlAdj =1;
desiredTemp = dispTemp;
lcd.setBacklight(255);
lcd.display();
digitalWrite(AUTO_LED, HIGH);
showTempinLCD ();
delay(300);
}
//If the climate control adjustment mode variable value is equal to 1 AND the current rotary encoder value is greater than the last rotary encoder value
if (climateContorlAdj = 1 && currenEncoderVal > lastEncoderVal)
{
Serial.println("CW");
}
if (dispTemp < 84)
{
dispTemp++;
hiMode = 0;
lowMode = 0;
showTempinLCD();
}
else{
dispTemp == 85;
hiMode == 1;
showHIonLCD();
}
else if (climateContorlAdj = 1 && currenEncoderVal < lastEncoderVal ) {
Serial.println("CCW");
}
if (dispTemp > 61){
dispTemp--;
hiMode = 0;
lowMode = 0;
// showTempinLCD();
}
else {
dispTemp = 59;
lowMode = 1;
showLowOnLCD();
}
//Set the last rotary encoder value to the current rotary encoder value.
currenEncoderVal(lastEncoderVal);
int fanControlbutton; //local variable that stores the fan control button value.
fanControlbutton=digitalRead(FAN_CONTROL);
Serial.print ("fan contorl is ="); // not neccessary
Serial.println(fanControlbutton);
if (FAN_CONTROL = 0)
{
climateContorlAdj = 0;
dispTemp = desiredTemp;
lcd.setBacklight(0);
lcd.noDisplay();
digitalWrite(AUTO_LED, LOW);
delay(300);
}
if(currentTemp < desiredTemp-3){
tempTooCold = 1;
}
else if currentTemp > desiredTemp +3){
tempTooHot =1;
}
else {
tempTooCold==0;
tempTooHot==0;
}
if (hiMode = =1 ||tempTooCold == 1){
turnOnHeatFun(); //Turn on heat function
}
else if( lowMode ==1 || tempTooHot ==1;) {
turnOnAirConfun(); //Turn on air condition function.
}
else {
turnOffHeatACfun(); //Turn off heat and air condition function.
}
millis(currentTime);
if (currentTime > nextTemp;) {
measureTempfun();
nextTemp = currentTemp+60000;
}
} //end of loop
// user-defined function never is called.
void doNothingFun()
{
int rotaryEncoderCLK;
int rotaryEncoderDT;
rotaryEncoderCLK = digitalRead (rotaryEncoderCLK);
rotaryEncoderDT = digitalRead (rotaryEncoderDT);
if (rotaryEncoderCLK == rotaryEncoderDT)
{
rotaryEncoderPos++;
}
else {
rotaryEncoderPos --;
}
currenEncoderVal = rotaryEncoderPos/3;
}
//these are here just in case i dont lose them.
void showTempinLCD () // user deined function to show temp on lcd
{
Serial.println (dispTemp);
LiquidCrystal_PCF8574.clear();
LiquidCrystal_PCF8574.setCursor(0x0);
LiquidCrystal_PCF8574.print(dispTemp);
LiquidCrystal_PCF8574.setCursor(3x0);
LiquidCrystal_PCF8574.print(F);
}
void showHIonLCD (){
Serial.println();
LiquidCrystal_PCF8574.clear();
LiquidCrystal_PCF8574.setCursor(0x0);
LiquidCrystal_PCF8574.print("HI");
}
void showLowOnLCD(){
Serial.println();
LiquidCrystal_PCF8574.clear();
LiquidCrystal_PCF8574.setCursor(0x0);
LiquidCrystal_PCF8574.print("LO");
}
void turnOnHeatFun () //user defined function to to turn on the red LED and rotate CW
{
Serial.println (HEATING_LED);
digitalWrite(COOLING_LED, LOW);
digitalWrite(HEATING_LED, HIGH);
}
void turnOnAirConfun(){
Serial.println (COOLING_LED);
//Write analog value 0 to the pin number connected to the DC motor first pin.
//Write analog value 250 to the pin number connected to the DC motor second pin.
Stepper DC_MOTOR_1ST(0);
Stepper DC_MOTOR_2ND ( 250);
}
void turnOffHeatACfun(){
serial.println(FAN_CONTROL);
digitalWrite(COOLING_LED, LOW);
digitalWrite(HEATING_LED, LOW);
//Write analog value 0 to the pin number connected to the DC motor first pin.
//Write analog value 0 to the pin number connected to the DC motor second pin.
pinMode(DC_MOTOR_1ST, OUTPUT);
pinMode(DC_MOTOR_2ND, OUTPUT);
}
void measureTempfun() {
Serial.println (currentTemp);
int thermistorPinVal;
float resisterVal = 10000;
float convertedResisterVal;
float resisterValLogPresentation;
float absTemp;
float tempInCels;
float tempInFahr;
float firstConstVal = 2.378405444e-4;
float seccondConstval = 2.378405444e-4;
float thirdContVal = 2.019202697e-7 ;
LiquidCrystal_PCF8574.setBacklight(0);
LiquidCrystal_PCF8574.noDisplay();
digitalWrite(AUTO_LED, LOW);
turnOffHeatACfun();
delay(50);
thermistorPinVal = analogRead(THERMISTOR);
convertedResisterVal = ((resisterVal * 1023 )/ thermistorPinVal) -1.0;
//skipped--->Call the log function, provide the converted resister value as the function input,
//and save the result in the resister value in log presentation variable
absTemp = 1 / firstConstVal + seccondConstval * resisterValLogPresentation +thirdContVal *resisterValLogPresentation *resisterValLogPresentation;
tempInCels = absTemp - 273.15;
tempInFahr = tempInCels * 9 /(5+32);
currentTemp = -tempInFahr;
Serial.print(currentTemp);
Serial.println(currentTemp);
if (climateContorlAdj = 1;) {
LiquidCrystal_PCF8574.setBacklight(255);
LiquidCrystal_PCF8574.display();
digitalWrite(AUTO_LED, HIGH);
}
if (hiMode = 1 || tempTooCold =1; ) {
//Call the user-defined Turn on heat function to turn on the red LED and
//rotate fan clockwise.
turnOffHeatACfun();
}
//Call the user-defined Turn on air condition function to turn on the
//blue LED and rotate fan counterclockwise
else if (lowMode = 1 ||tempTooHot =1 ) {
}
}