🤖Have you ever tried Chat.M5Stack.com before asking??😎
    M5Stack Community
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Register
    • Login

    M5-bit (Micro-Bit) part 2

    PROJECTS
    3
    8
    12.1k
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • ChrisWRC
      ChrisWR
      last edited by ChrisWR

      Turn your Micro-Bit leds on/off with the M5, create your own smilies on the M5.. ect..

      0_1577130117472_IMG_20191223_203318.jpg

      Here is the Micro-Bit code ;

      0_1577130157915_Image1.jpg

      And te M5Stack code ;

      
      
      #include <M5Stack.h>
      #include <M5StackUpdater.h>
      
      #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));
            }
      }
      

      On the M5; button A moves left, button C moves right and button B toggles the led, this shows on Micro-Bit and M5

      1 Reply Last reply Reply Quote 1
      • world101W
        world101
        last edited by

        This is great, but could you please format your code correctly when posting so we can read it? You do that by pasting your code enclosed within three back ticks (```) on the same line or separate lines.

        like this or

        like this
        
        ChrisWRC 1 Reply Last reply Reply Quote 0
        • ChrisWRC
          ChrisWR @world101
          last edited by

          @world101 ok, thx

          ajb2k3A 1 Reply Last reply Reply Quote 0
          • ajb2k3A
            ajb2k3 @ChrisWR
            last edited by ajb2k3

            @chriswr said in M5-bit (Micro-Bit) part 2:

            @world101 ok, thx

            Much better.
            Is the a uiflow blocky version of you latest code?

            UIFlow, so easy an adult can learn it!
            If I don't know it, be patient!
            I've ether not learned it or am too drunk to remember it!
            Author of the WIP UIFlow Handbook!
            M5Black, Go, Stick, Core2, and so much more it cant be fit in here!

            ChrisWRC 1 Reply Last reply Reply Quote 0
            • ChrisWRC
              ChrisWR @ajb2k3
              last edited by

              @ajb2k3 Its not uiflow, its makecode (for micro-bit) and arduino for m5

              ajb2k3A 1 Reply Last reply Reply Quote 0
              • ajb2k3A
                ajb2k3 @ChrisWR
                last edited by

                @chriswr I understand that it make code for the microbit but i was hoping you would consider using m5stacks uiflow for the m5stack products just to be consistant.

                Apart from this, nice work and please keep sharing!

                UIFlow, so easy an adult can learn it!
                If I don't know it, be patient!
                I've ether not learned it or am too drunk to remember it!
                Author of the WIP UIFlow Handbook!
                M5Black, Go, Stick, Core2, and so much more it cant be fit in here!

                ChrisWRC 2 Replies Last reply Reply Quote 0
                • ChrisWRC
                  ChrisWR @ajb2k3
                  last edited by

                  This post is deleted!
                  1 Reply Last reply Reply Quote 0
                  • ChrisWRC
                    ChrisWR @ajb2k3
                    last edited by

                    @ajb2k3 0_1577665242771_Image1.jpg
                    0_1577665257165_Image2.jpg
                    0_1577665274871_Image3.jpg

                    1 Reply Last reply Reply Quote 1
                    • First post
                      Last post