Reversing beep!

Bundu

New Member
Hi -hope this is the right area to post in anyway:

I've recently built the PIC buggy kit and I am trying tolearn through adapting the sample programme. I want to remove that beep you get when the buggy collides with something and add that annoying reversing beep you get with lorries when it actually reverses/

Code:
led_loop:
let pins = %0000110 'let pins 1 and 2 go high turning both LEDs on
sound 0, (100,50) ' sets piezo tone and length
pause 50 ' pause
let pins = %00000000 'turn LEDs off
pause 50 'pause
goto led_loop
I know enough to be dangerous! So I thought gosub would work but how do I strip this subroutine intothe programme so that it only runs AT THE SAME TIME as the vehicle is reversing and turning? At the moment it just gets to the sub routine and then gets stuck.

If someone could point me in the right direction I would appreciate it. Thanks.

Code:
'Buggy Test Program For PICAXE18 microcontroller
'using [URL="http://www.rev-ed.co.uk"]www.rev-ed.co.uk[/URL] Buggy Kit (CHI007 or MOD001)
'make sure piezo link LK3 is connected for sound to work on pin0!
 
'CPS May 2001
 
'output pin allocation (%76543210)
'76 = motor B
'54 = motor A
'3 = not used 
'2 = LED B
'1 = LED A
'0 = piezo sounder
 
'input pin allocation (v1-4)
'1 = sensor B
'0 = sensor A
'input pin allocation (v5)
'2 = sensor B
'7 = sensor A
 
 
'start going forwards
'testing switches as you go
 
main:
    let pins = %01010000
    if pin2 = 1 then left
    if pin7 = 1 then right
    goto main
 
led_loop:
    let pins = %0000110 'let pins 1 and 2 go high turning both LEDs on
    sound 0, (100,50) ' sets piezo tone and length
    pause 50 ' pause
    let pins = %00000000 'turn LEDs off
    pause 50 'pause
    goto led_loop
 
'left switch hit
'so stop, light LED, beep, reverse, turn 
 
left:
    gosub led_loop
    let pins =%10100000
    pause 2000
    let pins =%10010000
    pause 1500
    goto main
 
'right switch hit
'so stop, light LED, beep, reverse, turn other way
 
right:
    gosub led_loop
    let pins =%10100000
    pause 2000
    let pins =%01100000
 
    pause 1500
    goto main
PS:I am having a problem receiving notifications of posts - I'll keepchecking but please be patient with me. Thank you.
 
Last edited by a moderator:

Technical

Technical Support
Staff member
The code that makes it go backwards is this:

let pins =%10010000
pause 1500

ie switch on outputs 5 and 7 and wait 1.5 seconds.

so to mix with your code
Code:
let pins = %10100110 'let pins 1 and 2 go high turning both LEDs on + motors
for b1 =1 to 15  '15 * (50+50) = 1500
   sound 0, (100,50) ' sets piezo tone and length
   pause 50 ' pause
   let pins = %10100000 'turn LEDs off but leave motors on
   pause 50 'pause
next b1
 

Bundu

New Member
Thanks so much for your input - what I'm looking for is for both the LEDS to flash and the piezo to beep all the way through the reverse and turn. I'm not very experienced with this so I'll have a go again in the morning - thanks again for all your help - may spk tomorrow!
 
Top