Skills Dev III: Ambient Orb_Yulin

Made by Yulin Chen ·

Created: November 13th, 2024

0

Intention

Create a simple connection and display between Neopixels and meeting in google calendar by particle and IFTTT.

0

Process

It is very interesting to build the connection between these as a meeting alert. At first, it is a little bit hard for me to understand the millis(), so I just follow the instruction to do this part. I try two version of code to do this, maybe the first one has somewhere wrong, sometimes it can perform well but sometimes doesn't, however, I verified it in particle it shows correct.

0

Reflection

I think it is a great thing to dive into after this course, it can react to lots of scenarios.

0

First Version:

The Neopixels will start to change color from white to red. And then after several seconds, it will turn back to white when the

It is white now.

0
#include "Particle.h"
#include <neopixel.h>

#define PIXEL_PIN SPI
#define PIXEL_COUNT 8
#define PIXEL_TYPE WS2812B

Adafruit_NeoPixel strip(PIXEL_COUNT, PIXEL_PIN, PIXEL_TYPE);
unsigned long lastFade = 0;
int Interval = 9000;
int brightness = 0;
bool com = true;

void setup() {
    strip.begin();
    strip.show();
    Particle.function("LightUp", handleHandleLightUp);
}

int handleHandleLightUp(String command) {
    com = true;
    return 1;
}

void loop() {
    
    if (com) {
        unsigned long now = millis();
        uint16_t i;
        uint32_t c = strip.Color(255, 255, 255);
        if ((now - lastFade) >= Interval) {
            for (int color = 255; color > 0; color--) {
                for (uint16_t i = 0; i < strip.numPixels(); i++) {
                    uint32_t c = strip.Color(255, color, color);
                    strip.setPixelColor(i, c);
                }
                strip.show();
                delay(20);
            }
        lastFade = now;
        }
        com = false;

    } else if (!com) {
        unsigned long now = millis();
        if ((now - lastFade) >= Interval) {
            for (int color = 0; color <= 255; color++) {
                for (uint16_t i = 0; i < strip.numPixels(); i++) {
                    uint32_t c = strip.Color(255, color, color);
                    strip.setPixelColor(i, c);
                }
                strip.show();
                delay(20);
            }
        lastFade = now;
        }
        com = true;
    }
}
Click to Expand
0

Start to turn red.

0

Nearly red now.

0
0

Second Version looks better


0
#include "Particle.h"
#include <neopixel.h>

#define PIXEL_PIN SPI
#define PIXEL_COUNT 8
#define PIXEL_TYPE WS2812B

Adafruit_NeoPixel strip(PIXEL_COUNT, PIXEL_PIN, PIXEL_TYPE);
unsigned long lastFade = 0;
int Interval = 9000;
int brightness = 0;
bool com = true;

void setup() {
    strip.begin();
    strip.show();
    Particle.function("LightUp", handleHandleLightUp);
}

int handleHandleLightUp(String command) {

        unsigned long now = millis();
        uint16_t i;
        uint32_t c = strip.Color(255, 255, 255);
        if ((now - lastFade) >= Interval) {
            for (int color = 255; color > 0; color--) {
                for (uint16_t i = 0; i < strip.numPixels(); i++) {
                    uint32_t c = strip.Color(255, color, color);
                    strip.setPixelColor(i, c);
                }
                strip.show();
                delay(20);
            }
        lastFade = now;
        }

        for (int color = 0; color <= 255; color++) {
            for (uint16_t i = 0; i < strip.numPixels(); i++) {
                uint32_t c = strip.Color(255, color, color);
                strip.setPixelColor(i, c);
            }
            strip.show();
            delay(20);
        }
    lastFade = now;
return 1;
}
Click to Expand
0
x
Share this Project

This project is only accessible by signed in users. Be considerate and think twice before sharing.



About

~