Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "FastLED.h"
- #include <Wire.h>
- #include <Adafruit_Sensor.h>
- #include <Adafruit_ADXL345.h>
- int x;
- int y;
- int z;
- int mapx;
- int mapy;
- int mapz;
- int fade = 10;
- #define BRIGHTNESS 255
- int allleds[64] = {
- 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,
- 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
- };
- /* Assign a unique ID to this sensor at the same time */
- Adafruit_ADXL345 accel = Adafruit_ADXL345(12345);
- // How many leds in your strip?
- #define NUM_LEDS 64
- int halfway = NUM_LEDS/2;
- // For led chips like Neopixels, which have a data line, ground, and power, you just
- // need to define DATA_PIN. For led chipsets that are SPI based (four wires - data, clock,
- // ground, and power), like the LPD8806 define both DATA_PIN and CLOCK_PIN
- #define DATA_PIN 13
- #define CLOCK_PIN 11
- // Define the array of leds
- CRGB leds[NUM_LEDS];
- void setup() {
- // Uncomment/edit one of the following lines for your leds arrangement.
- FastLED.addLeds<WS2811, DATA_PIN, GRB>(leds, NUM_LEDS);
- // FastLED.addLeds<LPD8806, DATA_PIN, CLOCK_PIN, RGB>(leds, NUM_LEDS);
- }
- void loop() {
- /* Get a new sensor event */
- sensors_event_t event;
- accel.getEvent(&event);
- // remap the negative -10 to +10 figures to 0-255 range
- mapx = map(event.acceleration.x, -10, 10, 0, 255);
- mapy = map(event.acceleration.y, -10, 10, 0, 255);
- mapz = map(event.acceleration.z, -10, 10, 0, 255);
- for(int i = 0; i < 32; i++) {
- // Set the i'th led to red
- leds[i] = CRGB::Red;
- leds[63 - i] = CRGB::Red;
- // Show the leds
- FastLED.show();
- // now that we've shown the leds, reset the i'th led to black
- leds[i] = CRGB::Black;
- leds[63 - i] = CRGB::Black;
- //leds[i].nscale8(fade);
- //leds[63 - i].nscale8(fade);
- // Wait a little bit before we loop around and do it again
- delay(30);
- }
- // Turn the LED on, then pause
- // leds[0].setRGB(mapx, mapy, mapz);
- // FastLED.show();
- //delay(500);
- // Now turn the LED off, then pause
- //leds[16] = CRGB::Black;
- //FastLED.show();
- // delay(10);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement