I2c LCD Module

I am trying to figure out how to incorporate a single push button for the I2c that changes the temperature from c to f or f to c? I have looked every where and couldn't find anything..

this is what I have right now, works great...

#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x3F, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
const int sensor=A1; // Assigning analog pin A1 to variable 'sensor'
float tempc; //variable to store temperature Celsius
float tempf; //variable to store temperature Fahreinheit
float vout; //temporary variable to hold sensor reading

void setup()
{
Serial.begin(9600); // Used to type in characters

lcd.begin(16,2); // initialize the lcd for 16 chars 2 lines, turn on backlight

//-------- Write characters on the display ------------------
// NOTE: Cursor Position: (CHAR, LINE) start at 0
lcd.setCursor(0,0); //Start at character 4 on line 0
lcd.print("Temperature!");
delay(1000);
lcd.setCursor(0,1);
lcd.print("HEAT KILL's");
delay(3000);

pinMode(sensor,INPUT); // Configuring pin A1 as input
lcd.begin(16,2);

}
void loop()
{
vout=analogRead(sensor);
vout=(vout500)/1023;
tempc=vout; // Storing value in Degree Celsius
tempf=(vout
1.8)+32; // Converting to Fahrenheit
lcd.setCursor(0,0);
lcd.print("C= ");
lcd.print(tempc);
lcd.setCursor(0,1);
lcd.print("F=");
lcd.print(tempf);
delay(850); //Delay of 1 second for ease of viewing in serial monitor

}

any help would be awesome.

Hi,

first remark: pls read the "how to's" for that forum , especially how to use code tags </>.
See the URL in my signature about the forum rules.

For your sketch:

  1. (physically) connect a button to an Arduino pin and GND
  2. declare that button as input in setup() - preferably as INPUT_PULLUP, so a press will be LOW
  3. initiate a state variable which holds the most current state of the temperature unit (F or C)
  4. decide what will be the default unit of measurement at start up, say "F" by
boolean tempUnit = true;
  1. in loop()
    5.1 read the temperature and use the Fahrenheit formula to display the value as long tempUnit is "true"
    5.2 continuously read the button, if it is pressed or not including some debouncing
    (you could also use some of the debouncing libraries if you don't want to debounce manually)
  2. if a button press was detected, change tempUnit to "false" and use the Celsius formula

You could also use some little switch/case commands to either show the temperature in F or C; in that case I would use an integer variable and initialise with "1" for Fahrenheit and "2" for Celsius.

Then your code would have something like:

switch (tempUnit) {
    case 1:
      //use the formula for Fahrenheit and display the result as F
      break;
    case 2:
      //use the formula for Celsius and display the result as C
      break;
    default: 
      // if nothing else matches, do the default
      // default is optional
    break;
  }

tempf=(vout*1.8)+32; // Converting to Fahrenheit

What did you expect the smiley face to do?

Did you mean:

tempf=(vout*1.8)+32; // Converting to Fahrenheit

Don