Code:
'Greg Hunter's picaxe diesel sound installed into Cane Diesel
'output is now from C.0 (pin7)
'uses2.4 GHz RC so needs the speed 'inverted'
' Diesel engine sound - only 6 STEPS !!!!!!
'**lookup table shortened**
'constant "fast idle" when decelerating until speed falls below '60'
' single Horn blast on starting.
' Random doublee horn when running - every 2 mins at max speed, longer times at slower speeds.
' brake exhaust sound on stopping
'assume an analogue voltage on pin1 - 0 to 3.3V =max speed.=160
' 5 stage shift register. bits 4 & 5 EXORed and fed back to input bit
'pin 1 is speed volts input
'pin0 is output to speaker
symbol seed=b0 'shift register
seed=56 'initialize - can be any number except 0 and 255
'53 is slow, 36 is fast, 56 is pulsy fast
'4,9 are fast 5 is pulsy
'b1 unused
symbol speed=b2 'speed volts input 0-3.3
symbol paustime=b3 'timer to determine rate of sound (pause).
'b4 is intermediate value for speed/10
symbol oldspeed=b5
'b6 unused
symbol DECEL=b7
'word 4 is random number for horn timer = bytes b8 & b9
'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
pause 1000 'delay to let capacitor charge and not sound horn on turnon
start:
seed=seed*2 'shift left 1 bit
if bit4=bit5 then eXOR 'do an EXOR
LOW 0
bit0=0
goto motSpeed
eXOR: bit0=1
HIGH 0
bit0=1
MotSpeed:
random w4 'for horn
readadc 1,speed 'read speed into b2 - 15 steps of 'speed'
speed=160-speed 'new for RC - 'inverted'
if oldspeed=0 and speed>0 then Horn1
'if w4>65500 and speed>11 then Horn2 '65500 works every 2mins or so at max speed
if oldspeed>speed then slowing
if oldspeed=speed and decel=1 then slowing
'so must be accelerating or at steady speed but was last accelerating
accel:
DECEL=0
looper:
oldspeed=speed
b4=speed+30/31 '
'table:
lookup b4,(18,10,7,4,2,1,0),paustime 'idle + 6 steps of speed
paus:
pause paustime
goto start
'Horn2:
'sound 0,(57,50)
'pause 200
Horn1:
sound 0,(57,150)
oldspeed=speed
goto looper
slowing:
DECEL=1
'if speed=0 and oldspeed>10 then justStopped 'removed too noisy!!!
if speed<60 THEN looper
paustime=7 'decelerate at higher speeds gives constant 'fast idle'
oldspeed=speed
goto paus
justStopped:
'PAUSE 500
'sound 0,(253,150) 'exhaust brakes sound
'goto looper
I am trying to use parallel tasking and when I add this to the program;
start1:
Low C.4
pause1000
High C.4
goto start1:
The sound output pulse rate changes to a higher frequency.
What I trying to do is have C.4 driving an LED to simulate a rotating beacon light flashing at a constant rate and the diesel sound simulation to respond to the controller.
Seperately both command work but when combined they seem to interfere with each other.
Any suggestions on why this might be happening and ways to overcome it?
Thanks in advance for any help