# KY04 **Repository Path**: googlegis/KY04 ## Basic Information - **Project Name**: KY04 - **Description**: micro:bit入门套件Makecode库 from https://github.com/zhuning239/KY04.git - **Primary Language**: Unknown - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2020-05-18 - **Last Updated**: 2022-07-12 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # KY040 旋转编码器 MakeCode Package 这个包是KY040旋转编码器的MakeCode库 ## 硬件连接 1. Connect the appropriate pins (CLK, DT, SW, GND) to the micro:bit. ## Blocks ### Initialise rotary encoder Initialises the rotary encoder. Sets up the micro:bit to use the rotary encoder. ```sig RotaryEncoder.init(P0, P1, P2) ``` This block must be placed before any of the other blocks in this list. ### On button pressed Button push event. Called whenever the button is pushed down. ```sig RotaryEncoder.onPressEvent(() => { basic.showString("Button pressed!") }) ``` ### On rotate (left/right) Rotation event. Called whenever the encoder detects rotation. ```sig RotaryEncoder.onRotateEvent(RotationDirection.Left, () => { basic.showString("<") }) RotaryEncoder.onRotateEvent(RotationDirection.Right, () => { basic.showString(">") }) ``` ## 案例: Number input The follow code creates a number input that can be adjusted by turning the encoder. ```blocks RotaryEncoder.init(P0, P1, P2) let item = 0 basic.showNumber(item) RotaryEncoder.onRotateEvent(RotationDirection.Left, () => { item -= 1 basic.showNumber(item) }) RotaryEncoder.onRotateEvent(RotationDirection.Right, () => { item += 1 basic.showNumber(item) }) RotaryEncoder.onPressEvent(() => { basic.showString("selected!") }) ``` ## 授权方式 MIT 湖南创乐博智能科技有限公司 ## 支持硬件 * for PXT/microbit