1 button + LCD

hello, is it possible to create a scroll tru menu on a 4x20 LCD using 1 button?

something like this but then with a lcd: http://arduino.cc/en/tutorial/button

so lets say the arduino starts and i get my info from the lcd: Temp 1 Temp 2 Temp 3 Temp 4

and when i press the button that it will show another 4 rows with information/text

and if i press the button again it will go back to the temp 1 temp2 temp3 temp4

if someone could help me out that would be great!

this should get you started...

const int buttonPin = 3;
int lastButtonState; 
int state;
//
void setup() 
{
  Serial.begin(115200);
  pinMode(buttonPin, INPUT); 
}
//
void loop()
{
  int buttonState = digitalRead(buttonPin);
  if (buttonState == LOW)
  {
    if (lastButtonState == HIGH)
    {
      state++;
      if (state > 1)
      {
        state = 0;
      }
    }
  }
  lastButtonState = buttonState;
  if (state == 0)
  {
    // display your first page
    // lcd functions here
  }
  else if (state == 1)
  {
    // display your 2nd page
    // lcd functions here
  }
}

It should be possible. I can help a little.

If you know how to use an LCD, skip this paragraph: Find out if your LCD is controlled serially, or with multiple headers, as how it is controlled will play a huge roll in how you control the LCD. Adafruit and SparkFun both have good tutorials that will teach you how to control each type, and if you haven't bought your LCD yet, I would recommend some research before buying. Just punch in "LCD tutorial Adafruit" or "LCD tutorial SparkFun" into your favorite search engine, and you should find plenty of help.

After you get the LCD stuff figured out and working, coding the button input will be the hardest part. I would control it with a boolean value. While the variable is true, one part of your message will be displayed on the LCD, and while it is false, another message will be displayed. This will only work with two different messages, but it is the simplest thing I could come up with. Switching between true and false should be the hardest part.

I think I figured part of it out for you (Sorry, I'm bored), and although I have yet to test it, it should work. You use a while loop to 'hold' the code until the button is pressed and set the correct value to a Boolean, and then go on to the rest of your code when the button is released. It looks something like this: (Check out the debounce example too)

boolean scroll = true;

int buttonPin = 2 //button schematic should be the same as in the example

if(scroll =! false && digitalRead(buttonPin) == HIGH)   { //checks to see if the button is pressed and value of scroll
    while(digitalRead(buttonPin) == HIGH)   { //while loop holds the code in place until button is released
        scroll = false; //make scroll the opposite of what it was.
    }
}
if(scroll != true && digitalRead(buttonPin) == HIGH)    { //the same, except for opposite true/false
    while(digitalRead(buttonPin) == HIGH)   {
        scroll = true;
    }
}

EDIT: I went crazy, didn't I...

so lets say the arduino starts and i get my info from the lcd:

OK. How are you getting information FROM the LCD?

thing is i have build the arduino on my motorcycle.

it shows the time, coolant temp, oil temp, and oil pressure and the outside temprature , that takes up al the 4 lines on the lcd.

lets say i want to add more options then i would like to swich between those 4 lines and another 4 lines with a button.

maybe even use a 2x16 lcd to make the build smaller

my car does it the same way so thats why i'm asking here cause im not a C dev still learning.

this forum has helped me out many times. :)

so any help would be appreciated :)

i'm just playing around with the code right now everything is already hooked up

post what you have...

this is what i got…
but without the pressure sensor,still working on that

#include <Thermistor.h>
#include <OneWire.h>
Thermistor temp1(A0);
Thermistor temp2(A1);
int DS18S20_Pin = 7; //DS18S20 Signaal op digitale pin 7 door Danny
OneWire ds(DS18S20_Pin); // op digitale pin 7 danny
void setup() {
  Serial.begin(9600);
}

void loop() {
 float temperature = getTemp();
 Serial.print("Buitentempratuur: ");
 Serial.print(temperature);
 Serial.println("*C");

  
  Serial.print("Olie Tempratuur: ");
  Serial.print( temp1.getTemp());
  Serial.println("*C");

  Serial.print("Koelvloeistof Tempratuur: ");
  Serial.print( temp2.getTemp());
  Serial.println("*C");  

  delay(1000);
}
float getTemp(){
 //returns the temperature from one DS18S20 in DEG Celsius

 byte data[12];
 byte addr[8];

 if ( !ds.search(addr)) {
 //no more sensors on chain, reset search
 ds.reset_search();
 return -1000;
 }

 if ( OneWire::crc8( addr, 7) != addr[7]) {
 Serial.println("CRC Klopt niet");
 return -1000;
 }

 if ( addr[0] != 0x10 && addr[0] != 0x28) {
 Serial.print("Buiten tempratuur sensor niet gevonden");
 return -1000;
 }

 ds.reset();
 ds.select(addr);
 ds.write(0x44,1); // start conversion, with parasite power on at the end

 byte present = ds.reset();
 ds.select(addr);
 ds.write(0xBE); // Read Scratchpad


 for (int i = 0; i < 9; i++) { // we need 9 bytes
 data[i] = ds.read();
 }

 ds.reset_search();

 byte MSB = data[1];
 byte LSB = data[0];

 float tempRead = ((MSB << 8) | LSB); //using two's compliment
 float TemperatureSum = tempRead / 16;

 return TemperatureSum;

 }

