Skip to content
Snippets Groups Projects
Commit ce996907 authored by Frederic Aust's avatar Frederic Aust
Browse files

Added Status LED Stripes which are controlled with the code vom Project...

Added Status LED Stripes which are controlled with the code vom Project "Hochzeitsgeschenk" and added a servo to move the Tube to the center of the scale if puring or away to keep it dry from drops
parent 1e10477c
No related branches found
No related tags found
No related merge requests found
......@@ -2,6 +2,17 @@
#include <Adafruit_PWMServoDriver.h>
#include "HX711.h"
#include <FastLED.h>
#if FASTLED_VERSION < 3001000
#error "Requires FastLED 3.1 or later; check github for latest code."
#endif
#define NUM_LEDS 25
#define DATA_PIN 7
//#define CLOCK_PIN 13
// HX711 circuit wiring
const int LOADCELL_DOUT_PIN = A1;
const int LOADCELL_SCK_PIN = A0;
......@@ -25,6 +36,7 @@ Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver(0x41);
#define NUM_PUMPS 4
#define PIN_AIR_PUMP 13
#define PIN_PSU 12
#define TUBE_MOVER 15
bool boot = true;
bool waage_einstellen = false;
......@@ -54,7 +66,7 @@ void setup()
Serial.begin(115200);
Serial.println("######### Started #########");
setupLeds();
// Init SCALE ##########
scale.begin(LOADCELL_DOUT_PIN, LOADCELL_SCK_PIN);
......@@ -88,6 +100,8 @@ void setup()
void loop()
{
ledLoop();
bool keepPumping = false;
float weight = 0;
if (scale.is_ready()) {
......@@ -114,6 +128,7 @@ void loop()
keepPumping = true;
}
}
} else if (currentAction == pump_g)
{
// if weightlimit reached stop pummping
......@@ -156,6 +171,7 @@ void loop()
{
currentAction = idle;
initScale();
setLedMode(3);
}
if (keepPumping == false)
......@@ -163,6 +179,7 @@ void loop()
deactivateAirPump();
currentAction = idle;
goalWeight = 0;
setLedMode(3);
}
if (Serial.available())
......@@ -193,6 +210,7 @@ void interpretInput(String input)
currentAction = idle;
setLedMode(3);
while ((str = strtok_r(p, ";", &p)) != NULL) // delimiter is the semicolon
{
......@@ -203,14 +221,17 @@ void interpretInput(String input)
if (String(str) == "t")
{
currentAction = pump_ms;
setLedMode(1);
continue;
} else if (String(str) == "g")
{
currentAction = pump_g;
setLedMode(1);
continue;
} else if (String(str) == "tara")
{
currentAction = tara;
setLedMode(0);
continue;
}
......@@ -270,6 +291,19 @@ void interpretInput(String input)
}
}
void moveTubes(bool puring)
{
if (puring)
{
setServoToDegree(TUBE_MOVER, 45);
delay(1000);
}
else
{
setServoToDegree(TUBE_MOVER, 0);
}
}
void interpretInput_old(String input)
{
//for Debugging
......
......@@ -29,7 +29,8 @@ void openPump(uint8_t servo)
void activateAirPump()
{
// TODO to be implemented
moveTubes(true);
Serial.println("Air Pump activated");
digitalWrite(PIN_AIR_PUMP, HIGH);
digitalWrite(LED_BUILTIN, HIGH);
......@@ -41,6 +42,8 @@ void deactivateAirPump()
//Serial.println("Air Pump deactivated");
digitalWrite(PIN_AIR_PUMP, LOW);
digitalWrite(LED_BUILTIN, LOW);
delay(1000);
moveTubes(false);
}
void setServoToDegree(uint8_t servo,int degree)
......
uint8_t ledMode = 3;
// 0: White 100%
// 1: Cylon
// 2: Hold current Color
// 3: Pride
// 4: Off
uint8_t ledModes = 5;
CRGB leds[NUM_LEDS];
void setupLeds()
{
FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS); // GRB ordering is assumed
}
void setLedMode(uint8_t mode)
{
ledMode = mode;
}
void fadeall() { for(int i = 0; i < NUM_LEDS; i++) { leds[i].nscale8(250); } }
uint8_t cylonCounter =0;
uint8_t hue = 0;
void ledLoop()
{
//Serial.println("Mode: "+String(ledMode));
switch(ledMode){
case 0:
{
Serial.println("Mode: White");
for(int i =0; i< NUM_LEDS;i++)
{
leds[i] = CRGB::White;
}
FastLED.show();
break;
}
case 1:
{
Serial.println("Mode: Cylon");
// First slide the led in one direction
//for(cylonCounter =0; cylonCounter< NUM_LEDS;cylonCounter++)
//{
cylonCounter++;
if(cylonCounter>= NUM_LEDS)
{
cylonCounter =0;
}
// Set the i'th led to red
leds[cylonCounter] = CHSV(hue++, 255, 255);
// Show the leds
FastLED.show();
// now that we've shown the leds, reset the i'th led to black
// leds[cylonCounter] = CRGB::Black;
//fadeall();
// Wait a little bit before we loop around and do it again
//}
break;
}
case 2:
{
Serial.print("Mode: Hold Color");
break;
}
case 3:
{
Serial.println("Mode: Pride");
pride();
FastLED.show();
break;
}
case 4:
{
Serial.println("Mode: Black");
for(int i =0; i< NUM_LEDS;i++)
{
leds[i] = CRGB::Black;
}
FastLED.show();
break;
}
default:
{
Serial.println("##### undefinded Mode #####");
}
}
}
// Pride2015
// Animated, ever-changing rainbows.
// by Mark Kriegsman
// This function draws rainbows with an ever-changing,
// widely-varying set of parameters.
void pride()
{
static uint16_t sPseudotime = 0;
static uint16_t sLastMillis = 0;
static uint16_t sHue16 = 0;
uint8_t sat8 = beatsin88( 87, 220, 250);
uint8_t brightdepth = beatsin88( 341, 96, 224);
uint16_t brightnessthetainc16 = beatsin88( 203, (25 * 256), (40 * 256));
uint8_t msmultiplier = beatsin88(147, 23, 60);
uint16_t hue16 = sHue16;//gHue * 256;
uint16_t hueinc16 = beatsin88(113, 1, 3000);
uint16_t ms = millis();
uint16_t deltams = ms - sLastMillis ;
sLastMillis = ms;
sPseudotime += deltams * msmultiplier;
sHue16 += deltams * beatsin88( 400, 5,9);
uint16_t brightnesstheta16 = sPseudotime;
for( uint16_t i = 0 ; i < NUM_LEDS; i++) {
hue16 += hueinc16;
uint8_t hue8 = hue16 / 256;
brightnesstheta16 += brightnessthetainc16;
uint16_t b16 = sin16( brightnesstheta16 ) + 32768;
uint16_t bri16 = (uint32_t)((uint32_t)b16 * (uint32_t)b16) / 65536;
uint8_t bri8 = (uint32_t)(((uint32_t)bri16) * brightdepth) / 65536;
bri8 += (255 - brightdepth);
CRGB newcolor = CHSV( hue8, sat8, bri8);
uint16_t pixelnumber = i;
pixelnumber = (NUM_LEDS-1) - pixelnumber;
nblend( leds[pixelnumber], newcolor, 64);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment