Advertisement
Guest User

Untitled

a guest
Mar 12th, 2013
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.58 KB | None | 0 0
  1. //Jeremy Blum's Arduino Tutorial Series - Episode 13 - LCDs
  2. //Sample Code - LCD Temperature Display
  3. //http://www.jeremyblum.com
  4. //Debouncing code from Tutorial 2: http://jeremyblum.com/2011/01/10/arduino-tutorial-2-now-with-more-blinky-things/
  5. //I2C Code from Tutorial 7: http://jeremyblum.com/2011/02/13/arduino-tutorial-7-i2c-and-processing/
  6. //LiquidCrystal library by David A. Mellis, Limor Fried (http://www.ladyada.net), and Tom Igoe
  7. //http://www.arduino.cc/en/Tutorial/LiquidCrystal
  8.  
  9. //Include Wire I2C Library
  10. //#include <Wire.h> flag
  11. #include <OneWire.h>
  12.  
  13. //int temp_address = 72; flag
  14.  
  15. #include <OneWire.h>
  16.  
  17. int SensorPin = 7;
  18.  
  19.  
  20. // include the library code:
  21. #include <LiquidCrystal.h>
  22.  
  23. // initialize the library with the numbers of the interface pins
  24. LiquidCrystal lcd(2, 3, 4, 5, 6, 7);
  25.  
  26.  
  27. byte degree[8] = {
  28. B00110,
  29. B01001,
  30. B01001,
  31. B00110,
  32. B00000,
  33. B00000,
  34. B00000,
  35. };
  36.  
  37. int switchPin = 8;
  38. boolean lastButton = LOW;
  39. boolean currentButton = LOW;
  40. boolean celcius = true;
  41.  
  42. void setup() {
  43. //Mode Button
  44. pinMode(switchPin, INPUT);
  45.  
  46. //Create a Wire Object
  47. //Wire.begin();
  48.  
  49. // set up the LCD's number of columns and rows:
  50. lcd.begin(16, 2);
  51. // Print a message to the LCD.
  52. lcd.print("ROOM TEMPERATURE");
  53.  
  54. lcd.setCursor(11,1);
  55. lcd.print("mode>");
  56.  
  57. //Make progress characters
  58. lcd.createChar(0, degree);
  59. }
  60.  
  61. boolean debounce(boolean last)
  62. {
  63. boolean current = digitalRead(switchPin);
  64. if (last != current)
  65. {
  66. delay(5);
  67. current = digitalRead(switchPin);
  68. }
  69. return current;
  70. }
  71.  
  72. void loop() {
  73.  
  74. //Handle Temperature
  75. //Send Request
  76. // Wire.beginTransmission(temp_address); //Start talking flag
  77. // Wire.write(0); //Ask for Register zero
  78. // Wire.endTransmission(); //Complete Transmission
  79. // Wire.requestFrom(temp_address, 1); //Request 1 Byte
  80. // while(Wire.available() == 0); //wait for response
  81. // int c = Wire.read(); // Get the temp in c
  82. // //do some math... flag
  83.  
  84. float c = getTemp();
  85.  
  86. int f = round(c*9.0/5.0 +32.0); flag
  87.  
  88.  
  89. currentButton = debounce(lastButton);
  90. if (lastButton == LOW && currentButton == HIGH)
  91. {
  92. if (celcius) celcius = false;
  93. else celcius = true;
  94.  
  95. //Erase old characters
  96. lcd.setCursor(0,1);
  97. lcd.print(" ");
  98. }
  99. lastButton = currentButton;
  100.  
  101.  
  102. lcd.setCursor(0,1);
  103. if (celcius)
  104. {
  105. lcd.print(c);
  106. lcd.write((byte)0);
  107. lcd.print("C");
  108. }
  109. else
  110. {
  111. lcd.print(f);
  112. lcd.write((byte)0);
  113. lcd.print("F");
  114. }
  115.  
  116. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement