This program assumes that the mines trigger switches are on pins A2 & A3.
When one of the switches is triggered we will either add or remove health from the robot.
The RGB LEDs are connected to Port C:
RED C1
GREEN C2
BLUE C3
The color values for the /color variable are:
The port C values say which port C pin will be on for a given color.
Color no
0 off
1 Red. C1
2 Green C2
3 Blue C3
4 Cyan C2 C3
5 Purple. C1 C3
6 Yellow C1 C2
Program
---
Advanced Mine Program
---
prog_vars =
d/triggers 0
d/health 10
d/trig_result 0
d/flashes 0
d/start_time 0
d/run_time 0
prog_vars.
prog_start =
"Mine Start"
/start_time /uptime
-- Setup the trigger for pin A2 & A3
btp a2 do_boom
btp a3 do_boom
prog_start.
prog_loop =
-- Calc run time
sub /uptime /start_time -> /run_time
-- Check if we are dead >>>>>>>>>>>
any /health <= 0 ->
-- Dead
"XXXXXX WE DIED XXXXX"
repeat 10 -> tg c1|d50
exitprog
enda.
-- Exit
any /triggers > 10 -> exitprog
any /run_time >= 60 -> "Time up"|exitprog
prog_loop.
do_boom =
---
The mine is triggered work out the health or damage.
---
/flashes 0
-- Get a new random number between -6 and 6.
rand -6 6 -> /trig_result
-- Update the health var
add /health /trig_result -> /health
-- Check for negative health, if so flash 4 times.
any /trig_result < 0 -> /flashes 4
inc /triggers
print "Trig /triggers TR /trig_result Health /health flash /flashes"
set_color /health /flashes
do_boom.
set_color /color 0 /led_flash 0 =
---
Colors
0 off
1 Red
2 Green
3 Blue
4 Cyan c2 c3 on
5 Magenta c1 c3
6 . Yellow c1 c2
---
-- All c off
coff
-- Get abs version of color
abs /color -> /color
repeat /led_flash ->
-- Set the color on Port C
ant /color ->
= 1 -> c1 1
= 2 -> c2 1
= 3 -> c3 1
= 4 -> c3 1|c4 1
= 5 -> c1 1|c3 1
= 6 -> c1 1|c2 1
-> c1 1|c2 1
ant.
d250
-- any /led_flash > 2 -> d250
-- any /led_flash < 2 -> d1000
coff
repeat.
set_color.
prog_stop =
print "Bye"
-- clear the buttons
rstb
prog_stop.