-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This only works for the V1.3B Microbit (assumes accelerometer is MMA8653). * test-microbit/Makefile: add accelerometer. * test-microbit/README.md: likewise. * test-microbit/tests.gpr: likewise. * test-microbit/accelerometer.adb: new.
- Loading branch information
1 parent
f7afb32
commit d537c4c
Showing
4 changed files
with
58 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
with MMA8653; | ||
with MicroBit.I2C; | ||
with LEDs; | ||
with Ada.Real_Time; | ||
|
||
procedure Accelerometer is | ||
Acc : MMA8653.MMA8653_Accelerometer (Port => MicroBit.I2C.Controller); | ||
begin | ||
if not MicroBit.I2C.Initialized then | ||
MicroBit.I2C.Initialize (S => MicroBit.I2C.S400kbps); | ||
end if; | ||
|
||
if not Acc.Check_Device_Id then | ||
for R in LEDs.Coord'Range loop | ||
for C in LEDs.Coord'Range loop | ||
LEDs.Set_One_LED (R, C); | ||
end loop; | ||
end loop; | ||
delay until Ada.Real_Time.Time_Last; | ||
end if; | ||
|
||
Acc.Configure (MMA8653.Two_G, | ||
MMA8653.High_Resolution, | ||
MMA8653.High_Resolution); | ||
|
||
loop | ||
declare | ||
Detection_Limit : constant := 75; | ||
Data : constant MMA8653.All_Axes_Data := Acc.Read_Data; | ||
use type MMA8653.Axis_Data; | ||
use type Ada.Real_Time.Time; | ||
begin | ||
LEDs.Clear_All_LEDs; | ||
if Data.X > Detection_Limit then | ||
LEDs.Set_One_LED (3, 1); | ||
elsif Data.X < -Detection_Limit then | ||
LEDs.Set_One_LED (3, 5); | ||
elsif Data.Y > Detection_Limit then | ||
LEDs.Set_One_LED (1, 3); | ||
elsif Data.Y < -Detection_Limit then | ||
LEDs.Set_One_LED (5, 3); | ||
else | ||
LEDs.Set_One_LED (3, 3); | ||
end if; | ||
delay until Ada.Real_Time.Clock + Ada.Real_Time.Milliseconds (100); | ||
end; | ||
end loop; | ||
end Accelerometer; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters