Advertisement
Guest User

Untitled

a guest
Nov 27th, 2015
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. #include <LiquidCrystal.h>
  2. #include <String.h>
  3.  
  4. int temp_pin = 0;
  5. int light_pin = 1;
  6. int data_write_offset = 6;
  7.  
  8. // BS E D4 D5 D6 D7
  9. LiquidCrystal lcd(7, 8, 9, 10, 11, 12);
  10.  
  11. void setup() {
  12. Serial.begin( 9600 );
  13. lcd.begin( 16, 2 );
  14. }
  15.  
  16. void loop() {
  17. uint32_t temp_reading;
  18.  
  19. for (uint8_t x = 0; x < 100; x++) { // take 100 readings
  20. temp_reading = analogRead( temp_pin )
  21. }
  22. temp_reading = temp_reading / 100;
  23.  
  24. Serial.println( temp_reading );
  25.  
  26. float temp_volts = temp_reading * 5.0 / 1024.0;
  27. float temp_c = (temp_volts - 0.5) * 100.0;
  28. float temp_f = temp_c * 9.0 / 5.0 + 32.0;
  29.  
  30. lcd.clear();
  31.  
  32. lcd.setCursor(0,0);
  33. lcd.print("Temp");
  34. for( int i = 0; i < data_write_offset - strlen("Temp"); i++ )
  35. lcd.print(" ");
  36. lcd.print( temp_c );
  37. lcd.print(" C");
  38.  
  39. int light_reading = analogRead( light_pin );
  40. lcd.setCursor(0,1);
  41. lcd.print("Light");
  42. for( int i = 0; i < data_write_offset - strlen("Temp"); i++ )
  43. lcd.print(" ");
  44. lcd.print( light_reading );
  45. delay( 500 );
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement