Monday, October 15, 2018

day 14 lab

//LCD with I2C
#include <Wire.h>
//Include the library code:
#include <LiquidCrystal.h>
//Initialize the library with the numbers of the interface pins
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
int temp_address = 72; //1001000 written as decimal number
void setup() {
 // initialize serial communication at 9600 bits per second:
 Serial.begin(9600);
 //Set up the LCDs number of columns and rows:
 lcd.begin(16, 2);
  //Create a Wire object
 Wire.begin();
}
void loop() {
   //Start talking to the device at the specified address
 Wire.beginTransmission(temp_address);
 //Send a bit asking for register zero, the data register
 Wire.write(0);
 //Complete Transmission
 Wire.endTransmission();
 //Read the temperature from the device
 //Request 1 Byte from the specified address
 Wire.requestFrom(temp_address, 1);
 //Wait for response
 while(Wire.available() == 0);
 //Get the temp and read it into a variable
 int c = Wire.read();
 c = map(c, 22, 32, 22, 32);
 c = constrain(c, 22, 32);
 int buttonval = analogRead(A0);// let buttons read as variable
 int f = round(c*9.0/5.0 +32.0);//convert to farenheit
 // read the input on analog pin 0:
Serial.println(buttonval);
delay(1);
 Serial.println(c);
 delay(500); // delay in between reads
  Serial.println(f);
 delay(500); // delay in between reads
if ( buttonval == 481)
{
  switch(c){
  case 23:{
    lcd.setCursor(0,1);
    lcd.print("23C");
    break;
  }
  case 24:{
  lcd.setCursor(0,1);
    lcd.print("24C");
    break;
}
case 25:{
  lcd.setCursor(0,1);
    lcd.print("25C ");
    break;
}
case 26:{
  lcd.setCursor(0,1);
    lcd.print("26C");
    break;
}
}
}
else if ( buttonval == 0){
  switch(f){
  case 73:{
    lcd.setCursor(0,1);
    lcd.print("73F  ");
    break;
  }
  case 75:{
  lcd.setCursor(0,1);
    lcd.print("75F  ");
    break;
}
case 77:{
  lcd.setCursor(0,1);
    lcd.print("77F  ");
    break;
}
case 79:{
  lcd.setCursor(0,1);
    lcd.print("79F  ");
    break;
}
}
}
return;
}

No comments:

Post a Comment