You've already forked Ada_Drivers_Library
mirror of
https://github.com/AdaCore/Ada_Drivers_Library.git
synced 2026-02-12 12:26:55 -08:00
* micro:bit examples digital_out: fix resistor value * micro:bit examples digital_in: fix resistor value * Update README.md * Typo * Typo * Update README.md * Update README.md * Update README.md (#366)
1.2 KiB
1.2 KiB
Buttons Example
In this example we will see how to use the two buttons of the micro:bit.
Code
To know if a button is pressed or not, we will use the function State of the
MicroBit.Buttons package.
type Button_State is (Pressed, Released);
type Button_Id is (Button_A, Button_B);
function State (Button : Button_Id) return Button_State;
Arguments:
- Button : The Id of the button that we want to check. There are two Ids:
Button_AorButton_B.
Return value:
The function State return the Button_State that can be either Pressed or
Released.
Here is the code:
with MicroBit.Display;
with MicroBit.Buttons; use MicroBit.Buttons;
with MicroBit.Time;
procedure Main is
begin
loop
MicroBit.Display.Clear;
if MicroBit.Buttons.State (Button_A) = Pressed then
-- If button A is pressed
-- Display the letter A
MicroBit.Display.Display ('A');
elsif MicroBit.Buttons.State (Button_B) = Pressed then
-- If button B is pressed
-- Display the letter B
MicroBit.Display.Display ('B');
end if;
MicroBit.Time.Delay_Ms (200);
end loop;
end Main;