1
2import * as DS18B20 from 'ds18b20'
3
4
5/*
6Please add this section into app.json when run this script as app.js.
7This configuration is designed for haas100 edu k1.
8 {
9    "version": "1.0.0",
10    "io": {
11        "DS18B20": {
12            "type": "GPIO",
13            "port": 4,
14            "dir": "output",
15            "pull": "pullup"
16        }
17    },
18    "debugLevel": "DEBUG"
19 }
20*/
21
22console.log('testing DS18B20...');
23
24DS18B20.init("DS18B20");
25
26var temperature;
27var count = 10;
28
29while(count-- > 0)
30{
31    temperature = DS18B20.getTemperature();
32
33    {
34        console.log("Temperature is: " , temperature);
35    }
36}
37
38DS18B20.deinit();
39console.log("test DS18B20 success!");
40
41