Advertisement
Guest User

Untitled

a guest
Mar 29th, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. #include <DigisparkOLED.h>
  2. #include <font6x8.h>
  3.  
  4. #include <OneWire.h>
  5.  
  6. #define DS18B20_ID 0x28
  7.  
  8. OneWire ds(5);
  9.  
  10. int timer = 0;
  11.  
  12. void setup() {
  13. oled.begin();
  14. }
  15.  
  16.  
  17. void loop() {
  18. byte temp;
  19. byte data[12];
  20. byte addr[8];
  21.  
  22. byte i;
  23.  
  24. delay(1000);
  25.  
  26. timer++;
  27. oled.setCursor(0, 0);
  28. oled.print(timer);
  29.  
  30. oled.setCursor(0, 1);
  31. if (!ds.search(addr)) {
  32. ds.reset_search();
  33. oled.print(F("er1"));
  34. return ;
  35. }
  36. if (OneWire::crc8( addr, 7) != addr[7]) {
  37. oled.print(F("er2"));
  38. return ;
  39. }
  40. if (addr[0] != DS18B20_ID) {
  41. oled.print(F("er3"));
  42. return ;
  43. }
  44.  
  45. ds.reset();
  46. ds.select(addr);
  47. // Start conversion
  48. ds.write(0x44, 1);
  49.  
  50. // Wait some time...
  51. //delay(1000);
  52.  
  53. ds.reset();
  54. //ds.select(addr);
  55. // Issue Read scratchpad command
  56. ds.write(0xBE);
  57. // Receive 9 bytes
  58. for ( i = 0; i < 9; i++) {
  59. data[i] = ds.read();
  60. }
  61.  
  62. //// Calculate temperature value
  63. //temp = ((( (data[1] << 8) + data[0] )*0.0625)*1.8)+32;
  64.  
  65. //oled.setCursor(0, 0);
  66. oled.print(data[1]);
  67. //oled.setCursor(10, 0);
  68. oled.print(data[0]);
  69.  
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement