Skip to content

Instantly share code, notes, and snippets.

@sakjur
Created May 23, 2013 16:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sakjur/4dc70bfd58150919a212 to your computer and use it in GitHub Desktop.
Save sakjur/4dc70bfd58150919a212 to your computer and use it in GitHub Desktop.
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