a funy bracelet
Dependencies: ADXL345_I2C PololuLedStrip USBDevice mbed
Fork of xadow_m0_accelerometer by
Revision 1:daff562098ac, committed 2014-07-21
- Comitter:
- jacob_yan
- Date:
- Mon Jul 21 07:19:43 2014 +0000
- Parent:
- 0:b017c907d53d
- Child:
- 2:efc5c7e8c1a9
- Commit message:
- n
Changed in this revision
| PololuLedStrip.lib | Show annotated file Show diff for this revision Revisions of this file |
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PololuLedStrip.lib Mon Jul 21 07:19:43 2014 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/DavidEGrayson/code/PololuLedStrip/#87fd6273e0ff
--- a/main.cpp Wed Jun 18 11:03:59 2014 +0000
+++ b/main.cpp Mon Jul 21 07:19:43 2014 +0000
@@ -1,4 +1,6 @@
#include "ADXL345_I2C.h"
+#include "mbed.h"
+#include "PololuLedStrip.h"
#define DEBUG
@@ -9,33 +11,90 @@
#else
#define LOG(args...)
#endif
+PololuLedStrip ledStrip(P0_8);
+ADXL345_I2C accelerometer(P0_5, P0_4);
-ADXL345_I2C accelerometer(P0_5, P0_4);
+
+#define LED_COUNT 6
+rgb_color colors[LED_COUNT];
+Timer timer;
+rgb_color color;
+
+DigitalOut led_white(P0_23);
+DigitalOut led_blue(P0_20);
+DigitalOut led_strip(P0_8);
+int x,y,z,val;
+
+rgb_color hsvToRgb(float h, float s, float v) //claim object hsvToRbg
+{
+ int i = floor(h * 6);
+ float f = h * 6 - i;
+ float p = v * (1 - s);
+ float q = v * (1 - f * s);
+ float t = v * (1 - (1 - f) * s);
+ float r = 0, g = 0, b = 0;
+ switch(i % 6){
+ case 0: r = v; g = t; b = p; break;
+ case 1: r = q; g = v; b = p; break;
+ case 2: r = p; g = v; b = t; break;
+ case 3: r = p; g = q; b = v; break;
+ case 4: r = t; g = p; b = v; break;
+ case 5: r = v; g = p; b = q; break;
+ }
+ return (rgb_color){r * 255, g * 255, b * 255};
+}
int main()
{
+
+
+ led_white=0;
+ led_blue=0;
+
int readings[3] = {0, 0, 0};
- LOG("Starting ADXL345 test...\n");
- LOG("Device ID is: 0x%02x\n", accelerometer.getDeviceID());
-
- //Go into standby mode to configure the device.
accelerometer.setPowerControl(0x00);
-
- //Full resolution, +/-16g, 4mg/LSB.
accelerometer.setDataFormatControl(0x0B);
-
- //3.2kHz data rate.
accelerometer.setDataRate(ADXL345_3200HZ);
-
- //Measurement mode.
accelerometer.setPowerControl(0x08);
while (1) {
accelerometer.getOutput(readings);
- LOG("%i, %i, %i\n", (int16_t)readings[0], (int16_t)readings[1], (int16_t)readings[2]);
+
+ x=abs((int16_t)readings[2]);
+ y=abs((int16_t)readings[2]);
+ z=abs((int16_t)readings[2]);
- wait(1);
+ val=x;
+ if (val<y)val=y;
+ if (val<z)val=z;
+ if (val>1100)val=1100;
+
+ if (val>300)
+ {
+
+ color.red =0;
+ color.green = char((val-300)*255/800);
+ color.blue = 0;
+
+
+ for(uint16_t i = 0; i < LED_COUNT; i++)
+ {
+ colors[i] = color;
+ }
+
+ ledStrip.write(colors, LED_COUNT);
+ wait_ms (100);
+ }
+
+ else{
+
+ rgb_color colors[LED_COUNT]={};
+ ledStrip.write(colors, LED_COUNT);
+
+ }
+
+
}
}
