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 button = startButton({ pin: gpio(2) })
const servo = startServo({ pin: gpio(1) })
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
button.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)
}
Loading
esp32-c3-devkitm-1
esp32-c3-devkitm-1