use buttons for debugging

devel_freefall
Simon Frei 3 years ago
parent 3cf4380c91
commit 13d02a42ee
  1. 57
      ASYD_Safety/Ada_Microbit/examples/MicroBit/jumper/src/main.adb

@ -23,6 +23,7 @@ procedure Main is
FreeFallCounter : Integer;
FreeFallDetectionCycles : Integer;
FreeFallCondition : Boolean;
MotorStarted : Boolean;
Threshold : Axis_Data;
-- IO VARIABLES
@ -30,7 +31,6 @@ procedure Main is
DO_2_Pt : GPIO_Point;
DO_3_Pt : GPIO_Point;
DO_4_Pt : GPIO_Point;
-- DI_Conf_Up : GPIO_Configuration;
DI_Conf_Down : GPIO_Configuration;
@ -39,8 +39,9 @@ begin
-- PROGRAM STARTUP
Console.Put_Line ("Jumper - starting up ..");
FreeFallCondition := False;
MotorStarted := False;
FreeFallCounter := 0;
FreeFallDetectionCycles := 70; -- 70 * 5ms = 350ms
FreeFallDetectionCycles := 100; -- 70 * 5ms = 350ms
Threshold := 150; -- acceleration sensor threshold
-- IO CONFIGURATION
@ -49,10 +50,6 @@ begin
DO_3_Pt := MB_P9;
DO_4_Pt := MB_P16;
-- DI_Conf_Up.Mode := Mode_In;
-- DI_Conf_Up.Resistors := Pull_Up;
-- DI_Conf_Up.Input_Buffer := Input_Buffer_Connect;
-- DI_Conf_Up.Sense := Sense_Disabled;
DI_Conf_Down.Mode := Mode_In;
DI_Conf_Down.Resistors := Pull_Down;
@ -65,19 +62,22 @@ begin
DO_3_Pt.Configure_IO(DI_Conf_Down);
DO_4_Pt.Configure_IO(DI_Conf_Down);
Display.Clear;
loop
if Buttons.State (Button_A) = Pressed then
DO_1_Pt.Set_Pull_Resistor(Pull => HAL.GPIO.Pull_Up);
DO_2_Pt.Set_Pull_Resistor(Pull => HAL.GPIO.Pull_Up);
DO_3_Pt.Set_Pull_Resistor(Pull => HAL.GPIO.Pull_Up);
DO_4_Pt.Set_Pull_Resistor(Pull => HAL.GPIO.Pull_Up);
Display.Clear;
Display.Display ('0');
end if;
if Buttons.State (Button_B) = Pressed then
DO_1_Pt.Set_Pull_Resistor(Pull => HAL.GPIO.Pull_Down);
DO_2_Pt.Set_Pull_Resistor(Pull => HAL.GPIO.Pull_Down);
DO_3_Pt.Set_Pull_Resistor(Pull => HAL.GPIO.Pull_Down);
DO_4_Pt.Set_Pull_Resistor(Pull => HAL.GPIO.Pull_Down);
Display.Clear;
Display.Display ('X');
end if;
@ -109,39 +109,26 @@ begin
end if;
-- Clear the LED matrix
Display.Clear;
--Display.Clear;
-- Check, wether FreeFallCondition was triggered
if FreeFallCondition then
-- set outputs -> motor on
-- DO_1_Pt.Configure_IO(DI_Conf_Up);
-- DO_2_Pt.Configure_IO(DI_Conf_Up);
-- DO_3_Pt.Configure_IO(DI_Conf_Up);
-- DO_4_Pt.Configure_IO(DI_Conf_Up);
-- use function to set pull up
DO_1_Pt.Set_Pull_Resistor(Pull => HAL.GPIO.Pull_Up);
DO_2_Pt.Set_Pull_Resistor(Pull => HAL.GPIO.Pull_Up);
DO_3_Pt.Set_Pull_Resistor(Pull => HAL.GPIO.Pull_Up);
DO_4_Pt.Set_Pull_Resistor(Pull => HAL.GPIO.Pull_Up);
-- maybe timeout and stop motor
-- deep sleep afterwards
Display.Display ('X');
else
Display.Display ('0');
if not MotorStarted then
MotorStarted := True;
-- set outputs -> motor on
DO_1_Pt.Set_Pull_Resistor(Pull => HAL.GPIO.Pull_Up);
DO_2_Pt.Set_Pull_Resistor(Pull => HAL.GPIO.Pull_Up);
DO_3_Pt.Set_Pull_Resistor(Pull => HAL.GPIO.Pull_Up);
DO_4_Pt.Set_Pull_Resistor(Pull => HAL.GPIO.Pull_Up);
-- maybe timeout and stop motor
-- deep sleep afterwards
-- Display.Display ('X');
end if;
-- else
-- Display.Display ('0');
end if;
-- Read analogue pin (could be 0,1,2,3,4, or 10)
-- Value := MicroBit.IOs.Analog (2);
-- Console.Put_Line ("Value : " & Value'Image);
-- Set output
-- if Value > Analog_Value(200) then
-- MicroBit.IOs.Set (12, True);
-- else
-- MicroBit.IOs.Set (12, False);
-- end if;
Time.Sleep (5); -- 200 samples / s
end loop;
end Main;

Loading…
Cancel
Save