So I guess use your imagination? Basically what happens is that the rainbow pattern in the eyes changes as distance detected by the ping sensor varies.
This is not practical for much, if anything. But it is a cool demo and will probably entertain my infant child for hours once she's old enough to sit upright on her own.
Here's the code:
https://github.com/meatheadmike/kaleidoscope_ping_sensor_demo
As you can see I set up a buffer of 20 distance readings and then average the result. This makes the pattern changes a lot smoother than without the buffer. It can get quite flickery without.
An interesting observation that I came across while playing with this... Occasionally when you get too close to the sensor it would miss a reading. This would cause the code to get stuck on a while loop. So I added a simple timeout as you can see here:
while GPIO.input(PING_ECHO) == 0 and signaloff-start < 0.1: |
So if 0.1 seconds elapses, then we move along. This solved the problem for me. When I implement the ping sensor for my bump-and-go functionality on Robie, this won't be a concern (hopefully). I'm planning on using interrupt logic instead of a while loop. As always, I'll post my findings...
No comments:
Post a Comment