This version of the bumper robot has a smart RGB LED strip fitted with 5 LEDs.
There is a front and back bumper connected to pins a1 and a2 respectively.
If the front bumper is triggered the robot will move backwards and the LEDs will start to flash from the front to the back indicating that the robot is moving backwards.
If the back bumper is triggered the robot will start to move forward and the LEDs will flash from the back to the front to indicate the change in direction.
Program
---
Bumper Robot Program V2
---
prog_vars =
-- Keep track of the number of bumps.
d/front 0
d/back 0
-- Track to no of times we have run.
d/count 0
d/speed 0
-- Direction timer
d/dir_timer 0
d/dir 0
d/total_leds 5
d/led_no 0
d/red 0
d/green 0
d/blue 0
prog_vars.
prog_start =
print "Bumper Robot Program Setup"
-- Reset the buttons
rstb
-- Setup the front bumper.
-- Go back and turn left.
btp c1 front_bump
btp c2 back_bump
bms 50
sledn 10
sledoff
prog_start.
prog_loop =
-- main program loop
-- Increase the /count by 1
inc /count
/speed /150
-- Change dirtection if it gets stuck.
any /dir_timer > 400 ->
/dir_timer 0
tgdir
enda.
-- Set each color to a random value
-- rand 0 255 -> /red
-- rand 0 0 -> /green
-- rand 0 255 -> /blue
all /dir = 0 /led_no < 7 -> inc /led_no
all /dir = 0 /led_no >= 7 -> /led_no 0
all /dir = 1 /led_no >= 1 -> dec /led_no
all /dir = 1 /led_no <= 0 -> /led_no 7
-- "dir /dir /led_no"
sled /led_no /red /green /blue
prog_loop.
front_bump =
-- Task for front bumper
-- Set each color to a random value
rand 0 0 -> /red
rand 0 255 -> /green
rand 0 0 -> /blue
bms -50
lms -10
d500
lms -50
inc /front
/dir_timer 0
/dir 1
front_bump.
back_bump =
-- Task for the back bumper
rand 0 255 -> /red
rand 0 0 -> /green
rand 0 0 -> /blue
bms 50
rms 10
d500
rms 50
inc /back
/dir_timer 0
/dir 0
back_bump.
prog_stop =
print "Bye Front /front Back /back"
-- Clear the buttons
rstb
-- Stop the robot
stop
prog_stop.