Fading LED strips with Grove - LED strip driver

Hi guys,

I’m rediscovering Arduino again during working on my graduation project. I want to make a interactive prototype of a lamp I designed. The lamp lights up when the user interacts with it, and increases in brightness when it moves faster. When it doesn’t move any more, the light will fade out. So basically a LED strip reacts on an accelerometer.
My tutor advised me to use a Grove shield, because it makes my job a lot easier. And I have to say it does, I think it is really easy to not work with breadboards etc.

I achieved to let the LED strip light up when the accelerometer moves, by using my basic coding knowledge and combining the code examples and drivers that were provided on the Grove wiki.

[code]#include <Wire.h>
#include <ADXL345.h>

#include “RGBdriver.h”
#define CLK 2//pins definitions for the driver
#define DIO 3
RGBdriver Driver(CLK,DIO);

ADXL345 adxl; //variable adxl is an instance of the ADXL345 library

void setup(){
Serial.begin(9600);
adxl.powerOn();

//set activity/ inactivity thresholds (0-255)
adxl.setActivityThreshold(75); //62.5mg per increment
adxl.setInactivityThreshold(75); //62.5mg per increment
adxl.setTimeInactivity(10); // how many seconds of no activity is inactive?

//look of activity movement on this axes - 1 == on; 0 == off
adxl.setActivityX(1);
adxl.setActivityY(1);
adxl.setActivityZ(1);

//look of inactivity movement on this axes - 1 == on; 0 == off
adxl.setInactivityX(1);
adxl.setInactivityY(1);
adxl.setInactivityZ(1);

//look of tap movement on this axes - 1 == on; 0 == off
adxl.setTapDetectionOnX(0);
adxl.setTapDetectionOnY(0);
adxl.setTapDetectionOnZ(1);

//set values for what is a tap, and what is a double tap (0-255)
adxl.setTapThreshold(50); //62.5mg per increment
adxl.setTapDuration(15); //625us per increment
adxl.setDoubleTapLatency(80); //1.25ms per increment
adxl.setDoubleTapWindow(200); //1.25ms per increment

//set values for what is considered freefall (0-255)
adxl.setFreeFallThreshold(7); //(5 - 9) recommended - 62.5mg per increment
adxl.setFreeFallDuration(45); //(20 - 70) recommended - 5ms per increment

//setting all interrupts to take place on int pin 1
//I had issues with int pin 2, was unable to reset it
adxl.setInterruptMapping( ADXL345_INT_SINGLE_TAP_BIT, ADXL345_INT1_PIN );
adxl.setInterruptMapping( ADXL345_INT_DOUBLE_TAP_BIT, ADXL345_INT1_PIN );
adxl.setInterruptMapping( ADXL345_INT_FREE_FALL_BIT, ADXL345_INT1_PIN );
adxl.setInterruptMapping( ADXL345_INT_ACTIVITY_BIT, ADXL345_INT1_PIN );
adxl.setInterruptMapping( ADXL345_INT_INACTIVITY_BIT, ADXL345_INT1_PIN );

//register interrupt actions - 1 == on; 0 == off
adxl.setInterrupt( ADXL345_INT_SINGLE_TAP_BIT, 1);
adxl.setInterrupt( ADXL345_INT_DOUBLE_TAP_BIT, 1);
adxl.setInterrupt( ADXL345_INT_FREE_FALL_BIT, 1);
adxl.setInterrupt( ADXL345_INT_ACTIVITY_BIT, 1);
adxl.setInterrupt( ADXL345_INT_INACTIVITY_BIT, 1);
}

void loop(){

//Boring accelerometer stuff   
int x,y,z;  
adxl.readXYZ(&x, &y, &z); //read the accelerometer values and store them in variables  x,y,z
// Output x,y,z values 
Serial.print("values of X , Y , Z: ");
Serial.print(x);
Serial.print(" , ");
Serial.print(y);
Serial.print(" , ");
Serial.println(z);

double xyz[3];
double ax,ay,az;
adxl.getAcceleration(xyz);
ax = xyz[0];
ay = xyz[1];
az = xyz[2];
Serial.print("X=");
Serial.print(ax);
Serial.println(" g");
Serial.print("Y=");
Serial.print(ay);
Serial.println(" g");
Serial.print("Z=");
Serial.println(az);
Serial.println(" g");
Serial.println("**********************");
delay(500);

//Fun Stuff!
//read interrupts source and look for triggerd actions

//getInterruptSource clears all triggered actions after returning value
//so do not call again until you need to recheck for triggered actions
byte interrupts = adxl.getInterruptSource();

//inactivity
if(adxl.triggered(interrupts, ADXL345_INACTIVITY)){
Serial.println(“inactivity”);
//add code here to do when inactivity is sensed

Driver.begin(); // begin
Driver.SetColor(0, 0, 0); //hij gaat uit
Driver.end();

}

//activity
if(adxl.triggered(interrupts, ADXL345_ACTIVITY)){
Serial.println(“activity”);
//add code here to do when activity is sensed

Driver.begin(); // begin
Driver.SetColor(0, 255, 0); //Blue. first node data
Driver.end();
delay(500);

}

}[/code]

So basically, I have a few questions.

I want the LED strip to fade in, when activity is noticed (because it looks much nicer). I don’t know what code I should use for that. I tried to combine the code above with a simple fading tutorial, but I get some errors in the analog.Write line. I have the idea that maybe this is not the right command for fading the LED strip? Does anyone know what code I could use here?

[code] //activity
if(adxl.triggered(interrupts, ADXL345_ACTIVITY)){
Serial.println(“activity”);
//add code here to do when activity is sensed

Driver.begin(); // begin
for(int fadeValue = 0 ; fadeValue <= 255; fadeValue +=5) {
analogWrite(Driver.SetColor(0, 255, 0), fadeValue); //Blue. first node data
delay(30);
Driver.end();
delay(500);

 [/code]

I also want it to slowly fade to different colors during activity. Does anyone knows how I can do that or knows a good tutorial for this?

I’m feeling a bit desperate, because I tried a lot of different things and googled my ass off, but I just can’t find the answer…
Thank you :slight_smile: