Accelerometer data to RGB
2020-Jul-25, Saturday 01:30 pmThe LilyPad Accelerometer (ADXL335). I've been trying to use this for over ten years. Turns out I've misunderstood what it measures for 10 years. I had partial success with just the x-axis using Leah Buechley's code, but it has since disappeared, so I can't even be sure what it did.
I was trying to do something else, and the numbers, very strangely kept coming out to an exact 100.0, which is very wrong. So I went back to make sure the accelerometer was giving me a full value range. Which it didn't seem to be, so I went researching and found this excellent tutorial.
Although the accelerometer gives you raw values between 0 and 1023 on an analog read, it actually measures gravity acting on it as it moves around in 3D space. Converting the raw to Gs is straight-forward;
To then turn this into a colour, simply, you could map the range onto -255 to +255 (the polarity demonstrating direction of change), and then reducing that to just value of change;
Do the same for the y and z. Write to RGB LED/pixel of your choice. (Warning; movement in video is quite sudden.)
( Short video )
Sorry for the rough prototype version, I dismantled the version I made up for parts to make my tiara.
Other than light-up gloves, this could be used for rough gesture control, but doesn't give me the kind of information I needed for the thing I was trying to do as is.
I was trying to do something else, and the numbers, very strangely kept coming out to an exact 100.0, which is very wrong. So I went back to make sure the accelerometer was giving me a full value range. Which it didn't seem to be, so I went researching and found this excellent tutorial.
Although the accelerometer gives you raw values between 0 and 1023 on an analog read, it actually measures gravity acting on it as it moves around in 3D space. Converting the raw to Gs is straight-forward;
long xAcceleration = map(xRawPinValue, 0, 1023, -3.0, 3.0);To then turn this into a colour, simply, you could map the range onto -255 to +255 (the polarity demonstrating direction of change), and then reducing that to just value of change;
int xRed = map(xAcceleration, -3.0, 3.0, -255, 255);
int absoluteXRed = abs(xRed);Do the same for the y and z. Write to RGB LED/pixel of your choice. (Warning; movement in video is quite sudden.)
( Short video )
Sorry for the rough prototype version, I dismantled the version I made up for parts to make my tiara.
Other than light-up gloves, this could be used for rough gesture control, but doesn't give me the kind of information I needed for the thing I was trying to do as is.


