Week 9: Output Devices

Group Assignment

Group assignment answers can be found here: Group Assignments

LED as Output

This week, our assignment was to put an output device on our board and program it to do something. I continued with the accelerometer from last week as my input device. Working toward my final project, this week I wanted to use input from the accelerometer to send output to an LED. The idea is to have the LED turn on and off when it senses that the accelerometer has moved (ie. if the lamp is tapped, the light will turn on/off). It took me a bit of time to figure out the format of the accelerometer output. In the beginning, I also started to look into calibration of the accelerometer because I thought it might be necessary, however Anthony made a good point that I didn't need to care about the absolute values, but rather the change. For the accelerometer programming, I used an Adafruit library. After a bit of debugging, I got the code to work!




At first when I ran it, tapping the accelerometer once would turn the LED on, but then the next time I tapped to turn it off, it would turn back on after one second. I realized I had forgotten to reset and re-read the accelerometer values in between my two loops, so it would automatically enter the loop to turn the LED back on. Once this was fixed, I got the light to turn on and off pretty consistently by tapping the accelerometer.

I was hoping to also play around a bit with different LED brightnesses that I could cycle through. I haven't had a chance to do so yet, but will definitely be doing so later as it will likely be a feature of my final project as well.
Also just in terms of changes I want to make to the code, currently it is based off of absolute acceleration measures, however I'll change it so that it instead looks at the change in accelerometer readings compared to previous readings. This way, it doesn't matter if the values are wrong in some way shape or form as long as they are wrong in a consistent way.
Lessons Learned: make sure to pay attention to resetting values that are set in code