float tempRead = ((MSB << 8) | LSB); //using two’s compliment

Maybe you need to left shift by a different smiley face.

PaulS:

float tempRead = ((MSB << 8) | LSB); //using two’s compliment

Maybe you need to left shift by a different smiley face.

that’s why we use code tags, and not quotes to post code.

if you can correct that, it would be easier for folks…

i’m sorry my bad…
will edit it when i get home

Danny632:
i’m sorry my bad…
will edit it when i get home

something like this Danny:

I cannot compile or test, but you can try it hooking up a pushbutton to digital pin3. No resistor needed, it is using the internal pull-up resistor.

let me know…

#include <Thermistor.h>
#include <OneWire.h>
#include <Wire.h> 
#include <LiquidCrystal_I2C.h>
#include "RTClib.h"

Thermistor temp1(A0);
Thermistor temp2(A1);

const int buttonPin = 3;//<<<<<<<<<<<<<<<<
int lastButtonState; 
int state;
unsigned long startTime;
int DS18S20_Pin = 7; //DS18S20 pin 7
OneWire ds(DS18S20_Pin); // pin 7 danny
LiquidCrystal_I2C lcd(0x27,20,4); 
RTC_DS1307 RTC;

void setup() 
{
  pinMode(buttonPin, INPUT_PULLUP);
  lcd.begin(20, 4); 
  Wire.begin();
  RTC.begin();
  lcd.init(); 
  lcd.backlight();
  lcd.print("     test1");
  lcd.setCursor(0, 1);
  lcd.print("       test2");
  delay (5000); 
  lcd.clear ();
  lcd.print("      Loading");
  lcd.setCursor(0, 1);
  lcd.print("      Data....");
  delay (5000);
  lcd.clear(); 
}

void loop() 
{
  int buttonState = digitalRead(buttonPin);
  if (buttonState == LOW)
  {
    if (lastButtonState == HIGH)
    {
      state = 1 - state;
    }
  }
  lastButtonState = buttonState;
  if (state == 0)
  {
    if (millis() - startTime >= 1000UL)
    {
      float temperature = getTemp();
      //lcd.begin(20, 4);  THIS NEEDS TO BE IN setup()
      DateTime now = RTC.now();
      lcd.setCursor(0, 0);
      lcd.print(now.hour(), DEC);
      lcd.print(':');
      lcd.print(now.minute(), DEC);
      lcd.print(" ");
      lcd.print(temperature);
      lcd.print("\337C");
      lcd.setCursor(0, 1); 
      lcd.print("Oil:       ");
      lcd.print( temp1.getTemp());
      lcd.print("\337C");
      lcd.setCursor(0, 2);  
      lcd.print("Coolant:   ");
      lcd.print( temp2.getTemp());
      lcd.print("\337C");
      startTime += 1000UL;
    }
  }
  else if (state == 1)
  {
    if (millis() - startTime >= 1000UL)
    {
      lcd.setCursor(0, 0);
      lcd.print("First Line");
      lcd.setCursor(0, 1); 
      lcd.print("Second Line");
      lcd.setCursor(0, 2);  
      lcd.print("Third Line");
      startTime += 1000UL;
    }
  }
}
//
float getTemp()
{
  byte data[12];
  byte addr[8];
  if ( !ds.search(addr)) 
  {
    ds.reset_search();
    return -1000;
  }
  if ( OneWire::crc8( addr, 7) != addr[7]) 
  {
    Serial.println("CRC Klopt niet");
    return -1000;
  }

  if ( addr[0] != 0x10 && addr[0] != 0x28) 
  {
    Serial.print("Buiten tempratuur sensor niet gevonden");
    return -1000;
  }
  ds.reset();
  ds.select(addr);
  ds.write(0x44,1); // start conversion, with parasite power on at the end
  byte present = ds.reset();
  ds.select(addr);
  ds.write(0xBE); // Read Scratchpad
  for (int i = 0; i < 9; i++) 
  { 
    data[i] = ds.read();
  }
  ds.reset_search();
  byte MSB = data[1];
  byte LSB = data[0];
  float tempRead = ((MSB << 8) | LSB); //using two's compliment
  float TemperatureSum = tempRead / 16;
  return TemperatureSum;
}

i will test it when i get home thank you :)

i tested youre code. it works but there one problem... lol first if i press the button once it shows "first line", "second line" and "third line" but it doesnt clear the lcd with the old data. and if i press the button again the arduino reboots and that also happends if i hold the button.

you can see here what happends:
http://s294.photobucket.com/user/Danny632/media/arduino/20140826_005838.mp4.html?sort=3&o=0

lcd.clear();

Is your friend.

already did that now i need to figure out why the arduino "reboots"