Navigation

    M5Stack Community

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    1. Home
    2. LyleDodge
    L
    • Continue chat with LyleDodge
    • Start new chat with LyleDodge
    • Flag Profile
    • Profile
    • Following
    • Followers
    • Blocks
    • Topics
    • Posts
    • Best
    • Groups
    Save
    Saving

    LyleDodge

    @LyleDodge

    5
    Reputation
    2
    Posts
    783
    Profile views
    0
    Followers
    0
    Following
    Joined Last Online

    LyleDodge Follow

    Posts made by LyleDodge

    • RE: UIFlow digital input interrupt

      I've created a custom module to avoid the need to use the "Execute" block. It basically gives you a way to set the pin number, trigger, and callback for the IRQ. You will still create your own function using Blockly.

      1. Create a Variable: example "counter"
      2. Create a Function:
        1. Name it what you like, example: "count_pulses"
        2. Add single step from Variables: change counter by 1
      3. Init PWM0 with your desired pin, freq, and duty
      4. Load the attached file under Custom | Open *.m5b file
      5. Drag "PIN_IRQ" from Custom onto your workspace
        1. Set the pin number (just an integer, 0 for example)
        2. Set your trigger "machine.Pin.IRQ_RISING"
        3. Set the handler to your function from step 2 above "count_pulses"
      6. Add a label if you want and set the loop event to update a label with the current counter value
      7. It sounds more complicated than it actually is, check the screenshot

      0_1622847040214_PWM_IRQ_Demonstration.png

      Your resulting code should look vaguely like this:

      from m5stack import *
      from m5ui import *
      from uiflow import *
      import machine
      
      setScreenColor(0x222222)
      
      counter = None
      
      label0 = M5TextBox(146, 187, "Text", lcd.FONT_Default, 0xFFFFFF, rotate=0)
      
      from numbers import Number
      
      def count_pulses():
        global counter
        counter = (counter if isinstance(counter, Number) else 0) + 1
      
      PWM0 = machine.PWM(26, freq=25000, duty=50, timer=0)
      pin0.irq(trigger=machine.Pin.IRQ_RISING, handler=count_pulses)
      while True:
        label0.setText(str(counter))
        wait_ms(2)
      

      Have fun storming the castle!

      posted in UIFlow
      L
      LyleDodge
    • RE: Is there a way to reuse blockly code?

      I agree, it is sad. :(

      There is hope, however! I opened up one of the .m5f files that is saved from UI Flow to learn that it is a hybrid json/xml file with all the blockly code represented in XML. I'm thinking of working up a simple script that could be run in browser to parse this data and allow you pull single blocks and merge them into another file.

      The concept here is that you upload two files (library.m5f and project.m5f, for examples sake) and then you can pluck whole blocks from and to either file. This way your great new invention from project.m5f can be added to your library and your great work from the library can be added to your project.

      It will be simple, dare I say crude, to start with but should help. Also, I did tinker with making a custom .m5b file and it's not that hard but not quite the same as having a pre-built set of routines you want to use all the time. I'll post more info here once I have anything worth playing with.

      posted in UIFlow
      L
      LyleDodge