adafruit / Adafruit_CircuitPython_PIOASM

Simple assembler to convert pioasm to bytes
MIT License
27 stars 17 forks source link

Create button_pio.py #22

Closed parsko41 closed 2 years ago

parsko41 commented 3 years ago

Hi,

I am not sure if this is the correct way to do this (propose this code), and I apologize in advance if it is not. I tweaked the encoder example to create a button example. This is my first time playing with PIO. I'm pretty sure the read pin state loop could be only 2-3 lines long, but I left things as they were. I felt this library needed a button example, for the next Parsko that shows up.

I'm unclear what line 34 is about. I see the need I think, but don't understand what or why "set y 31". Is it arbitrary?

I plan on trying the encoder example with some higher line count rotaries to see if it loses counts. So, I still need to understand the code where this came from.

Thanks,

-Parsko

tannewt commented 3 years ago

This is the perfect way to propose code! Why do you want to use PIO to read the button instead of DigitalInOut? I think the set y is loading 0xff for comparison in the main code.

parsko41 commented 3 years ago

Hi, Because blinking and LED and reading a button are I/O "Hello worlds". I am trying to learn how the PIO's work, and wanted the other fundamental, a button.

The real reason. I think at first, after copy pasting code, and reading through the Circuitpython PIO tuturial, something borked out when I wanted to use the DigitalIO library to have a button trigger an LED I was coding in the tutorials. At some point, I was/am going to use multiple state machines, linked with the IRQ (I think). Still learning.

After uploading this, I realized I had some bad code. I've since evolved it and would like to retry. I think I have solved the failed checks? I'll see if I can get this fixed tonight.

-Parsko

tannewt commented 3 years ago

If all you want to do is read a button, then I'd suggest simplifying the PIO code to push 1 bit samples of the button. You will need to worry about overrun because the FIFO will store 8 old samples. An alternative would be to use exec to push the ISR to the fifo when you want to read it.

jposada202020 commented 3 years ago

Hello @parsko41, any update after tannewt comments, let us know. thanks.

parsko41 commented 2 years ago

This has gone dormant, will close.