Grumpy_Mike:
A lot of people look at this forum on mobile devices and they can’t cope with .ino files that is why we have other ways of posting your code. Please read the how to use this forum sticky post to see how.
If the code works for a day it is unlikely to be a problem with your code and more likely to be a hardware problem, possibly one of some interference pickup. Can you post a schematic of your circuit and a photograph of the wiring. If there is a Solderless bread board involved that is also likely to be a problem, otherwise it is probably a lack of sufficient supply decoupling.
Thank you for the insight Mike. I understand, I read the sticky first and I would've posted the code directly in the post but it stated it was too large to fit (over 9000), probably because of all the comments (and likely unnecessary code).
I removed some comments so I could paste the code now:
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_TSL2561_U.h>
#include <SPI.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
/***** LED-STRIP ******/
#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
#include <avr/power.h>
#endif
#define PIN 5
#define NUM_LEDS 100
Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUM_LEDS, PIN, NEO_GRB + NEO_KHZ400);
/***********************/
#define OLED_RESET 4
Adafruit_SSD1306 display(OLED_RESET);
#define NUMFLAKES 10
#define XPOS 0
#define YPOS 1
#define DELTAY 2
#define LOGO16_GLCD_HEIGHT 16
#define LOGO16_GLCD_WIDTH 16
static const unsigned char PROGMEM logo16_glcd_bmp[] =
{ B00000000, B11000000,
B00000001, B11000000,
B00000001, B11000000,
B00000011, B11100000,
B11110011, B11100000,
B11111110, B11111000,
B01111110, B11111111,
B00110011, B10011111,
B00011111, B11111100,
B00001101, B01110000,
B00011011, B10100000,
B00111111, B11100000,
B00111111, B11110000,
B01111100, B11110000,
B01110000, B01110000,
B00000000, B00110000 };
#if (SSD1306_LCDHEIGHT != 32)
#error("Height incorrect, please fix Adafruit_SSD1306.h!");
#endif
Adafruit_TSL2561_Unified tsl = Adafruit_TSL2561_Unified(TSL2561_ADDR_FLOAT, 12345);
/**************************************************************************/
/*
Configures the gain and integration time for the TSL2561
*/
/**************************************************************************/
void configureSensor(void) {
/* You can also manually set the gain or enable auto-gain support */
// tsl.setGain(TSL2561_GAIN_1X); /* No gain ... use in bright light to avoid sensor saturation */
// tsl.setGain(TSL2561_GAIN_16X); /* 16x gain ... use in low light to boost sensitivity */
tsl.enableAutoRange(true); /* Auto-gain ... switches automatically between 1x and 16x */
/* Changing the integration time gives you better sensor resolution (402ms = 16-bit data) */
tsl.setIntegrationTime(TSL2561_INTEGRATIONTIME_13MS); /* fast but low resolution */
// tsl.setIntegrationTime(TSL2561_INTEGRATIONTIME_101MS); /* medium resolution and speed */
// tsl.setIntegrationTime(TSL2561_INTEGRATIONTIME_402MS); /* 16-bit data but slowest conversions */
/* Update these values depending on what you've set above! */
Serial.println("------------------------------------");
Serial.print ("Gain: "); Serial.println("Auto");
Serial.print ("Timing: "); Serial.println("13 ms");
Serial.println("------------------------------------");
}
void setup(void) {
Serial.begin(9600);
Serial.println("Light Sensor Test"); Serial.println("");
/* Display some basic information on this sensor */
//displaySensorDetails();
/* Setup the sensor gain and integration time */
configureSensor();
// by default, we'll generate the high voltage from the 3.3v line internally! (neat!)
display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // initialize with the I2C addr 0x3C (for the 128x32)
// init done
// Show image buffer on the display hardware.
// Since the buffer is intialized with an Adafruit splashscreen
// internally, this will display the splashscreen.
display.display();
delay(1000);
// Clear the buffer.
display.clearDisplay();
display.setTextSize(1);
display.setCursor(0, 0);
display.setTextColor(WHITE);
strip.begin();
strip.show(); // Initialize all pixels to 'off'
delay(500);
}
/**************************************************************************/
/*
Arduino loop function, called once 'setup' is complete (your own code
should go here)
*/
/**************************************************************************/
void loop(void)
{
uint16_t broadband = 0;
uint16_t infrared = 0;
/* Get a new sensor event */
sensors_event_t event;
tsl.getEvent(&event);
/* Populate broadband and infrared with the latest values */
tsl.getLuminosity (&broadband, &infrared);
/* Display the results (light is measured in lux) */
if (event.light) {
Serial.print(event.light); Serial.println(" lux");
Serial.print(infrared); Serial.println(" ir");
Serial.print(broadband); Serial.println(" bb");
fadeColor (event.light);
}
else {
//we dont have any info, lets fade to black
/* If event.light = 0 lux the sensor is probably saturated
and no reliable data could be generated! */
Serial.println("Sensor blocked or 0 lux");
colorWipe(0, 0, 0, 10); // Fade to black
}
delay(200);
display.setCursor(0, 0);
display.print("LUX: ");
display.println(event.light);
display.print("IR: ");
display.println(infrared);
display.print("BB: ");
display.println(broadband);
display.display();
delay(30);
display.clearDisplay();
}
void fadeColor (int luxval) {
if (luxval >= 110.00 and luxval <= 130.00) {
Serial.print ("fading to goodmorning_6 :");
Serial.println (luxval);
colorWipe(35, 0, 12, 10); // Y3
} else if (luxval >= 90 and luxval < 110.00) {
Serial.print ("fading to goodmorning_5 :");
Serial.println (luxval);
colorWipe(30, 0, 10, 10); // Y3
} else if (luxval >= 70 and luxval < 90) {
Serial.print ("fading to goodmorning_4 :");
Serial.println (luxval);
colorWipe(25, 0, 8, 10); // Y3
} else if (luxval >= 50 and luxval < 70) {
Serial.print ("fading to goodmorning_3 :");
Serial.println (luxval);
colorWipe(20, 0, 6, 10); // Y3
} else if (luxval >= 30 and luxval < 50) {
Serial.print ("fading to goodmorning_2 :");
Serial.println (luxval);
colorWipe(15, 0, 4, 100); // Y2
} else if (luxval >= 10 and luxval < 30) {
Serial.print ("fading to goodmorning_1 :");
Serial.println (luxval);
colorWipe(10, 0, 2, 200); // Y1
} else if (luxval >= 6 and luxval < 10) {
Serial.print ("fading to goodmorning_0 :");
Serial.println (luxval);
colorWipe(5, 0, 1, 300); // Y0
} else if (luxval >= 3 and luxval < 6) {
Serial.print ("fading to goodmorning :");
Serial.println (luxval);
colorWipe(3, 0, 1, 400); // Y
} else if (luxval < 3) {
Serial.print ("fading to black :");
Serial.println (luxval);
colorWipe(0, 0, 0, 500); // Black
}
}
void colorWipe(uint8_t r, uint8_t g, uint8_t b, uint8_t wait) {
for(uint16_t i = 0; i < strip.numPixels(); i++) {
uint8_t curr_r, curr_g, curr_b;
strip.getPixelColor(i); // get the current colour
curr_b = strip.getPixelColor(i) & 0xFF; curr_g = (strip.getPixelColor(i) >> 8) & 0xFF; curr_r = (strip.getPixelColor(i) >> 16) & 0xFF; // separate into RGB components
while ((curr_r != r) || (curr_g != g) || (curr_b != b)){ // while the curr color is not yet the target color
if (curr_r < r) curr_r++; else if (curr_r > r) curr_r--; // increment or decrement the old color values
if (curr_g < g) curr_g++; else if (curr_g > g) curr_g--;
if (curr_b < b) curr_b++; else if (curr_b > b) curr_b--;
for(uint16_t i = 0; i < strip.numPixels(); i++) {
strip.setPixelColor(i, curr_r, curr_g, curr_b); // set the color
}
strip.show();
delay(50); // add a delay if its too fast
}
}
}
There is a bread board involved yes, and also an external power supply(the power supply is more then sufficient for one led led strip).
I have also tried to create a schematic and will take some pictures of the wiring when I get home.
Cheers for helping out.