Back to Parent

// This #include statement was automatically added by the Particle IDE.
#include <neopixel.h>

// This #include statement was automatically added by the Particle IDE.
#include <neopixel.h>
#include <math.h>

#include "Particle.h"
#include "neopixel.h"
SYSTEM_MODE(AUTOMATIC);

// IMPORTANT: Set pixel COUNT, PIN and TYPE WS2812B E357163
#define PIXEL_PIN D2
#define PIXEL_COUNT 7
#define PIXEL_TYPE WS2812B

Adafruit_NeoPixel strip(PIXEL_COUNT, PIXEL_PIN, PIXEL_TYPE);
int conditionPin = A1;
int conditionVal = 0;

// Prototypes for local build, ok to leave in for Build IDE
void rainbow(uint8_t wait);
uint32_t Wheel(byte WheelPos);

int pixel_position = 0;
int startTime = -1;
int checkTime1 = 10 * 1000; // go sleeping count down time
unsigned long currentTime = -1;
bool isCounting = false;

// input
int forceYellowPin = A1;
int forceYellowVal = 0;
int forceWhitePin = A3;
int forceWhiteVal = 0;
int forceBluePin = A5;
int forceBlueVal = 0;

// output
int ledYellowPin = D1;
int ledWhitePin = D3;
int ledBluePin = D5;

bool isYellow = false;
bool isWhite = false;
bool isBlue = false;

void setup()
{
  Serial.begin(9600);
  Particle.variable( "condition", conditionVal );
  Particle.variable( "forceYellow", &forceYellowVal, INT);
  Particle.variable( "forceWhite", &forceWhiteVal, INT);
  Particle.variable( "forceBlue", &forceBlueVal, INT);
  pinMode(ledYellowPin, OUTPUT);
  pinMode(ledWhitePin, OUTPUT);
  pinMode(ledBluePin, OUTPUT);
	
  strip.begin();
  strip.show(); // Initialize all pixels to 'off'
  delay(1000);
  startTime = startTime + millis();
}

void loop()
{
  int x;
  uint32_t c = strip.Color(255-x, 255-x, x); // light color
  
  // read fsr value from three devices
  forceYellowVal = analogRead(forceYellowPin);
  Serial.println(forceYellowVal);
  isYellow = forceYellowVal < 700;
  forceWhiteVal = analogRead(forceWhitePin);
  Serial.println(forceWhiteVal);
  isWhite = forceWhiteVal < 700;
  forceBlueVal = analogRead(forceBluePin);
  Serial.println(forceBlueVal);
  isBlue = forceBlueVal < 700;
  
  // light up the corresponding LED light
  if (isYellow) {
      digitalWrite(ledYellowPin, HIGH);
  } else {
      digitalWrite(ledYellowPin, LOW);
  }
  
  if (isBlue) {
      digitalWrite(ledBluePin, HIGH);
  } else {
      digitalWrite(ledBluePin, LOW);
  }
  
  if (isWhite) {
      digitalWrite(ledWhitePin, HIGH);
  } else {
      digitalWrite(ledWhitePin, LOW);
  }
  
  if (isWhite) {
      c = strip.Color(255, 255, 255); // white light
      isCounting = false;
  } else if (isYellow) {
      c = strip.Color(255, 255, 100); // yellow light
      isCounting = false;
  } else if (isBlue) {
      c = strip.Color(120, 120, 255); // blue light
      isCounting = false;
  } else {
      // set the counting state
      if (!isCounting) {
          startTime = millis();
          isCounting = true;
      } 
      
      // light fading out
      currentTime = millis() - startTime;
      x = map(currentTime, 0, checkTime1, 255, 0);
      x = x < 0 ? 0 : x;
      c = strip.Color(x, x, x);  // fading light
  }
  
  // light up jewel
  for (int i = 0; i < strip.numPixels(); i++) {
        strip.setPixelColor(i, c);
  }
  strip.show();
  delay(100);
  
}
Susan Xu (2019) Click to Expand

Content Rating

Is this a good/useful/informative piece of content to include in the project? Have your say!

0