/
gatortemp.ts
66 lines (54 loc) · 1.68 KB
/
gatortemp.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/**
* Mary West @ SparkFun Electronics
* July 3, 2017
* https://github.com/sparkfun/pxt-gator-temp
* Development environment specifics:
* Written in Microsoft Makecode
* Tested with a SparkFun gatortemp sensor and micro:bit
*
* This code is released under the [MIT License](http://opensource.org/licenses/MIT).
* Please review the LICENSE.md file included with this example. If you have any questions
* or concerns with licensing, please contact techsupport@sparkfun.com.
* Distributed as-is; no warranty is given.
*/
/**
* Functions to operate the gatortemp sensor
*/
enum GatorTempType{
F=1,
C=2,
adcVal=3,
}
//% color=#f44242 icon="\uf2c9"
namespace gatortemp {
// Functions for reading temperature from the gatortemp in degrees C or F
/**
* Reads the number
*/
//% weight=30 blockId="gatortemp_temp" block="Get Temperature on pin %pin | in %GatorTempType"
export function temp(pin: AnalogPin, type: GatorTempType): number{
let tempADCVal = pins.analogReadPin(pin)
switch(type){
case GatorTempType.F: return getDegF(tempADCVal)
case GatorTempType.C: return getDegC(tempADCVal)
case GatorTempType.adcVal: return tempADCVal
default: return -11111111
}
}
/**
* Function used for simulator, actual implementation is in gatorTemp.cpp
*/
//% shim=gatortemp::getDegF
function getDegF(tempADCVal: number) {
// Fake function for simulator
return 0
}
/**
* Function used for simulator, actual implementation is in gatorTemp.cpp
*/
//% shim=gatortemp::getDegC
function getDegC(tempADCVal: number) {
// Fake function for simulator
return 0
}
}