Circuit Playground soft moon light

Hi all. I was thinking of to use my Circuit Playground as a moon light in my Vivarium and rely did not find any good code to start with or even a nice tutorial.

What i want is that when the light sensor see the daylight i got in the Vivarium turns of than the Circuit Playground start with a soft moon light and during time at night to be more bright and agian get back to an more soft light before the day ligth turns on again.

If any one got a solution pleas share that with me.

You might use an LDR to determine when “sundown” starts and a simple pot to adjust how long your night will be. You would simply divide the “night” into 3 phases: ramp up the moonlight brightness to max, max moonlight, then slowly ramp it down to off. I’d suggest using PWM to adjust the light levels.

PS - what animal?

There will be no animal at all just tropical plants.
Do you got an code example for that?

I used this code before on a light stripe for my aquarium and is it possible to use parts of it or the full code in to the circuit playground?

Here is the code.

#include <Adafruit_NeoPixel.h>

const int STRAND_SIZE = 24; // we have a 30-LED strand
const byte STRAND_PIN = 6; // putting the neopixels on pin 6
Adafruit_NeoPixel strand = Adafruit_NeoPixel(STRAND_SIZE, STRAND_PIN, NEO_GRB + NEO_KHZ800);

//#define DEBUG

#ifdef DEBUG

const int MOON_WIDTH = 5; // make our moon 5 pixels wide.
const unsigned long NIGHT_TIMEms = 10L * 1000L; // 30 seconds
const unsigned long REDRAW_DELAYms =  100L; // redraw twice a second
const byte STRAND_BRIGHTNESS = 32; // one eightth brighness
const int MOON_WIDTH = 5; // make our moon 5 pixels wide.
const unsigned long NIGHT_TIMEms = 10L * 60L * 60L * 1000L; // the night is 10 hours long - in milliseconds
const unsigned long REDRAW_DELAYms =  60L * 1000L; // redraw once a  minute - in milliseconds
const byte STRAND_BRIGHTNESS = 64; // one quarter brighness

unsigned long lastUpdate;

void setup() {
  // set the overall brightness of the strip to 160 out of a possible 255
  lastUpdate = millis();

#ifdef DEBUG

void loop() {
  // update every 60 minutes (meansured in milliseconds)
  if (millis() - lastUpdate > REDRAW_DELAYms) {
    lastUpdate = millis();


// ok. This function does the job of drawing the moon, based on what time it is.

void updateMoon() {

  float now = ((float)millis()) / ((float)NIGHT_TIMEms); // "now" is a number between 0 and 1

  if (now >= 1) return;

#ifdef DEBUG

  // the overall brighness of the moon depends on the time.
  float moonBright = sin(now * PI);
  if (moonBright <= 0 ) return;

#ifdef DEBUG

  float moonPos = now * STRAND_SIZE;

  for (int i = -MOON_WIDTH / 2 - 1; i <= MOON_WIDTH / 2 + 1; i++) {
    int pix = moonPos + i;
    if (pix < 0 || pix >= STRAND_SIZE) continue;

    float bright = moonBright * cos((pix - moonPos) / MOON_WIDTH * PI);

    // 'bright' may be negative at the start and end of the edge of the moon
    if (bright > 0) {

      bright = bright * bright; // this changes the profile of the sin by a bit

        // 200/200/255 should be a nice bluish white
        (int)(0xE0 * bright),
        (int)(0xE0 * bright),
        (int)(0xFF * bright)

#ifdef DEBUG

No one that got a solution?
Or can help me in the right direction?

So.... what do you have running?

  1. You mentioned your LDR light sensor. Have you gotten that to work yet?

  2. Can you control your kit’s lights?

I got this now on the CP board right now GitHub - schnoggo/jack-o-candle: An Arduino sketch for creating a flickering candle effect with Neopixels.
So i have basically not any good other start to begin with to make what i want and as it is all new to me i seek help from any one how are willing to help me.

You probably should move this to the Project Guidance section, this board is for paid help.

Also do go and read the "How to use this forum" sticky, so you know what we need for informed help.

The problem, of course, is that the light itself influences light in the vivarium. But that’s ok! You can build a thing whose job it is to keep the brigthness at a target level.

Of course, the correct values for the target LDR reading is a matter of experimentation.

If the LDR value gets lower as the light gets brighter, you’ll need to reverse some of this logic:

const int TARGET_LDR_LEVEL = 40; // whatever
const int SLOP_FACTOR = 2; 
byte current_LED = 0;

loop() {
  delay(1000); // this can be pretty slow

  current_LDR = read_the_LDR();

  if(current_LDR < TARGET_LDR-SLOP_FACTOR) {
    // need to turn the light BRIGHTER
    if(current_LED < 255) {
      current_LED ++;
      analogOut(LED_PIN, current_LED);
  else if(current_LDR > TARGET_LDR+SLOP_FACTOR) {
    // need to turn the light DIMMER    
    if(current_LED >0) {
      current_LED --;
      analogOut(LED_PIN, current_LED);