Skip to content

Instantly share code, notes, and snippets.

@virgilvox
Created November 19, 2018 03:56
Show Gist options
  • Save virgilvox/bc2d98b5c71836b558937c198efc3107 to your computer and use it in GitHub Desktop.
Save virgilvox/bc2d98b5c71836b558937c198efc3107 to your computer and use it in GitHub Desktop.
#include <FastLED.h>
#include <HX711_ADC.h>
//HX711 constructor (dout pin, sck pin)
HX711_ADC LoadCell(4, 5);
long t;
// How many leds in your strip?
#define NUM_LEDS 64
// For led chips like Neopixels, which have a data line, ground, and power, you just
// need to define DATA_PIN. For led chipsets that are SPI based (four wires - data, clock,
// ground, and power), like the LPD8806, define both DATA_PIN and CLOCK_PIN
#define DATA_PIN 6
#define CLOCK_PIN 13
#define COMM_PIN 7
CRGB leds[NUM_LEDS];
void setup() {
Serial.begin(9600);
Serial.println("resetting");
LEDS.addLeds<WS2812,DATA_PIN,RGB>(leds,NUM_LEDS);
LEDS.setBrightness(84);
Serial.println("Wait...");
LoadCell.begin();
long stabilisingtime = 4000; // tare preciscion can be improved by adding a few seconds of stabilising time
LoadCell.start(stabilisingtime);
LoadCell.setCalFactor(696.0); // user set calibration factor (float)
Serial.println("Startup + tare is complete");
pinMode(COMM_PIN, OUTPUT);
digitalWrite(COMM_PIN, LOW);
}
void loop() {
LoadCell.update();
//get smoothed value from data set + current calibration factor
bool isHuggerPresent = false;
if (millis() > t + 400) {
float i = LoadCell.getData();
Serial.print("Load_cell output val: ");
Serial.println(i);
t = millis();
if(i > 180.0){
isHuggerPresent = true;
}
}
if(isHuggerPresent){
loadBlue();
digitalWrite(COMM_PIN, HIGH);
}else {
clearLed();
digitalWrite(COMM_PIN, LOW);
}
//check if last tare operation is complete
if (LoadCell.getTareStatus() == true) {
Serial.println("Tare complete");
}
}
void fadeall() { for(int i = 0; i < NUM_LEDS; i++) { leds[i].nscale8(250); } }
void loadBlue() {
for(int i = 0; i < NUM_LEDS; i++) {
leds[i] = CRGB::Blue;
// Show the leds
FastLED.show();
fadeall();
// delay(10);
}
for(int i = 0; i < NUM_LEDS; i++) {
leds[i] = CRGB::Blue;
// Show the leds
FastLED.show();
// delay(10);
}
}
void clearLed() {
for(int i = 0; i < NUM_LEDS; i++) {
leds[i] = CRGB::Black;
FastLED.show();
fadeall();
// delay(10);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment