Rain Ye
Published © GPL3+

Life Check

This project takes time as a horizontal axis, presenting the learning, emotions and philosophy throughout one's life.

BeginnerFull instructions provided10 hours96
Life Check

Things used in this project

Hardware components

Seeeduino Lotus V1.1 - ATMega328 Board with Grove Interface
Seeeduino Lotus V1.1 - ATMega328 Board with Grove Interface
×1
Grove - 16 x 2 LCD (White on Blue)
Seeed Grove - 16 x 2 LCD (White on Blue)
×1
Grove - WS2813 RGB LED Strip Waterproof - 60 LED/m - 1m
Seeed Grove - WS2813 RGB LED Strip Waterproof - 60 LED/m - 1m
×3
Seeed Grove- Magnetic Switch
×1

Software apps and online services

Arduino IDE
Arduino IDE

Hand tools and fabrication machines

Laser cutter (generic)
Laser cutter (generic)

Story

Read more

Code

yeyu

Arduino
#include <Adafruit_NeoPixel.h>
#include <Wire.h>
#include "rgb_lcd.h"

#define LED_PIN1    5
#define LED_PIN2    6
#define LED_PIN3    7

#define MAGNECTIC_SWITCH1 2
#define MAGNECTIC_SWITCH2 3
#define MAGNECTIC_SWITCH3 4

#define LED_COUNT  18

byte neopix_gamma[] = {
    0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
    0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  1,  1,  1,
    1,  1,  1,  1,  1,  1,  1,  1,  1,  2,  2,  2,  2,  2,  2,  2,
    2,  3,  3,  3,  3,  3,  3,  3,  4,  4,  4,  4,  4,  5,  5,  5,
    5,  6,  6,  6,  6,  7,  7,  7,  7,  8,  8,  8,  9,  9,  9, 10,
   10, 10, 11, 11, 11, 12, 12, 13, 13, 13, 14, 14, 15, 15, 16, 16,
   17, 17, 18, 18, 19, 19, 20, 20, 21, 21, 22, 22, 23, 24, 24, 25,
   25, 26, 27, 27, 28, 29, 29, 30, 31, 32, 32, 33, 34, 35, 35, 36,
   37, 38, 39, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 50,
   51, 52, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 66, 67, 68,
   69, 70, 72, 73, 74, 75, 77, 78, 79, 81, 82, 83, 85, 86, 87, 89,
   90, 92, 93, 95, 96, 98, 99,101,102,104,105,107,109,110,112,114,
  115,117,119,120,122,124,126,127,129,131,133,135,137,138,140,142,
  144,146,148,150,152,154,156,158,160,162,164,167,169,171,173,175,
  177,180,182,184,186,189,191,193,196,198,200,203,205,208,210,213,
  215,218,220,223,225,228,231,233,236,239,241,244,247,249,252,255 };

Adafruit_NeoPixel strip1(LED_COUNT, LED_PIN1, NEO_RGB + NEO_KHZ800);
Adafruit_NeoPixel strip2(LED_COUNT, LED_PIN2, NEO_RGB + NEO_KHZ800);
Adafruit_NeoPixel strip3(LED_COUNT, LED_PIN3, NEO_RGB + NEO_KHZ800);

rgb_lcd lcd;

const int LED_COUNT_INIT1 = 6;
const int LED_COUNT_INIT2 = 8;
const int LED_COUNT_INIT3 = 9;
const int steps = 6;

int LED_COUNT1 = 0;
int LED_COUNT2 = 0;
int LED_COUNT3 = 0;

int LED_COUNT1_P = 0;
int LED_COUNT2_P = 0;
int LED_COUNT3_P = 0;

int sw_flag1 = 0;
int sw_flag2 = 0;
int sw_flag3 = 0;

int mode = 0;
long delay_count = 0;

int times = 0;

/*-----------*/
uint32_t Wheel1(byte WheelPos) {
  WheelPos = 255 - WheelPos;
  if(WheelPos < 85) {
    return strip1.Color(255 - WheelPos * 3, 0, WheelPos * 3,0);
  }
  if(WheelPos < 170) {
    WheelPos -= 85;
    return strip1.Color(0, WheelPos * 3, 255 - WheelPos * 3,0);
  }
  WheelPos -= 170;
  return strip1.Color(WheelPos * 3, 255 - WheelPos * 3, 0,0);
}

uint8_t red(uint32_t c) {
  return (c >> 16);
}
uint8_t green(uint32_t c) {
  return (c >> 8);
}
uint8_t blue(uint32_t c) {
  return (c);
}

void rainbowFade2White1(uint8_t wait, int rainbowLoops, int whiteLoops) {
  float fadeMax = 255.0;
  int fadeVal = 0;
  uint32_t wheelVal;
  int redVal, greenVal, blueVal;

  for(int k = 0 ; k < rainbowLoops ; k ++){
    
    for(int j=0; j<256; j++) { // 5 cycles of all colors on wheel

      for(int i=0; i< strip1.numPixels(); i++) {

        wheelVal = Wheel1(((i * 256 / strip1.numPixels()) + j) & 255);

        redVal = red(wheelVal) * float(fadeVal/fadeMax);
        greenVal = green(wheelVal) * float(fadeVal/fadeMax);
        blueVal = blue(wheelVal) * float(fadeVal/fadeMax);

        strip1.setPixelColor( i, strip1.Color( redVal, greenVal, blueVal ) );
        strip2.setPixelColor( i, strip1.Color( redVal, greenVal, blueVal ) );
        strip3.setPixelColor( i, strip1.Color( redVal, greenVal, blueVal ) );
      }
     //First loop, fade in!
      if(k == 0 && fadeVal < fadeMax-1) {
          fadeVal++;
      }

      //Last loop, fade out!
      else if(k == rainbowLoops - 1 && j > 255 - fadeMax ){
          fadeVal--;
      }
        strip1.show();
        strip2.show();
        strip3.show();
        delay(wait);
    }
  }
  for(int k = 0 ; k < whiteLoops ; k ++){

    for(int j = 0; j < 256 ; j++){

        for(uint16_t i=0; i < strip1.numPixels(); i++) {
            strip1.setPixelColor(i, strip1.Color(0,0,0, neopix_gamma[j] ) );
            strip2.setPixelColor(i, strip1.Color(0,0,0, neopix_gamma[j] ) );
            strip3.setPixelColor(i, strip1.Color(0,0,0, neopix_gamma[j] ) );
          }
          strip1.show();
          strip2.show();
          strip3.show();
        }
    for(int j = 255; j >= 0 ; j--){

        for(uint16_t i=0; i < strip1.numPixels(); i++) {
            strip1.setPixelColor(i, strip1.Color(0,0,0, neopix_gamma[j] ) );
            strip2.setPixelColor(i, strip1.Color(0,0,0, neopix_gamma[j] ) );
            strip3.setPixelColor(i, strip1.Color(0,0,0, neopix_gamma[j] ) );
          }
          strip1.show();
          strip2.show();
          strip3.show();
        }
  }
}
/*-----------*/

boolean isNearMagnet(int sw)
{
    int sensorValue = digitalRead(sw);
    if(sensorValue == HIGH)//if the sensor value is HIGH?
    {
        return true;//yes,return ture
    }
    else
    {
        return false;//no,return false
    }
}

void breathing_turn_on1(int num, int brightness_max, int brightness_min)
{
  for(int n=brightness_min;n<brightness_max;++n)
  {
    for(int i=0 ; i < num; ++i)
    {
      strip1.setPixelColor(i, strip1.Color((n/255.0)*77, (n/255.0)*219, (n/255.0)*109));
    }
    strip1.show();
  }
}

void breathing_turn_off1(int num, int brightness_max, int brightness_min)
{
  for(int k=brightness_max;k>brightness_min;--k)
  {
    for(int i=0 ; i < num; ++i)
    {
      strip1.setPixelColor(i, strip1.Color((k/255.0)*77, (k/255.0)*219, (k/255.0)*109));
    }
    strip1.show();
  }
}

void breathing_turn_on2(int num, int brightness_max, int brightness_min)
{
  for(int n=brightness_min;n<brightness_max;++n)
  {
    for(int i=0 ; i < num; ++i)
    {
      strip2.setPixelColor(i, strip2.Color((n/255.0)*162, (n/255.0)*123, (n/255.0)*63));
    }
    strip2.show();
  }
}

void breathing_turn_off2(int num, int brightness_max, int brightness_min)
{
  for(int n=brightness_max;n>brightness_min;--n)
  {
    for(int i=0 ; i < num; ++i)
    {
      strip2.setPixelColor(i, strip2.Color((n/255.0)*180, (n/255.0)*144, (n /255.0)*75));
    }
    strip2.show();
  }
}

void breathing_turn_on3(int num, int brightness_max, int brightness_min)
{
  for(int n=brightness_min;n<brightness_max;++n)
  {
    for(int i=0 ; i < num; ++i)
    {
      strip3.setPixelColor(i, strip3.Color((n/255.0)*169, (n/255.0)*46, (n /255.0)*223));
    }
    strip3.show();
  }
}

void breathing_turn_off3(int num, int brightness_max, int brightness_min)
{
  for(int n=brightness_max;n>brightness_min;--n)
  {
    for(int i=0 ; i < num; ++i)
    {
      strip3.setPixelColor(i, strip3.Color((n/255.0)*169, (n/255.0)*46, (n /255.0)*223));
    }
    strip3.show();
  }
}

