Advertisement
ektoras2012

lesson 15

May 24th, 2020
2,030
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.   LiquidCrystal Library - Hello World
  3.  
  4.  Demonstrates the use a 16x2 LCD display.  The LiquidCrystal
  5.  library works with all LCD displays that are compatible with the
  6.  Hitachi HD44780 driver. There are many of them out there, and you
  7.  can usually tell them by the 16-pin interface.
  8.  
  9.  This sketch prints "Hello World!" to the LCD
  10.  and shows the time.
  11.  
  12.   The circuit:
  13.  * LCD RS pin to digital pin 12
  14.  * LCD Enable pin to digital pin 11
  15.  * LCD D4 pin to digital pin 5
  16.  * LCD D5 pin to digital pin 4
  17.  * LCD D6 pin to digital pin 3
  18.  * LCD D7 pin to digital pin 2
  19.  * LCD R/W pin to ground
  20.  * LCD VSS pin to ground
  21.  * LCD VCC pin to 5V
  22.  * 10K resistor:
  23.  * ends to +5V and ground
  24.  * wiper to LCD VO pin (pin 3)
  25.  
  26.  Library originally added 18 Apr 2008
  27.  by David A. Mellis
  28.  library modified 5 Jul 2009
  29.  by Limor Fried (http://www.ladyada.net)
  30.  example added 9 Jul 2009
  31.  by Tom Igoe
  32.  modified 22 Nov 2010
  33.  by Tom Igoe
  34.  
  35.  This example code is in the public domain.
  36.  
  37.  http://www.arduino.cc/en/Tutorial/LiquidCrystal
  38.  */
  39.  
  40. // include the library code:
  41. #include <LiquidCrystal.h>
  42. #define TempPin A0
  43.  
  44. // initialize the library with the numbers of the interface pins
  45. LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
  46.  
  47. void setup() {
  48.   Serial.begin( 9600 );
  49.   pinMode(LED_BUILTIN, OUTPUT);
  50.   pinMode(TempPin, INPUT);
  51.  
  52.   // set up the LCD's number of columns and rows:
  53.   lcd.begin(16, 2);
  54.   // Print a message to the LCD.
  55.   lcd.print("Temperature");
  56. }
  57.  
  58. void loop() {
  59.   float temp = ((analogRead(TempPin) * (5.0/1024))-0.5 )/0.01;
  60.   // set the cursor to column 0, line 1
  61.   // (note: line 1 is the second row, since counting begins with 0):
  62.   lcd.setCursor(0, 1);
  63.   // print the number of seconds since reset:
  64.   lcd.print("                ");
  65.   lcd.setCursor(0, 1);
  66.   lcd.print( temp );
  67.   if (temp > 40)
  68.   {
  69.    digitalWrite(LED_BUILTIN, HIGH);
  70.   }
  71.   else {
  72.     digitalWrite(LED_BUILTIN, LOW);
  73.   }
  74.  
  75.   Serial.println( temp );
  76.   delay( 1000 );
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement