import { gpio, delay } from '@devicescript/core'
import { startButton, startServo } from "@devicescript/servers"
async function main(){
// List of pins: https://microsoft.github.io/devicescript/devices/esp32/esp32c3-bare
const runButton = startButton({ pin: gpio(0) })
const stopButton = startButton({ pin: gpio(1) })
const servo = startServo({ pin: gpio(5) })
const initialAngle = await servo.angle.read()
console.log('servo test', initialAngle)
await delay(1000)
await servo.angle.write(30);
await delay(1000)
await servo.angle.write(-30);
console.log('servo test end')
// listen for button down events
runButton.down.subscribe(async () => {
console.log(`toggle`)
await servo.angle.write(-45)
await delay(1000)
await servo.angle.write(45)
})
}
try {
await main()
} catch(error){
console.log(error)
await delay(2000)
}