Guest User

Untitled

a guest
Nov 18th, 2018
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.11 KB | None | 0 0
  1. #include <FastLED.h>
  2. #include <HX711_ADC.h>
  3.  
  4. //HX711 constructor (dout pin, sck pin)
  5. HX711_ADC LoadCell(4, 5);
  6.  
  7. long t;
  8.  
  9. // How many leds in your strip?
  10. #define NUM_LEDS 64
  11.  
  12. // For led chips like Neopixels, which have a data line, ground, and power, you just
  13. // need to define DATA_PIN. For led chipsets that are SPI based (four wires - data, clock,
  14. // ground, and power), like the LPD8806, define both DATA_PIN and CLOCK_PIN
  15. #define DATA_PIN 6
  16. #define CLOCK_PIN 13
  17.  
  18. #define COMM_PIN 7
  19.  
  20. CRGB leds[NUM_LEDS];
  21.  
  22. void setup() {
  23. Serial.begin(9600);
  24. Serial.println("resetting");
  25. LEDS.addLeds<WS2812,DATA_PIN,RGB>(leds,NUM_LEDS);
  26. LEDS.setBrightness(84);
  27.  
  28. Serial.println("Wait...");
  29. LoadCell.begin();
  30. long stabilisingtime = 4000; // tare preciscion can be improved by adding a few seconds of stabilising time
  31. LoadCell.start(stabilisingtime);
  32. LoadCell.setCalFactor(696.0); // user set calibration factor (float)
  33. Serial.println("Startup + tare is complete");
  34.  
  35. pinMode(COMM_PIN, OUTPUT);
  36. digitalWrite(COMM_PIN, LOW);
  37. }
  38.  
  39. void loop() {
  40. LoadCell.update();
  41.  
  42. //get smoothed value from data set + current calibration factor
  43. bool isHuggerPresent = false;
  44.  
  45. if (millis() > t + 400) {
  46. float i = LoadCell.getData();
  47. Serial.print("Load_cell output val: ");
  48. Serial.println(i);
  49. t = millis();
  50. if(i > 180.0){
  51. isHuggerPresent = true;
  52. }
  53. }
  54.  
  55. if(isHuggerPresent){
  56. loadBlue();
  57. digitalWrite(COMM_PIN, HIGH);
  58. }else {
  59. clearLed();
  60. digitalWrite(COMM_PIN, LOW);
  61. }
  62.  
  63. //check if last tare operation is complete
  64. if (LoadCell.getTareStatus() == true) {
  65. Serial.println("Tare complete");
  66. }
  67. }
  68.  
  69. void fadeall() { for(int i = 0; i < NUM_LEDS; i++) { leds[i].nscale8(250); } }
  70.  
  71. void loadBlue() {
  72. for(int i = 0; i < NUM_LEDS; i++) {
  73. leds[i] = CRGB::Blue;
  74. // Show the leds
  75. FastLED.show();
  76. fadeall();
  77. // delay(10);
  78. }
  79. for(int i = 0; i < NUM_LEDS; i++) {
  80. leds[i] = CRGB::Blue;
  81. // Show the leds
  82. FastLED.show();
  83. // delay(10);
  84. }
  85. }
  86.  
  87. void clearLed() {
  88. for(int i = 0; i < NUM_LEDS; i++) {
  89. leds[i] = CRGB::Black;
  90. FastLED.show();
  91. fadeall();
  92. // delay(10);
  93. }
  94. }
Add Comment
Please, Sign In to add comment