|
|
|
@ -23,6 +23,7 @@ procedure Main is |
|
|
|
FreeFallCounter : Integer; |
|
|
|
FreeFallCounter : Integer; |
|
|
|
FreeFallDetectionCycles : Integer; |
|
|
|
FreeFallDetectionCycles : Integer; |
|
|
|
FreeFallCondition : Boolean; |
|
|
|
FreeFallCondition : Boolean; |
|
|
|
|
|
|
|
MotorStarted : Boolean; |
|
|
|
Threshold : Axis_Data; |
|
|
|
Threshold : Axis_Data; |
|
|
|
|
|
|
|
|
|
|
|
-- IO VARIABLES |
|
|
|
-- IO VARIABLES |
|
|
|
@ -30,7 +31,6 @@ procedure Main is |
|
|
|
DO_2_Pt : GPIO_Point; |
|
|
|
DO_2_Pt : GPIO_Point; |
|
|
|
DO_3_Pt : GPIO_Point; |
|
|
|
DO_3_Pt : GPIO_Point; |
|
|
|
DO_4_Pt : GPIO_Point; |
|
|
|
DO_4_Pt : GPIO_Point; |
|
|
|
-- DI_Conf_Up : GPIO_Configuration; |
|
|
|
|
|
|
|
DI_Conf_Down : GPIO_Configuration; |
|
|
|
DI_Conf_Down : GPIO_Configuration; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -39,8 +39,9 @@ begin |
|
|
|
-- PROGRAM STARTUP |
|
|
|
-- PROGRAM STARTUP |
|
|
|
Console.Put_Line ("Jumper - starting up .."); |
|
|
|
Console.Put_Line ("Jumper - starting up .."); |
|
|
|
FreeFallCondition := False; |
|
|
|
FreeFallCondition := False; |
|
|
|
|
|
|
|
MotorStarted := False; |
|
|
|
FreeFallCounter := 0; |
|
|
|
FreeFallCounter := 0; |
|
|
|
FreeFallDetectionCycles := 70; -- 70 * 5ms = 350ms |
|
|
|
FreeFallDetectionCycles := 100; -- 70 * 5ms = 350ms |
|
|
|
Threshold := 150; -- acceleration sensor threshold |
|
|
|
Threshold := 150; -- acceleration sensor threshold |
|
|
|
|
|
|
|
|
|
|
|
-- IO CONFIGURATION |
|
|
|
-- IO CONFIGURATION |
|
|
|
@ -49,10 +50,6 @@ begin |
|
|
|
DO_3_Pt := MB_P9; |
|
|
|
DO_3_Pt := MB_P9; |
|
|
|
DO_4_Pt := MB_P16; |
|
|
|
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.Mode := Mode_In; |
|
|
|
DI_Conf_Down.Resistors := Pull_Down; |
|
|
|
DI_Conf_Down.Resistors := Pull_Down; |
|
|
|
@ -65,19 +62,22 @@ begin |
|
|
|
DO_3_Pt.Configure_IO(DI_Conf_Down); |
|
|
|
DO_3_Pt.Configure_IO(DI_Conf_Down); |
|
|
|
DO_4_Pt.Configure_IO(DI_Conf_Down); |
|
|
|
DO_4_Pt.Configure_IO(DI_Conf_Down); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Display.Clear; |
|
|
|
loop |
|
|
|
loop |
|
|
|
|
|
|
|
|
|
|
|
if Buttons.State (Button_A) = Pressed then |
|
|
|
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_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); |
|
|
|
DO_4_Pt.Set_Pull_Resistor(Pull => HAL.GPIO.Pull_Up); |
|
|
|
|
|
|
|
Display.Clear; |
|
|
|
|
|
|
|
Display.Display ('0'); |
|
|
|
end if; |
|
|
|
end if; |
|
|
|
if Buttons.State (Button_B) = Pressed then |
|
|
|
if Buttons.State (Button_B) = Pressed then |
|
|
|
DO_1_Pt.Set_Pull_Resistor(Pull => HAL.GPIO.Pull_Down); |
|
|
|
DO_1_Pt.Set_Pull_Resistor(Pull => HAL.GPIO.Pull_Down); |
|
|
|
DO_2_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_3_Pt.Set_Pull_Resistor(Pull => HAL.GPIO.Pull_Down); |
|
|
|
DO_4_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; |
|
|
|
end if; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -109,39 +109,26 @@ begin |
|
|
|
end if; |
|
|
|
end if; |
|
|
|
|
|
|
|
|
|
|
|
-- Clear the LED matrix |
|
|
|
-- Clear the LED matrix |
|
|
|
Display.Clear; |
|
|
|
--Display.Clear; |
|
|
|
|
|
|
|
|
|
|
|
-- Check, wether FreeFallCondition was triggered |
|
|
|
-- Check, wether FreeFallCondition was triggered |
|
|
|
if FreeFallCondition then |
|
|
|
if FreeFallCondition then |
|
|
|
-- set outputs -> motor on |
|
|
|
if not MotorStarted then |
|
|
|
-- DO_1_Pt.Configure_IO(DI_Conf_Up); |
|
|
|
MotorStarted := True; |
|
|
|
-- DO_2_Pt.Configure_IO(DI_Conf_Up); |
|
|
|
-- set outputs -> motor on |
|
|
|
-- DO_3_Pt.Configure_IO(DI_Conf_Up); |
|
|
|
DO_1_Pt.Set_Pull_Resistor(Pull => HAL.GPIO.Pull_Up); |
|
|
|
-- DO_4_Pt.Configure_IO(DI_Conf_Up); |
|
|
|
DO_2_Pt.Set_Pull_Resistor(Pull => HAL.GPIO.Pull_Up); |
|
|
|
-- use function to set pull up |
|
|
|
DO_3_Pt.Set_Pull_Resistor(Pull => HAL.GPIO.Pull_Up); |
|
|
|
DO_1_Pt.Set_Pull_Resistor(Pull => HAL.GPIO.Pull_Up); |
|
|
|
DO_4_Pt.Set_Pull_Resistor(Pull => HAL.GPIO.Pull_Up); |
|
|
|
DO_2_Pt.Set_Pull_Resistor(Pull => HAL.GPIO.Pull_Up); |
|
|
|
-- maybe timeout and stop motor |
|
|
|
DO_3_Pt.Set_Pull_Resistor(Pull => HAL.GPIO.Pull_Up); |
|
|
|
-- deep sleep afterwards |
|
|
|
DO_4_Pt.Set_Pull_Resistor(Pull => HAL.GPIO.Pull_Up); |
|
|
|
-- Display.Display ('X'); |
|
|
|
-- maybe timeout and stop motor |
|
|
|
end if; |
|
|
|
-- deep sleep afterwards |
|
|
|
-- else |
|
|
|
Display.Display ('X'); |
|
|
|
-- Display.Display ('0'); |
|
|
|
else |
|
|
|
|
|
|
|
Display.Display ('0'); |
|
|
|
|
|
|
|
end if; |
|
|
|
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 |
|
|
|
Time.Sleep (5); -- 200 samples / s |
|
|
|
end loop; |
|
|
|
end loop; |
|
|
|
end Main; |
|
|
|
end Main; |
|
|
|
|