-
Notifications
You must be signed in to change notification settings - Fork 8
/
sensors.go
61 lines (47 loc) · 1.18 KB
/
sensors.go
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
package gopherbot
import (
"machine"
"tinygo.org/x/drivers/lis3dh"
"tinygo.org/x/drivers/thermistor"
)
// AccelerometerDevice controls the Gopherbot built-in LIS3DH.
type AccelerometerDevice struct {
lis3dh.Device
}
// Accelerometer returns the AccelerometerDevice.
func Accelerometer() *AccelerometerDevice {
EnsureI2CInit()
accel := lis3dh.New(machine.I2C1)
accel.Address = lis3dh.Address1 // address on the Circuit Playground Express
accel.Configure()
accel.SetRange(lis3dh.RANGE_2_G)
return &AccelerometerDevice{
Device: accel,
}
}
// ThermometerDevice controls the Gopherbot built-in thermistor.
type ThermometerDevice struct {
thermistor.Device
}
// Thermometer returns the ThermometerDevice.
func Thermometer() *ThermometerDevice {
EnsureADCInit()
s := thermistor.New(machine.TEMPSENSOR)
s.Configure()
return &ThermometerDevice{
Device: s,
}
}
// LightMeterDevice controls the Gopherbot built-in photoresistor.
type LightMeterDevice struct {
machine.ADC
}
// LightMeter returns the LightMeterDevice.
func LightMeter() *LightMeterDevice {
EnsureADCInit()
p := machine.ADC{machine.LIGHTSENSOR}
p.Configure(machine.ADCConfig{})
return &LightMeterDevice{
ADC: p,
}
}