avr: ADC with 0-1023 range

This commit is contained in:
Ron Evans
2018-09-18 15:02:38 +02:00
committed by Ayke van Laethem
parent dbb5ae5a23
commit 40f834d58f
4 changed files with 77 additions and 10 deletions
+29
View File
@@ -0,0 +1,29 @@
package main
import (
"machine"
"time"
)
// This example assumes that an analog sensor such as a rotary dial is connected to pin ADC0.
// When the dial is turned past the midway point, the built-in LED will light up.
func main() {
machine.InitADC()
led := machine.GPIO{machine.LED}
led.Configure(machine.GPIOConfig{Mode: machine.GPIO_OUTPUT})
sensor := machine.ADC{machine.ADC2}
sensor.Configure()
for {
val := sensor.Get()
if val < 512 {
led.Low()
} else {
led.High()
}
time.Sleep(time.Millisecond * 100)
}
}
-10
View File
@@ -1,10 +0,0 @@
package main
import "time"
func main() {
for {
println("hello world!")
time.Sleep(time.Second)
}
}