FUNITEM - How to make Portable waterproof Temperature Sensor 소형 방수 온도센서 만들기 :)



<How to make Portable waterproof Temperature Sensor>


Digitspark Source Code


#include <DigisparkOLED.h>
#include <OneWire.h>
#include <Wire.h>

OneWire ds(3);
byte addr[8];

void setup() {
  oled.begin();
  oled.clear(); //all black
  delay(200);

  if ( !ds.search(addr)) {
    ds.reset_search();
    delay(250);
    return;
  }
}

void loop() {
  byte i;
  byte data[12];

  ds.reset();
  ds.select(addr);
  ds.write(0x44, 1);
  delay(1000);
  ds.reset();
  ds.select(addr);
  ds.write(0xBE);

  for ( i = 0; i < 9; i++) {           // we need 9 bytes
    data[i] = ds.read();
  }

  int16_t raw = (data[1] << 8) | data[0];
  byte cfg = (data[4] & 0x60);

  if (cfg == 0x00) raw = raw & ~7;
  else if (cfg == 0x20) raw = raw & ~3;
  else if (cfg == 0x40) raw = raw & ~1;

  oled.setCursor(0, 0); //top left
  oled.setFont(FONT8X16);
  oled.println(F("Temperature"));
  oled.setCursor(0, 2);
  oled.print(raw / 16);
  oled.print(".");
  oled.print(raw % 16);
  oled.setCursor(40, 2);
  oled.println(F(" 'C"));
}

댓글 쓰기

0 댓글