hi everyone welcome to the next episode
of micro monsters and today we're going
to be doing a magic trick and so we're
going to be using the micro bit and we
bought some magic buttons today we've
got an A and a B button label and we're
going to show you a trick using the a
and B button which hopefully you'll be
astounded by and then if you're really
lucky and you carry on watching when you
promise to subscribe to a channel we'll
show you how the trick actually works so
let's get on and do the trick what we've
done is we've labeled so it's easier to
read the micro bit button so a has a
label today B has a label to speed we've
written a little program that when you
press a it says a and when you press B
this is pretty it's really simple to
carry on pressing 8 we'll go back again
there's no trick it will just change
between them okay but what we're going
to do now is we're going to try changing
the labels over so we take the label
ready put it on B yeah table B put it on
a okay so now if we were to press a
which is on the left but we've labeled B
it will still say a and when we press a
B on the right which is labeled a or
still suppress people's all we've done
is change the labels so let's try that
so if you press a it says hey Chris and
do it again press a is it it's changed
over with the label there we go what's
going on so if we press a label with a B
bar it doesn't mind a bit how did you
get it to swap you begin you press ok
when rip that's magical but change them
back again change it back again if it
works okay so if you
yes I now he says when you press that's
magic
awesome so that's that's the trick I
think it's pretty cool um as soon as
Jasmine lets me know how we actually do
it I can't go but um so if you don't
want to know how to do the trick then
goodbye and thank you for watching the
episode if you want to watch how we did
the trick and show you how we can to
trick and once Jasmine tells me how it
works then stay on but please make sure
you subscribe to us first and in a few
seconds we'll stop showing how the trick
works so thanks for staying on um magic
tricks are often quite cool when you
don't know how they're done but we're
going to show you how they're done
because this is a little about code and
that's what channel is about but I don't
actually know how it is done yet so
we're going to need Jasmine to tell us
what the secret is tricked really is
hell how does it swap is it magic labels
no it's not magic 8-balls it's a magic
like what okay so that's a really strong
magnet that we bought for a different
project on on ebay so how how does it
how's it work well I saw my hands over
if magnet is nearly like rabbit then it
detects it is and it switches over the
pictures from HP and B takes okay so
show us that working okay oh it's
sticking so maybe there it says be okay
and press a okay if you take the magnet
away and try again probably too close
okay oh there's nothing to do is what
canuse labels over to know okay so how
did you do that during the tricks we
didn't see the magnets of what did you
do to trick us well with my magical
hands I held it in my hand I can see all
it so when I could Hey it goes to B now
when I get B it goes to a and when I
cook a goes to B okay so now we're going
to go and show you the code for that
and hell
works and how you can program your own
market bit to do this trick okay so now
we're going to learn how hasman coded
this and show you how the trick works so
what do we need to start off with do we
need something to detect the magnet yep
that works okay so there is bit hidden
now so we're using our favorite editor
which is app code that my crabbit org
like that over comm sorry and it will
come to this address at top PTX top
microcut - org and it's almost identical
to the block editor on the micro-p
website but it's being constantly
updated it's got lots of nice new things
in it a bit more powerful this is when
we use now you have seen in our other
tutorials so we're looking for input
because it's from a mag from the compass
is what we're using but the one we want
is hidden under this more so click more
and we want to read magnetic force all
right yep and you can read all about
magnetic force you don't understand what
it's doing by clicking on this link here
and we'll open up a little help page for
us to read all about it we don't really
care what axis we don't care whereabouts
the magnet is around the micro bit we
just want a strength of it so we can
just choose strength okay yeah so we
need that and we've got to measure that
I've we all the time so let's let's go
and look in advanced so we want to
running in in like the background not
the main bit of the code that's me
constantly running so we can use this
running background block in control it
means that the rest of the code can
carry on running but this will always be
running at the same time as well so we
want to say we want to measure something
we want to loop around doing it all the
time here yep
so we should be use the forever block
carry on running forever you can use the
while and you just leave it on true that
forever is just cleaner and easier so we
want to check that the magnets near it
so we're going to need some kind of if
for something
so right yep and I think we're going to
do a different thing if it's not all
using if-then so we want to measure the
magic for the magnetic magic force I
love as well for this trick the magnetic
force and when it is up so when when you
don't have a magnet Europe from our
other products we've done with this you
get kind of like a background magnetic
from the Earth's magnetic field of like
40 50 something like that so we should
probably measure if it's like some over
100 bigger than 100 yeah so in logic
we've got this so if magnetic force is
greater than 100 let's say um but that
there's a bit of problem with magnets
isn't there because what the magnets
have a plus or minus yeah
so one way is different from the other
so the strength will come out with
either a minus symbol behind it in front
of it sorry or not a minus signal and it
will tell you which way around the
magnet is but we don't care which way
around the magnet is so we need to get
rid of that minus symbol so there is
somewhere in here I think in maths and
in more there is this absolute absolute
basically says I don't care whether it's
a negative number or a positive number I
just want to know how much is if it's
negative 50 it'll make it 50 if it's 50
it will stay 50 so we put that into
there it doesn't matter if it's negative
or not the number that comes out will
always be positive and we can check it
around it so that's going to run in the
background it's going to check this is
greater than 100 so is the magnet near
it what do we do any like a variable or
something to to know whether the magnets
near it that we use yeah sound good sign
so that's create a new variable what
recommission cool is variable is
switched
because it's whether we've switched the
buttons right what effectively sir is
switched and is it a number or is it
what what things should this variable
store I store these trees and Falls oh
yeah yeah so if the field strength is
greater than 100 then we do want it to
be switched because the magnets new and
we'll duplicate this if it isn't near
100 which is either the magnet isn't
there or we've just taken it away we
want it to be full so want to get back
to not being switched yeah yeah and
should it be set right the beginning
should it be true or false do you think
Doc's because right the beginning we
probably don't have a magnet lyrically
all right so now we've got a bit that
detects the magnet because it's going to
run in the background it's going to run
forever keep looping around doing this
again and again and again it's going to
say if the magnets near it's the
strength is greater than 100 and you
might have changed that hundred very
fair value depending on your magnet so
if it doesn't work change it up and down
and see how it works so if it is near it
set a switch to true otherwise so it's
false so now we've got that it what the
next two bits we need we need to check
the buttons don't we because it's all
about button so when button a is pressed
the kind of point of the trick is it
should show a so let's start there yeah
yep so in basic show Hey
and what UK that change button be for
that at the moment is no trick she won't
change so what are we gonna have to do
to make button AE switch over and button
B switch over if the magnet is there and
what how do we know if the magnet is
there cuz of this code down here if it's
true okay so eat a logic if so what
we're checking is true if the magnet is
near it or not so if if switched if if
switch is switched equals true and I
never do want true or false that if
switched equals true show ourselves
otherwise so else shows watch the show
if it is switched B okay so if we get
rid of this for a moment do you care all
of this and I'm button B if it if it is
switched is false it should show E and
then plate okay so now if we press
button name is no magnet so press it is
switched is not true it'll show a and B
will show B and if it's switched has
been changed to true by our code down
here then it will switch over and show a
and B I think that's all we need yeah
pretty simple when you think about it
yeah there's a nice little trick isn't
it yeah so that's all you really need to
do then if you haven't used this or any
of the other ones before you click
download and copy it to your micro bit
or if you've ever looked at this you can
go and use this in upload s what we run
and it runs in
background and uploads to your micro bit
and then that's how you perform a trick
go and buy a magnet or just get like a
fridge magnet if you've got one of those
around try it out for yourself and let
us know how you get on make sure you
don't give the seeker away without
subscribing and without telling people
about our channel I think that's all for
now
bye