I have a question; how would I loop a case until the case changes from a button press?
#include <LiquidCrystal.h>
#include <SimpleDHT.h>
int buttonValue;
int previous = HIGH;
int pin = 2;
int screenNumber = 0;
int pinDHT11 = 1;
SimpleDHT11 dht11;
int xValue, yValue;
#define joyX A1
#define joyY A2
// initialize the library by associating any needed LCD interface pin
// with the arduino pin number it is connected to
const int rs = 12, en = 8, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
const int trigPin = 7;
const int echoPin = 6;
long duration;
int distance;
void setup()
{
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output
pinMode(echoPin, INPUT); // Sets the echoPin as an Input
Serial.begin(9600);
pinMode(13, INPUT_PULLUP);
}
void loop()
{
buttonValue = digitalRead(13);
if (buttonValue == LOW && previous == HIGH) // Has a button just been pressed?
{
switch (screenNumber) // Select the screen to display.
{
case 0:
lcd.clear();
lcd.print("Joystick control"); // joystick and rgb led page
delay(250);
lcd.clear();
while(buttonValue = LOW);{
xValue = analogRead(joyX);//Reading X and Y values from joystick
yValue = analogRead(joyY);
lcd.setCursor(0,0);
lcd.print("X Value : ");
lcd.print(xValue);//Displaying xValue on top
lcd.setCursor(0,1);
lcd.print("Y Value : ");
lcd.print(yValue);//Displaying yValue on bottom
}
break;
case 1:
lcd.clear();
lcd.print("Humidity/Temp"); // dht11 temp/humidity module page
while(buttonValue = LOW);{
Serial.println("=================================");
Serial.println("DHT11 readings...");
byte temperature = 0;
byte humidity = 0;
int err = SimpleDHTErrSuccess;
Serial.print("Readings: ");
Serial.print((int)temperature); Serial.print(" Celcius, ");
Serial.print((int)humidity); Serial.println(" %");
//Telling our lcd to refresh itself every 0.75 seconds
lcd.clear();
//Choosing the first line and row
lcd.setCursor(0,0);
//Typing Temp: to the first line starting from the first row
lcd.print("Temp: ");
//Typing the temperature readings after "Temp: "
lcd.print((int)temperature);
//Choosing the second line and first row
lcd.setCursor(0,1);
//Typing Humidity(%): to the second line starting from the first row
lcd.print("Humidity(%): ");
//Typing the humidity readings after "Humidity(%): "
lcd.print((int)humidity);
delay(750);
}
break;
case 2:
lcd.clear();
lcd.print("Light level"); // photoresistor page
delay(250);
lcd.clear();
while(buttonValue = LOW);{
int sensorValue = analogRead(A0);
double dV = sensorValue;
double le = (dV/1023)*100;
int level = le;
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("LIGHT LEVEL:");
lcd.print(level);
lcd.print("%");
lcd.setCursor(0, 1);
if ((level >= 0) && (level <= 5))
{
lcd.print("VERY DARK");
}
else if ((level > 5) && (level <= 10))
{
lcd.print("DARK");
}
else if ((level > 10) && (level <= 50))
{
lcd.print("BRIGHT");
}
else
{
lcd.print("VERY BRIGHT");
}
delay(500);
}
break;
case 3:
lcd.clear();
lcd.print("Distance"); // ultrasonic sensor page
delay(250);
lcd.clear(); // Clears the screen in preparation of new measurement
while(buttonValue = LOW);{
// Clears the trigPin
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
// Sets the trigPin on HIGH state for 10 micro seconds
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
// Reads the echoPin, returns the sound wave travel time in microseconds
duration = pulseIn(echoPin, HIGH);
// Calculating the distance
distance = duration * 0.034 / 2;
// Prints the distance on the Serial Monitor
lcd.print("Distance: ");
lcd.print(distance);
lcd.print(" cm");
}
break;
case 4:
lcd.clear();
lcd.print("IR control"); // infrared controller page
delay(250);
lcd.clear();
while(buttonValue = LOW);{
}
break;
}
screenNumber = (screenNumber + 1 ) % 5; // Calculate the next screen number
}
previous = buttonValue;
}