Micro:bit Advent Calendar Day 03 - Push Buttons


#1

Need help for the Micro:Bit Advent Calendar Day 3 Guide ( Micro:bit Advent Calendar Day 3 - Push Buttons )? Just post on this thread and our highly trained team of Micro:Bit ninjas will be able to help you in no time!


#2

The kids got to learn a bit of debugging and digital input basics with this one :smiley:

Please note that Step 5 seems to be incorrect. I’m not sure if there is further code needed to enable an internal pullup resistor in the micro:bit, or if there was meant to be an external pullup resistor wired? I had to get dressed and head to work, so didn’t have the time to do further testing, so I just had the kids move the black jumper from B2 to I13 to take the (-) on the pushbutton to the 3v3 rail :slight_smile:

Thanks guys! :slight_smile:


#3

I agree with @Rendrag’s comments on step 5. Moving the black jumper from B2 to I13 works.

The instructions at step 11 are a bit confusing - they seem to double up with an unnecessary “else if”.


#4

Would love to see a simple summary of what the wiring is doing at the end of each day. I can see that day 3 uses the push button to connect P0 to the 3.3v, but I don’t know why it does that.


#5

https://makecode.microbit.org/_Wr2gPu34y3og is my code that works with or without the proper three wire connection to the button.

The button should be wired with ground on the first pin (as per the instructions), 3.3v on the second pin and signal (P0) on the third pin.


#6

I have been unable to make if statements work to switch pins off after switching them on. I tried a few things and it works properly in the simulator. When I push the code to the device it fails. Been frustrating. I now see this guide has been removed as well. I haven’t followed this one yet but anyhow interested to know why it’s gone.


#7

Looks like the issue is with digitalreadpin. The code below works in the sim but displays a 0 on the led array and won’t change from there on the actual device.
let tm = 0
input.onButtonPressed(Button.A, function () {
if (tm == 0) {
pins.digitalWritePin(DigitalPin.P1, 1)
tm = 1
basic.showString("" + pins.digitalReadPin(DigitalPin.P1))
} else if (tm == 1) {
pins.digitalWritePin(DigitalPin.P1, 0)
tm = 0
basic.showString("" + pins.digitalReadPin(DigitalPin.P1))
}
})


#8

The push button supplied in the advent calendar is a 3 pin device, it has a internal pull-up resistor so you do not have to worry about adding one externally or enabling it in software.