diff --git a/docs/assets/img/product_pics/unit/m5bit/m5bit.png b/docs/assets/img/product_pics/unit/m5bit/m5bit.png new file mode 100644 index 00000000..28be797a Binary files /dev/null and b/docs/assets/img/product_pics/unit/m5bit/m5bit.png differ diff --git a/docs/en/core/atom_lite.md b/docs/en/core/atom_lite.md index 94533997..fa336e9c 100644 --- a/docs/en/core/atom_lite.md +++ b/docs/en/core/atom_lite.md @@ -45,6 +45,8 @@ Supported development platforms and program languages: Arduino, Blockly language - SDIO master/salve 50MHz - SD-card interface support + + ## Peripherals Pin Map diff --git a/docs/en/core/atom_matrix.md b/docs/en/core/atom_matrix.md index 13996454..85b4a8ea 100644 --- a/docs/en/core/atom_matrix.md +++ b/docs/en/core/atom_matrix.md @@ -42,6 +42,7 @@ Supported development platforms and program languages: Arduino, Block based prog - SDIO master/salve 50MHz - SD-card interface support + + ## Peripherals Pin Map diff --git a/docs/en/unit/m5-bit.md b/docs/en/unit/m5-bit.md index 6e9a080a..143ca0ed 100644 --- a/docs/en/unit/m5-bit.md +++ b/docs/en/unit/m5-bit.md @@ -25,4 +25,79 @@ More IO pins are extended, you can used DuPont Cable to connect other hardware. ## Include -- 1x M5:bit \ No newline at end of file +- 1x M5:bit + +## Example + +- **MakeCode** + + + +### Arduino IDE + +*The code below is incomplete. TO get complete code, please click [here](https://github.com/m5stack/M5-ProductExampleCodes/tree/master/Unit/M5Bit/Arduino/M5BIT).* + +```arduino +/* + Connect to GRVOE C on M5Core +*/ +#include +#include + +#define WIDTH 320 +#define HEIGHT 240 +#define BLOCK_SIZE 40 +#define UNIT_WIDTH 5 +#define UNIT_HEIGHT 5 +#define UNIT_SIZE 25 +#define GETX(i) ((i) % (5)) +#define GETY(i) ((i) / (5)) +int world[UNIT_SIZE]; +int i; + +void setup() { + M5.begin(); + Wire.begin(); + if(digitalRead(BUTTON_A_PIN) == 0){ + Serial.println("Will load menu binary"); + updateFromFS(SD); + ESP.restart(); + } + Serial2.begin(115200, SERIAL_8N1, 16, 17); + M5.Lcd.fillScreen(BLACK); + M5.Lcd.setTextSize(2); + M5.Lcd.setCursor(35, 220); + M5.Lcd.println(" < * >"); + for (i = 0; i < UNIT_SIZE; i++) { + world[i] = 0; + } + i = UNIT_SIZE / 2; +} + +void loop() { + M5.update(); + int x = GETX(i) + 1; + int y = GETY(i); + if (world[i] > 0) M5.Lcd.fillRect(x * BLOCK_SIZE + 1, y * BLOCK_SIZE + 1, BLOCK_SIZE - 2, BLOCK_SIZE - 2, LIGHTGREY); + else M5.Lcd.fillRect(x * BLOCK_SIZE + 1, y * BLOCK_SIZE + 1, BLOCK_SIZE - 2, BLOCK_SIZE - 2, BLUE); + if (M5.BtnC.wasPressed()) { + if (world[i] > 0) M5.Lcd.fillRect(x * BLOCK_SIZE + 1, y * BLOCK_SIZE + 1, BLOCK_SIZE - 2, BLOCK_SIZE - 2, WHITE); + else M5.Lcd.fillRect(x * BLOCK_SIZE, y * BLOCK_SIZE, BLOCK_SIZE, BLOCK_SIZE, BLACK); + ++i; + if (i >= UNIT_SIZE) i=0; + } + if (M5.BtnA.wasPressed()) { + if (world[i] > 0) M5.Lcd.fillRect(x * BLOCK_SIZE + 1, y * BLOCK_SIZE + 1, BLOCK_SIZE - 2, BLOCK_SIZE - 2, WHITE); + else M5.Lcd.fillRect(x * BLOCK_SIZE, y * BLOCK_SIZE, BLOCK_SIZE, BLOCK_SIZE, BLACK); + --i; + if (i < 0 ) i=UNIT_SIZE -1; + } + if (M5.BtnB.wasPressed()) { + if (world[i] > 0) world[i]=0; + else world[i]=1; + Serial2.print(world[i]); + Serial2.print(GETX(i)); + Serial2.println(GETY(i)); + } +} +``` diff --git a/docs/zh_CN/core/atom_lite.md b/docs/zh_CN/core/atom_lite.md index 8172d093..1ceb235a 100644 --- a/docs/zh_CN/core/atom_lite.md +++ b/docs/zh_CN/core/atom_lite.md @@ -41,6 +41,8 @@ - SDIO master/salve 50MHz - 支持SD卡接口 + + ## 外设的管脚映射 diff --git a/docs/zh_CN/core/atom_matrix.md b/docs/zh_CN/core/atom_matrix.md index a9d5a99d..15fcf0f7 100644 --- a/docs/zh_CN/core/atom_matrix.md +++ b/docs/zh_CN/core/atom_matrix.md @@ -43,6 +43,8 @@ - SDIO master/salve 50MHz - 支持SD卡接口 + ## 外设的管脚映射 diff --git a/docs/zh_CN/unit/m5-bit.md b/docs/zh_CN/unit/m5-bit.md index 27e640b5..95ada439 100644 --- a/docs/zh_CN/unit/m5-bit.md +++ b/docs/zh_CN/unit/m5-bit.md @@ -28,3 +28,80 @@ ## 套件清单 - 1x M5:bit + +## 例程 + +- **MakeCode** + + + +### Arduino IDE + +*以下代码仅为片段,如需获取完整代码, [请点击此处](https://github.com/m5stack/M5-ProductExampleCodes/tree/master/Unit/M5Bit/Arduino/M5BIT).* + +```arduino +/* + Connect to GRVOE C on M5Core +*/ +#include +#include + +#define WIDTH 320 +#define HEIGHT 240 +#define BLOCK_SIZE 40 +#define UNIT_WIDTH 5 +#define UNIT_HEIGHT 5 +#define UNIT_SIZE 25 +#define GETX(i) ((i) % (5)) +#define GETY(i) ((i) / (5)) +int world[UNIT_SIZE]; +int i; + +void setup() { + M5.begin(); + Wire.begin(); + if(digitalRead(BUTTON_A_PIN) == 0){ + Serial.println("Will load menu binary"); + updateFromFS(SD); + ESP.restart(); + } + Serial2.begin(115200, SERIAL_8N1, 16, 17); + M5.Lcd.fillScreen(BLACK); + M5.Lcd.setTextSize(2); + M5.Lcd.setCursor(35, 220); + M5.Lcd.println(" < * >"); + for (i = 0; i < UNIT_SIZE; i++) { + world[i] = 0; + } + i = UNIT_SIZE / 2; +} + +void loop() { + M5.update(); + int x = GETX(i) + 1; + int y = GETY(i); + if (world[i] > 0) M5.Lcd.fillRect(x * BLOCK_SIZE + 1, y * BLOCK_SIZE + 1, BLOCK_SIZE - 2, BLOCK_SIZE - 2, LIGHTGREY); + else M5.Lcd.fillRect(x * BLOCK_SIZE + 1, y * BLOCK_SIZE + 1, BLOCK_SIZE - 2, BLOCK_SIZE - 2, BLUE); + if (M5.BtnC.wasPressed()) { + if (world[i] > 0) M5.Lcd.fillRect(x * BLOCK_SIZE + 1, y * BLOCK_SIZE + 1, BLOCK_SIZE - 2, BLOCK_SIZE - 2, WHITE); + else M5.Lcd.fillRect(x * BLOCK_SIZE, y * BLOCK_SIZE, BLOCK_SIZE, BLOCK_SIZE, BLACK); + ++i; + if (i >= UNIT_SIZE) i=0; + } + if (M5.BtnA.wasPressed()) { + if (world[i] > 0) M5.Lcd.fillRect(x * BLOCK_SIZE + 1, y * BLOCK_SIZE + 1, BLOCK_SIZE - 2, BLOCK_SIZE - 2, WHITE); + else M5.Lcd.fillRect(x * BLOCK_SIZE, y * BLOCK_SIZE, BLOCK_SIZE, BLOCK_SIZE, BLACK); + --i; + if (i < 0 ) i=UNIT_SIZE -1; + } + if (M5.BtnB.wasPressed()) { + if (world[i] > 0) world[i]=0; + else world[i]=1; + Serial2.print(world[i]); + Serial2.print(GETX(i)); + Serial2.println(GETY(i)); + } +} +``` + +