chebe: (Default)
[personal profile] chebe
My Lilypad is now aware! It actually does something in response to changes it detects! I can't take the glory, I simply used the code from the project that inspired mine: Leah Buechley's accelerometer shirt.

Interesting things about this code:

Number 1: It only uses the data from the x-axis of the accelerometer, so as of yet y and z are unused.

Number 2: There is a fair bit of extra code included that isn't used. It looks like the first steps to a more complicated program. Some of my favourite, on the contrary, looks almost like test code: cycleColors(). It simply cycles the led through all the colours, regardless of input.

Number 3: It creates a function called setGradient() that normalises the range of your input (0-1023) so it can map more cleanly and more fully to the range of output/colour (0-255). It's basically divides by four, but then keeps the values as the endpoints, so to speak; for low, middle, and high. What one would think should be 0, ~123 and 255, but in reality aren't. You have to initialise this function with the lowest and highest values your accelerometer gives you, as well as an average. This requires some lab-work. Hook up the glove to the computer, and simply have it output values as you twist and turn the glove in all directions. Find the highest and lowest, and then find the average of all the values. This does mean that you have to recalibrate the code every time you use a different accelerometer, but it's the only way to get good results.

Number 4: The code has a bug. When I first tried to use this code my glove always displayed blue, occasionally flashing red. The bug is in the simpleColor() function at the line:
else
    new_sensor_value = new_sensor_value/4;


It should read:
else
    new_sensor_value = sensor_value/4;


Otherwise the value will always be 0, which is why it stayed blue for me.

(I tried to find contact information for Leah Buechley to let her know so it could be fixed, but it seems like she doesn't want to be contacted by random people from the internet. So, if you have some way of reaching her, please let her know. She mightn't have the time to do anything about it, but if I was her I'd want to know.)


The Result:




Also, there is a newer version of the Arduino IDE available, 17, that fixes the bug I mentioned in a previous post about how the Lilypad was using the wrong baud rate to communicate back to the computer. So now if you set it at 9600, it actually uses 9600. This makes me happy.

Next step? Using data from the 3-axes!

Date: 2010-01-08 07:57 am (UTC)
foxfirefey: Dreamwidth: social content with dimension. (dreamwidth)
From: [personal profile] foxfirefey
Ooooh, this is kinda awesome, can I post about it to [community profile] dreamlight?
Page generated 2017-Apr-29, Saturday 07:28 am
Powered by Dreamwidth Studios