Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- let Cnt1 = 0
- let Cnt = 0
- control.onEvent(EventBusSource.MICROBIT_ID_IO_P8, EventBusValue.MICROBIT_PIN_EVT_RISE, () => {
- Cnt += 1
- })
- control.onEvent(EventBusSource.MICROBIT_ID_IO_P12, EventBusValue.MICROBIT_PIN_EVT_FALL, () => {
- Cnt1 += 1
- })
- control.onEvent(EventBusSource.MICROBIT_ID_IO_P8, EventBusValue.MICROBIT_PIN_EVT_FALL, () => {
- Cnt += 1
- })
- control.onEvent(EventBusSource.MICROBIT_ID_IO_P12, EventBusValue.MICROBIT_PIN_EVT_RISE, () => {
- Cnt1 += 1
- })
- pins.setEvents(DigitalPin.P8, PinEventType.Edge)
- pins.setEvents(DigitalPin.P12, PinEventType.Edge)
- Cnt = 0
- Cnt1 = 0
- basic.forever(() => {
- if (input.buttonIsPressed(Button.A)) {
- Cnt = 0
- Cnt1 = 0
- iBIT.Motor(ibitMotor.Forward, 50)
- } else if (input.buttonIsPressed(Button.B)) {
- Cnt = 0
- Cnt1 = 0
- iBIT.Motor(ibitMotor.Backward, 50)
- } else if (Cnt >= 40) {
- iBIT.MotorStop()
- } else if (Cnt1 >= 40) {
- iBIT.MotorStop()
- }
- })
Advertisement
Add Comment
Please, Sign In to add comment