I do not get any compiler error. This is the program that doesn’t work the way I want it to work.
The whole thing is quite long (more than the 9000 characters limit), but here you have it. I tried to structure it the way I could, but this is my first “real scale” project… hope you understand without too much troubles.
The issue occurs in the function menu_check(). What I want is:
(a) If the Serial.read() function gives a value to recData that is anything different of 1, 2 and 3, the menu displayed on the LCD screen goes to the next data display. (There are 3 different printing functions that are what I call the different “printing/data displays”).
(b) However, if the value of recData is 1, 2 or 3, then the menu should go to the corresponding data display.
But, what’s happening currently is that the menu goes to the next data display each time (case (a)) and doesn’t care about the lines
if((recData == 1) || (recData == 2) || (recData == 3)){
if(recData==menu){Serial.println("recData = 1 || =2 || =3\nrecData == menu --> return 1"); return 1;}
else {menu = recData; Serial.println("recData = 1||2||3\nrecData != menu --> return 0"); return 0;};
}
Here is the first half
/****************************************************************/
/************/ /// SETUP LCD DISPLAY /// /************/
/****************************************************************/
#include <LiquidCrystal.h>
const int rs = 2, en = 3, d4 = 4, d5 = 5, d6 = 6, d7 = 7;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
/****************************************************************/
/************/ /// PRINTING FUNCTIONS /// /************/
/****************************************************************/
void print_scrolling_line(int*,char*);
void print_inside_ambiance();
void print_outside_ambiance();
void print_anemometer_sensor();
/****************************************************************/
/************/ /// SETUP ANEMOMETER /// /************/
/****************************************************************/
int windSensor = A5; // Defines the pin that the anemometer output is connected
/// Anemometer Technical Variables ///
float voltageMin = .4; // Mininum output voltage from anemometer in mV
float windSpeedMin = 0; // Wind speed in meters/sec corresponding to minimum voltage
float voltageMax = 2.0; // Maximum output voltage from anemometer in mV
float windSpeedMax = 32; // Wind speed in meters/sec corresponding to maximum voltage
/// Calculation variables ///
int sensorDelay = 1000; // Measures every 1000 ms
int readingIndex = 1;
float totalWind = 0; // Used to calculate averageWindSpeed
/// Anemometer Function ///
void anemometer_sensor(float*, float*, float*);
/****************************************************************/
/************/ /// SETUP T° SENSORS /// /************/
/****************************************************************/
int tempSensorIn = A3; // Set sensorPin to A1
int tempSensorOut = A1; // Set sensorPin to A2
void temperature_sensor_in(float*);
void temperature_sensor_out(float*);
/****************************************************************/
/************/ /// SETUP LIGHT SENSORS /// /************/
/****************************************************************/
int lightSensorIn = A4; // Set sensorPin to A
int lightSensorOut = A0; // Set sensorPin to A0
char lightLvlTxt[5][12] = {"Dark","Dim","Light","Bright","Very bright"};
void light_sensor_in(int*);
void light_sensor_out(int*);
/****************************************************************/
/*************/ /// OTHER SETUPS /// /*************/
/****************************************************************/
/******************/ // MENU // /*******************/
int menu = 1;
const int menu_button = 12;
char recData;
boolean newData = false;
/*****************/ // AWNING // /******************/
const int led = 13;
/****************************************************************/
/*************/ /// VOID SETUP /// /*************/
/****************************************************************/
void setup() {
pinMode (menu_button, INPUT);
pinMode (led, OUTPUT);
Serial.begin(9600); // Start the serial connection
char startMessage1[]="Loading ...";
char startMessage2[]="Project started!";
lcd.begin(16,2);lcd.clear();lcd.cursor();
for(int i=0 ; i<11 ; i++){
lcd.setCursor(i+1,0);
lcd.print(startMessage1[i]);
delay(120);
}
delay(500);lcd.clear();delay(400);
for(int i=0 ; i<16 ; i++){
lcd.setCursor(i,0);
lcd.print(startMessage2[i]);
delay(80);
}
lcd.noCursor();delay(800);lcd.clear();
Serial.println("\t<< Menu: Send any value in the serial port or press the button to switch to the next data display, or send a number from 1 to 3 to switch to a specific data display: >>\n\t_________________________________________________________________________________________________________________________\n\n\t\t1. Inside ambiance\n\t\t2. Outside ambiance\n\t\t3. Anemometer sensor");
delay(500);
}
/****************************************************************/
/************/ /// MAIN LOOP /// /************/
/****************************************************************/
void loop() {
float wSpeed,mWind,aWind;
anemometer_sensor(&wSpeed,&mWind,&aWind);
float temperatureIn, temperatureOut;
temperature_sensor_in(&temperatureIn);
temperature_sensor_in(&temperatureOut);
int nbrLightLvlIn, nbrLightLvlOut;
light_sensor_in(&nbrLightLvlIn);
light_sensor_out(&nbrLightLvlOut);
if(mWind < 30 && nbrLightLvlIn >= 3 && nbrLightLvlOut == 4 && temperatureIn > 20 && temperatureOut > 20)digitalWrite(led, HIGH);
else digitalWrite(led, LOW);
if(menu==1){
print_inside_ambiance();
}
else if(menu==2){
print_outside_ambiance();
}
else if(menu==3){
print_anemometer_sensor();
}
}
/****************************************************************/
/************/ /// PRINTING FUNCTIONS /// /************/
/****************************************************************/
/**********/ // PRINTING INSIDE AMBIANCE // /**********/
void print_inside_ambiance(){
char lighLvlIn[12], tmpStr1[7], tmpBright[13] = "Brightness: ", tmpTemp[17] = " - Temperature:";
char in2P[50] = "";
float temperatureIn;
temperature_sensor_in(&temperatureIn);
dtostrf(temperatureIn,6,1,tmpStr1);
int nbrLightLvlIn;
light_sensor_in(&nbrLightLvlIn);
strcpy(lighLvlIn,lightLvlTxt[nbrLightLvlIn]);
strcpy(in2P,tmpBright);
strcpy(&in2P[strlen(in2P)],lighLvlIn);
strcpy(&in2P[strlen(in2P)],tmpTemp);
strcpy(&in2P[strlen(in2P)],tmpStr1);
char titleI[17] = {"Inside ambiance "};
for(int i=0 ; i<16 ; i++)
{
lcd.setCursor(i,0);
lcd.print(titleI[i]);
delay(80);
}
delay(500);
for(int index2P = 0; index2P <= strlen(in2P) - 16; index2P++) //From 0 to upto n-16 characters supply to below function
{
if(menu_check()==0)break;
print_scrolling_line(index2P, in2P);
if(index2P==0)delay(1000); // freezes the printing at the begining and the end of the array.
}delay(1000);lcd.setCursor(0,1);lcd.print(" ");delay(300);
}
/**********/ // PRINTING OUTSIDE AMBIANCE // /**********/
void print_outside_ambiance(){
char lighLvlOut[12],tmpStr1[7], tmpBright[13] = "Brightness: ", tmpTemp[17] = " - Temperature:";
char out2P[50] = "";
float temperatureOut;
temperature_sensor_out(&temperatureOut);
dtostrf(temperatureOut,6,1,tmpStr1);
int nbrLightLvlOut;
light_sensor_out(&nbrLightLvlOut);
strcpy(lighLvlOut,lightLvlTxt[nbrLightLvlOut]);
strcpy(out2P,tmpBright);
strcpy(&out2P[strlen(out2P)],lighLvlOut);
strcpy(&out2P[strlen(out2P)],tmpTemp);
strcpy(&out2P[strlen(out2P)],tmpStr1);
char titleO[17] = {"Outside ambiance"};
for(int i=0 ; i<16 ; i++)
{
lcd.setCursor(i,0);
lcd.print(titleO[i]);
delay(80);
}
delay(500);
for(int index2P = 0; index2P <= strlen(out2P) - 16; index2P++) {
if(menu_check()==0)break;
print_scrolling_line(index2P, out2P);
if(index2P==0)delay(1000);
}
delay(1000);lcd.setCursor(0,1);lcd.print(" ");delay(300);
}