From: "Björn Lundin" <b.f.lundin@gmail.com>
Subject: bbc:microbit and buttons and No_Implicit_Dynamic_Code
Date: Wed, 25 Jul 2018 09:31:19 +0200
Date: 2018-07-25T09:31:19+02:00 [thread overview]
Message-ID: <pj9924$bbm$1@dont-email.me> (raw)
Hi!
I got my microbot yesterday. I read about it here and
decided to try it out.
I also downloaded the cross-compiler and the gpl 2018 for linux
and ran it all on a linux virtualBox guest on a win 10 system.
I also cloned the Ada_Drivers_Library from github
To my surprise - it just worked :-)
And there was examples too.
I did try avr-ada with an Arduino Nano with limited success a couple of
years ago,but this was a very pleasant surprise.
So I tried some code of my own,
and there are 3 things I wonder.
1 - gpr and style. Why does the setting in the gpr file
insist on a certain style, and treat everything else as error.
Selecting all + tab does not pretty print in a way that the gpr file
wants. Someone new to Ada would have a real hard time to get anything
done. (Yes I did remove the gnaty but it should be so by default)
2 - Debugging. How do I do it? I've almost never used the debugger,
not via GPS nor via GDB. Is there a guide somewhere how to use it
via GPS? (Put_Lines have been my friend, thinking of taking
advantage of the GPS)
3 - The microbit has 2 buttons. And the microbit.Button package has a
way of subscribing callbacks to pressed/released events.
But trying to use it I get
main.adb:55:33: violation of restriction "No_Implicit_Dynamic_Code" at
system.ads:45
code as below.
with Microbit.Display;
with Microbit.Buttons;
with Microbit.Time;
procedure Main is
use Microbit.Buttons;
procedure Button_Pressed(Button : Button_Id;
State : Button_State) is
begin
case State is
when Pressed => Microbit.Display.Set(2,2);
when Released => Microbit.Display.Clear(2,2);
end case;
end Button_Pressed;
Ok : Boolean := True;
begin
MicroBit.Display.Clear;
Ok := Subscribe(Button_Pressed'Unrestricted_Access);
if Ok then
Microbit.Display.Set(0,0);
end if;
loop
Microbit.Time.Delay_Ms (200);
end loop;
end Main;
I did find an example using
if State (Button_A) = Pressed then
so problem is fixed, but I like the callback style here.
Thanks for a good integration.
(And I see that I can use my Adafruit Thermo printer too :-) )
--
--
Björn
next reply other threads:[~2018-07-25 7:31 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-07-25 7:31 Björn Lundin [this message]
2018-07-25 9:03 ` bbc:microbit and buttons and No_Implicit_Dynamic_Code fabien.chouteau
2018-07-25 9:29 ` Björn Lundin
2018-09-05 16:38 ` fabien.chouteau
2018-09-07 9:07 ` Björn Lundin
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox