-
-
Save sakjur/4dc70bfd58150919a212 to your computer and use it in GitHub Desktop.
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
with adc; | |
with atmega128; | |
with Calendar; | |
with Digital_IO; | |
Procedure Turret is | |
pragma Suppress (All_Checks); | |
sensor : Integer := ADC.get(0); -- Teh all seeing 3y3 | |
ValRem : Boolean := False; | |
shot : Boolean := True; | |
procedure scan (SID: atmega128.Bit_Index) is | |
Value : Integer := 0; | |
begin | |
Digital_IO.Enable_Servo (SID); | |
Digital_IO.Set_Servo (SID, Digital_IO.Servo_Value (Value)); | |
Calendar.Delay_MS (10); | |
-- begin right-left movement | |
if Value >= 125 then | |
ValRem := True; | |
shot := false; -- Resetting letsnotwastebullet-boolean | |
elsif Value <= -125 then | |
ValRem := False; | |
shot := false; -- Resetting letsnotwastebullet-boolean | |
end if; | |
if ValRem then | |
Value := Value - 1; | |
else | |
Value := Value + 1; | |
end if; | |
end scan; | |
procedure shoot (TID: atmega128.Bit_Index) is | |
i : integer := 0; -- Iterator for triggering | |
y : integer := 0; -- Iterator for untriggering | |
begin | |
Digital_IO.Set_Output (TID); | |
Digital_IO.set_pin(TID, False); | |
shot := True; -- Setting letsnotwastebullet-boolean | |
while i < 3 Loop -- Firing | |
Digital_IO.set_pin(TID,True); | |
Calendar.Delay_ms(2); | |
Digital_IO.set_pin(TID,False); | |
Calendar.Delay_ms(20); | |
i := i + 1; | |
End Loop; | |
Calendar.Delay_MS(100); -- Hold down trigger | |
while y < 4 Loop -- Resetting gun state | |
Digital_IO.set_pin(TID,True); | |
Calendar.Delay_ms(1); | |
Digital_IO.set_pin(TID,False); | |
Calendar.Delay_ms(20); | |
y := y + 1; | |
End Loop; | |
Calendar.Delay_ms(400); -- Rest for half a second before returning | |
end shoot; | |
Begin | |
loop -- main loop | |
sensor := ADC.get(0); | |
If (sensor >= 70 and shot = False) Then | |
shoot(6); | |
else | |
scan(7); | |
end if; | |
end loop; | |
End Turret; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment