//Code to control the color of the containers and to check the weight in each container to determine when supplies are running low
/*-------------------------------------------------------------------------
Spark Core library to control WS2811/WS2812 based RGB
LED devices such as Adafruit NeoPixel strips.
Currently handles 800 KHz and 400kHz bitstream on Spark Core,
WS2812, WS2812B and WS2811.
Also supports:
- Radio Shack Tri-Color Strip with TM1803 controller 400kHz bitstream.
- TM1829 pixels
PLEASE NOTE that the NeoPixels require 5V level inputs
and the Spark Core only has 3.3V level outputs. Level shifting is
necessary, but will require a fast device such as one of the following:
[SN74HCT125N]
http://www.digikey.com/product-detail/en/SN74HCT125N/296-8386-5-ND/376860
[SN74HCT245N]
http://www.digikey.com/product-detail/en/SN74HCT245N/296-1612-5-ND/277258
Written by Phil Burgess / Paint Your Dragon for Adafruit Industries.
Modified to work with Spark Core by Technobly.
Contributions by PJRC and other members of the open source community.
Adafruit invests time and resources providing this open source code,
please support Adafruit and open-source hardware by purchasing products
from Adafruit!
--------------------------------------------------------------------*/
/* ======================= includes ================================= */
#include "application.h"
//#include "spark_disable_wlan.h" (for faster local debugging only)
#include "neopixel.h"
/* ======================= prototypes =============================== */
void colorAll(uint32_t c, uint8_t wait);
void colorWipe(uint32_t c, uint8_t wait);
void rainbow(uint8_t wait);
void rainbowCycle(uint8_t wait);
uint32_t Wheel(byte WheelPos);
/* ======================= extra-examples.cpp ======================== */
// IMPORTANT: Set pixel COUNT, PIN and TYPE
#define PIXEL_COUNT 8
#define PIXEL_PIN D2
#define PIXEL_TYPE WS2812B
// Parameter 1 = number of pixels in strip
// Parameter 2 = pin number (most are valid)
// note: if not specified, D2 is selected for you.
// Parameter 3 = pixel type [ WS2812, WS2812B, WS2811, TM1803 ]
// note: if not specified, WS2812B is selected for you.
// note: RGB order is automatically applied to WS2811,
// WS2812/WS2812B/TM1803 is GRB order.
//
// 800 KHz bitstream 800 KHz bitstream (most NeoPixel products ...
// ... WS2812 (6-pin part)/WS2812B (4-pin part) )
//
// 400 KHz bitstream (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
// (Radio Shack Tri-Color LED Strip - TM1803 driver
// NOTE: RS Tri-Color LED's are grouped in sets of 3)
Adafruit_NeoPixel strip = Adafruit_NeoPixel(PIXEL_COUNT, PIXEL_PIN, PIXEL_TYPE);
// IMPORTANT: To reduce NeoPixel burnout risk, add 1000 uF capacitor across
// pixel power leads, add 300 - 500 Ohm resistor on first pixel's data input
// and minimize distance between Arduino and first pixel. Avoid connecting
// on a live circuit...if you must, connect GND first.
int fsrPin = A0;
int fsrRead = 0;
int baselineRead = 90; // reading when nothing on pressure sensor
int fullRead = 3000; //read when full;
void setup() {
pinMode(fsrPin, INPUT);
strip.begin();
strip.show(); // Initialize all pixels to 'off'
colorAll(strip.Color(255, 0, 255), 50); // Magenta
Spark.variable("fsrRead", &fsrRead, INT);
Spark.subscribe("IOTFinal15calibrate", calibrate);
}
void loop() {
checkCapacity();
delay(3000);
}
void calibrate(const char *event, const char *data) {
fullRead = analogRead(fsrPin);
Spark.publish("JJIoTFinal15capacity", "H", 2);
}
void checkCapacity() {
fsrRead = analogRead(fsrPin);
double capPercent = (fsrRead*1.0 - baselineRead*1.0)/(fullRead*1.0 - baselineRead*1.0)*100.0;
int temp = (int)capPercent;
if (50 <= temp) {
Spark.publish("JJIoTFinal15capacity", "H", 2);
}
else if ((15 <= temp) && (temp < 50)) {
Spark.publish("JJIoTFinal15capacity", "M", 2);
}
else if ((0 <= temp) && (temp < 15)) {
Spark.publish("JJIoTFinal15capacity", "L", 2);
}
else {
colorAll(strip.Color(255, 0, 0), 50);
}
}
// Set all pixels in the strip to a solid color, then wait (ms)
void colorAll(uint32_t c, uint8_t wait) {
uint16_t i;
for(i=0; i<strip.numPixels(); i++) {
strip.setPixelColor(i, c);
}
strip.show();
delay(wait);
}
Click to Expand
Content Rating
Is this a good/useful/informative piece of content to include in the project? Have your say!
You must login before you can post a comment. .