Technology: Art and Sound by Design
[[ultra]]
Last edit on
Apr 24, 2006
10:43 PM
by dagentooboy
full code
Parallax ultrasonic sensor code
Here is the same code we used in class only I made some additions to make it more accurate here are the changes....
I changed getave to set total_val to the current sensor reading. I also made it so that it averages each new value in as it gets it.
to getave
settotal_val (getvalue_SRF05) ; set total_val to the current distance value repeat 8 [ ; get 8 readings settotal_val (((total_val) + getvalue_SRF05 / 2)) wait 1 ] output total_val ; return averageend
I also changed getvalue_SRF05 so that the value back from the sensor doesn't get to large for the variables by dividing it by 100.
to getvalue_SRF05
clearbit 2 PIR1 ; reset to trigger next event on C2 setn (((read TMR3H) * 256) + (read TMR3L)) ; get current timer 3 value setbit 7 portb clearbit 7 portb ; trigger SRF05 for reading waituntil [testbit 2 PIR1] ; have we got event on C2 yet? setm (((read CCPR1H) * 256) + (read CCPR1L)) ; what was value of timer 3 at time of event on C2? output ((m - n) / 100) ; return the time it took for the event to occur divided by 100end
Right now it is set so that it will run the averaging on power up and if you push the start button it will switch over to a real-time reading.
I don't know how this will work with three sensors but we are well on our way.... the vibrating motors shouldn't be to hard to add in to the code later.