Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <DigisparkOLED.h>
- #include <font6x8.h>
- #include <OneWire.h>
- #define DS18B20_ID 0x28
- OneWire ds(5);
- int timer = 0;
- void setup() {
- oled.begin();
- }
- void loop() {
- byte temp;
- byte data[12];
- byte addr[8];
- byte i;
- delay(1000);
- timer++;
- oled.setCursor(0, 0);
- oled.print(timer);
- oled.setCursor(0, 1);
- if (!ds.search(addr)) {
- ds.reset_search();
- oled.print(F("er1"));
- return ;
- }
- if (OneWire::crc8( addr, 7) != addr[7]) {
- oled.print(F("er2"));
- return ;
- }
- if (addr[0] != DS18B20_ID) {
- oled.print(F("er3"));
- return ;
- }
- ds.reset();
- ds.select(addr);
- // Start conversion
- ds.write(0x44, 1);
- // Wait some time...
- //delay(1000);
- ds.reset();
- //ds.select(addr);
- // Issue Read scratchpad command
- ds.write(0xBE);
- // Receive 9 bytes
- for ( i = 0; i < 9; i++) {
- data[i] = ds.read();
- }
- //// Calculate temperature value
- //temp = ((( (data[1] << 8) + data[0] )*0.0625)*1.8)+32;
- //oled.setCursor(0, 0);
- oled.print(data[1]);
- //oled.setCursor(10, 0);
- oled.print(data[0]);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement