Advertisement
KelvinMead

FastLed ADXL345

Dec 20th, 2014
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.29 KB | None | 0 0
  1. #include "FastLED.h"
  2. #include <Wire.h>
  3. #include <Adafruit_Sensor.h>
  4. #include <Adafruit_ADXL345.h>
  5.  
  6. int x;
  7. int y;
  8. int z;
  9. int mapx;
  10. int mapy;
  11. int mapz;
  12. int fade = 10;
  13.  
  14. #define BRIGHTNESS 255
  15.  
  16. int allleds[64] = {
  17. 0, 33, 1, 34, 2, 35, 3, 36, 4, 37, 5, 38, 6, 39, 7, 40, 8, 41, 9, 42, 10, 43, 11, 44, 12, 45, 13, 46, 14, 47, 15, 48,
  18. 16, 49, 17, 50, 18, 51, 19, 52, 20, 53, 21, 54, 22, 55, 23, 56, 24, 57, 25, 58, 26, 59, 27, 60, 28, 61, 29, 62, 30, 63, 31, 64
  19. };
  20.  
  21.  
  22. /* Assign a unique ID to this sensor at the same time */
  23. Adafruit_ADXL345 accel = Adafruit_ADXL345(12345);
  24.  
  25. // How many leds in your strip?
  26. #define NUM_LEDS 64
  27. int halfway = NUM_LEDS/2;
  28.  
  29. // For led chips like Neopixels, which have a data line, ground, and power, you just
  30. // need to define DATA_PIN. For led chipsets that are SPI based (four wires - data, clock,
  31. // ground, and power), like the LPD8806 define both DATA_PIN and CLOCK_PIN
  32. #define DATA_PIN 13
  33. #define CLOCK_PIN 11
  34.  
  35. // Define the array of leds
  36. CRGB leds[NUM_LEDS];
  37.  
  38. void setup() {
  39. // Uncomment/edit one of the following lines for your leds arrangement.
  40. FastLED.addLeds<WS2811, DATA_PIN, GRB>(leds, NUM_LEDS);
  41. // FastLED.addLeds<LPD8806, DATA_PIN, CLOCK_PIN, RGB>(leds, NUM_LEDS);
  42. }
  43.  
  44. void loop() {
  45. /* Get a new sensor event */
  46. sensors_event_t event;
  47. accel.getEvent(&event);
  48. // remap the negative -10 to +10 figures to 0-255 range
  49. mapx = map(event.acceleration.x, -10, 10, 0, 255);
  50. mapy = map(event.acceleration.y, -10, 10, 0, 255);
  51. mapz = map(event.acceleration.z, -10, 10, 0, 255);
  52.  
  53. for(int i = 0; i < 32; i++) {
  54. // Set the i'th led to red
  55. leds[i] = CRGB::Red;
  56. leds[63 - i] = CRGB::Red;
  57. // Show the leds
  58. FastLED.show();
  59. // now that we've shown the leds, reset the i'th led to black
  60. leds[i] = CRGB::Black;
  61. leds[63 - i] = CRGB::Black;
  62. //leds[i].nscale8(fade);
  63. //leds[63 - i].nscale8(fade);
  64. // Wait a little bit before we loop around and do it again
  65. delay(30);
  66. }
  67.  
  68.  
  69. // Turn the LED on, then pause
  70.  
  71.  
  72.  
  73.  
  74.  
  75. // leds[0].setRGB(mapx, mapy, mapz);
  76. // FastLED.show();
  77. //delay(500);
  78. // Now turn the LED off, then pause
  79. //leds[16] = CRGB::Black;
  80. //FastLED.show();
  81. // delay(10);
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement