Monday, January 15, 2018

LOOM ROW COUNTER: Simple Programming With BBC MICRO:BIT



BBC Micro:bit is a micro controller for kids with a shinning BBC brand, integrated with buttons, blue-tooth, LED display and a bunch of other sensors built-in.  And it is the first micro controller I got to experiment with half a year ago. It is a nice little package and I like it a lot. But over time, I have my hands on other arduino based boards and soon my micro:bit is kind of left rusting in a box, which is sad.

Recently I have been working on looming a scarf for my girlfriend's birthday. It is not my idea at all and she seems to really enjoy knowing me working my ass off on something that I have never tried before. Fine. But the thing is, with the most simple pattern, there are a list, with row numbers, to knit, like this:



The thing is, while looming (and watching YouTube or listening to podcast) it is very hard to remember which row I am on and got mixed up. On my first try I was working on a scarf just like this video above, things were, still manageable. But my second try the project is way more bigger and more complex, with 16 rows. I need something that is just a simple counter to help me remember where I am.

Of course I could whip out a set of arduino boards, display modules, batteries, debounced buttons, but hey, I could do the same with less, in fact, with a simple micro:bit. I dig it out last night and after just about 10 minutes I got what I want:


And on such a simple project, I went with micro python. Come on I don't have to worry about LED multiplex in arduino or, do I really need to cross-compile this using Yotta? Guess not. Here is the code:

from microbit import *
a = 1
while True:
    if button_a.was_pressed():
        a = a + 1
    elif button_b.was_pressed():
        a = a - 1
    if a == 17:
        a = 1
    display.scroll(str(a), delay=150)
   
What it does is bare minimal as well. Left button add 1 to the display, and if I add too much I can use the right button to subtract 1 from the display. Simple. But works. (One thing I got to say is those button_a.was_pressed() methods really works well on this project. I really don't have to worry debouncing my buttons at all)

I mean, this is exactly the reason why I love to play with micro controllers like micro:bit here. I can program things instead of having to live with a computer or cloud. And it really helps in daily life, even if it's the most simple program.

No comments:

Post a Comment

LOOM ROW COUNTER: Simple Programming With BBC MICRO:BIT

BBC Micro:bit is a micro controller for kids with a shinning BBC brand, integrated with buttons, blue-tooth, LED display and a bunch o...