HowToMake(almost)
Anything

 

Input Devices

This weeks assignment is to add a sensor input to a microcontroller board and read from it. Since I've already done that a couple of times (assignment 7 and 5), I figured I would just optimize the code a bit.

Flower Wall

Finally having enough time to debug the code properly, I made the following changes:

1. Instead of fastPWM I use phase correct PWM which allows twice the resolution for the servo position.

2. I realized that the flourescent lights in our lab were blinking at around 100Hz causing my ambient lightreading to fluctuate. Now I read 10 times per period and average out my readings. The readings are triggered by timer0 overflow interrupt (just after I turn off my IR emitter).

3.Every 2nd time the compare match interrupt is called (i.e. only on the up-counting cycle), I read the intensity of the IRreceiver, this corresponds to the amount of light reflected from the emitter. By using the interrupt I ensure that I am always reading at the right time.

4. To avoid jitter in the servo I do a running average of the last 10 readings (~0.5seconds).

5. Finally, I cleaned up the code a bit and added two functions that converts IRreadings to distance, and distance to servo_output.

It's starting to look good! :)

Code / Video.