//B.R.E.A.T.H.E //Final Project. Fab Academy 2021 //Lorena Delgado Piña //Fab Lab León + Fab Lab IED Madrid //Accelerometer + Neopixels #include #include #include ADXL345 adxl = ADXL345(); //accelerometer values int xposition0 = -32; int xposition1 = -14; int xposition2 = 25; int xposition3 = -28; int margin = 1; //neopixels definition //#include #include #define PIN 1 // Parameter 1 = number of pixels in strip // Parameter 2 = Arduino pin number (most are valid) // Parameter 3 = pixel type // NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products) // NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2) // NEO_RGBW Pixels are wired for RGBW bitstream (NeoPixel RGBW products) tinyNeoPixel strip = tinyNeoPixel(3, PIN, NEO_GRB + NEO_KHZ800); //Adafruit_NeoPixel strip = Adafruit_NeoPixel(3, PIN, NEO_GRB + NEO_KHZ800); void setup() { //accelerometer Serial.begin(9600); Serial.println("Begin"); Serial.println(); adxl.powerOn(); adxl.setRangeSetting(16); //Define the range, values 2, 4, 8 o 16 //neopixels strip.begin(); } void loop() { //read the values and print it int x, y, z; adxl.readAccel(&x, &y, &z); //If the accelerometer values coincides with the zero position, the neopixels light red) Serial.println(x); if (x > xposition0 - margin && x < xposition0 + margin){ strip.setPixelColor(0, 255, 0, 0); //light red definition at zero position on the first neopixel strip.setPixelColor(1, 255, 0, 0); //light red definition at zero position on the second neopixel strip.setPixelColor(2, 255, 0, 0); //light red definition at zero position on the third neopixel } else { if (x > xposition1 - margin && x < xposition1 + margin){ strip.setPixelColor(0, 255, 0, 255); //light magenta definition at first position on the first neopixel strip.setPixelColor(1, 255, 0, 255); //light magenta definition at first position on the second neopixel strip.setPixelColor(2, 255, 0, 255); //light magenta definition at first position on the third neopixel }else { if (x > xposition2 - margin && x < xposition2 + margin){ strip.setPixelColor(0, 0, 255, 0); //light green definition at first position on the first neopixel strip.setPixelColor(1, 0, 255, 0); //light green definition at first position on the second neopixel strip.setPixelColor(2, 0, 255, 0); //light green definition at first position on the third neopixel }else { if (x > xposition3 - margin && x < xposition3 + margin){ strip.setPixelColor(0, 0, 0, 255); //light blue definition at first position on the first neopixel strip.setPixelColor(1, 0, 0, 255); //light blue definition at first position on the second neopixel strip.setPixelColor(2, 0, 0, 255); //light blue definition at first position on the third neopixel }else { strip.setPixelColor(0, 0, 0, 0); //off definition at zero position on the first neopixel strip.setPixelColor(0, 0, 0, 0); //off definition at zero position on the second neopixel strip.setPixelColor(0, 0, 0, 0); //off definition at zero position on the third neopixel } } } } strip.show(); //Switch on the leds with the define colors delay(500); }