void setNum(int num)
{
  lcd.setCursor(6,2);
  lcd.print(num);
}

void setup() {
  LED_COUNT1 = LED_COUNT_INIT1;
  LED_COUNT2 = LED_COUNT_INIT2;
  LED_COUNT3 = LED_COUNT_INIT3;

  LED_COUNT1_P = LED_COUNT1;
  LED_COUNT2_P = LED_COUNT2;
  LED_COUNT3_P = LED_COUNT3;

  times = (LED_COUNT1 + LED_COUNT2 + LED_COUNT3)/steps;
  
  Serial.begin(115200);
  strip1.begin();
  strip1.show();
  strip2.begin();
  strip2.show();
  strip3.begin();
  strip3.show();
  pinMode(MAGNECTIC_SWITCH1, INPUT);
  pinMode(MAGNECTIC_SWITCH2, INPUT);
  pinMode(MAGNECTIC_SWITCH3, INPUT);
  lcd.begin(16, 2);
  lcd.print("   Life Check");
  lcd.setCursor(8,2);
  lcd.print("%");
  breathing_turn_on1(LED_COUNT1,40,39);
  breathing_turn_on2(LED_COUNT2,40,39);
  breathing_turn_on3(LED_COUNT3,40,39);
}

void loop()
{
  if(isNearMagnet(MAGNECTIC_SWITCH1) == true && sw_flag1 == 0)
  {
    delay_count = millis();
    delay(1000);
    if (isNearMagnet(MAGNECTIC_SWITCH1) == true && sw_flag1 == 0)
    {
      sw_flag1 = 1;
      LED_COUNT1++;
      if (LED_COUNT1 <= 36)
      {
        breathing_turn_on1(LED_COUNT1,40,39);
      }
    }
  }else if(isNearMagnet(MAGNECTIC_SWITCH1) == false && sw_flag1 == 1)
  {
    sw_flag1 = 0;
  }else if (isNearMagnet(MAGNECTIC_SWITCH1) == true && sw_flag1 == 1)
  {
    if(millis() - delay_count >= 3000)
    {
      mode = 1;
    } 
  }

  if(isNearMagnet(MAGNECTIC_SWITCH2) == true && sw_flag2 == 0)
  {
    delay(1000);
    if (isNearMagnet(MAGNECTIC_SWITCH2) == true && sw_flag2 == 0)
    {
      sw_flag2 = 1;
      LED_COUNT2++;
      if (LED_COUNT2 <= 36)
      {
        breathing_turn_on2(LED_COUNT2,40,39);
      }
    }
  }else if(isNearMagnet(MAGNECTIC_SWITCH2) == false && sw_flag2 == 1)
  {
    sw_flag2 = 0;
  }

  if(isNearMagnet(MAGNECTIC_SWITCH3) == true && sw_flag3 == 0)
  {
    delay(1000);
    if (isNearMagnet(MAGNECTIC_SWITCH3) == true && sw_flag3 == 0)
    {
      sw_flag3 = 1;
      LED_COUNT3++;
      if (LED_COUNT3 <= 36)
      {
        breathing_turn_on3(LED_COUNT3,40,39);
      }
    }
  }else if(isNearMagnet(MAGNECTIC_SWITCH3) == false && sw_flag3 == 1)
  {
    sw_flag3 = 0;
  }  
  int per = LED_COUNT1+LED_COUNT2+LED_COUNT3;
  if (per/steps > times)
  {
    mode = 1;
    ++times;
  }
  per = per*100/54;
  setNum(per);
  Serial.print(LED_COUNT1);
  Serial.print(',');
  Serial.print(LED_COUNT2);
  Serial.print(',');
  Serial.print(LED_COUNT3);
  Serial.print(',');
  Serial.print(per);
  Serial.println();

  if (mode == 1)
  {
    breathing_turn_off1(LED_COUNT1,40,0);
    breathing_turn_off2(LED_COUNT2,40,0);
    breathing_turn_off3(LED_COUNT3,40,0);
    for (int i = 0; i < 4; ++i)
    {
      breathing_turn_on1(i,40,39);
      delay(100);
    }
    for (int i = 0; i < 4; ++i)
    {
      breathing_turn_on2(i,40,39);
      delay(100);
    }
    for (int i = 0; i < 5; ++i)
    {
      breathing_turn_on3(i,40,39);
      delay(100);
    }
    delay(500);
    rainbowFade2White1(3,3,1);
    mode = 0;
    breathing_turn_on1(LED_COUNT1,40,39);
    breathing_turn_on2(LED_COUNT2,40,39);
    breathing_turn_on3(LED_COUNT3,40,39);
  }
}

Credits

Rain Ye

Rain Ye

1 project • 0 followers

Comments

Add projectSign up / Login