diff --git a/Cockstar Cap.stl b/Cockstar Cap.stl new file mode 100644 index 0000000..6c7fc87 Binary files /dev/null and b/Cockstar Cap.stl differ diff --git a/Cockstar Halter Kappe.stl b/Cockstar Halter Kappe.stl new file mode 100644 index 0000000..2d3e3d9 Binary files /dev/null and b/Cockstar Halter Kappe.stl differ diff --git a/Cockstar Halter Taster.stl b/Cockstar Halter Taster.stl new file mode 100644 index 0000000..e696a83 Binary files /dev/null and b/Cockstar Halter Taster.stl differ diff --git a/Cockstar LCD Holder Converter.stl b/Cockstar LCD Holder Converter.stl new file mode 100644 index 0000000..0c62d62 Binary files /dev/null and b/Cockstar LCD Holder Converter.stl differ diff --git a/Cockstar LCD.stl b/Cockstar LCD.stl new file mode 100644 index 0000000..52dd2c7 Binary files /dev/null and b/Cockstar LCD.stl differ diff --git a/Cockstar Poti.stl b/Cockstar Poti.stl new file mode 100644 index 0000000..478f68b Binary files /dev/null and b/Cockstar Poti.stl differ diff --git a/Cockstar Pumpenhalterung Rahmen.stl b/Cockstar Pumpenhalterung Rahmen.stl new file mode 100644 index 0000000..f740dd8 Binary files /dev/null and b/Cockstar Pumpenhalterung Rahmen.stl differ diff --git a/Cockstar Schlauchhalter.stl b/Cockstar Schlauchhalter.stl new file mode 100644 index 0000000..ca9cd69 Binary files /dev/null and b/Cockstar Schlauchhalter.stl differ diff --git a/Cockstar Stromversorgung.stl b/Cockstar Stromversorgung.stl new file mode 100644 index 0000000..7baa3dd Binary files /dev/null and b/Cockstar Stromversorgung.stl differ diff --git a/README.md b/README.md index b5bb6ba..7a5a4dc 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,48 @@ -# Cockstara +# Cockstar -Cocktail robot to automatically dose rum for Tschunk. \ No newline at end of file +Cocktail robot to automatically dose rum for Tschunk. + + +## Hardware Configuration + +### Functionality: +* 0 off +* 1-99 amount in ml +* 100 permanent on + + +LED-Ring has 12 LEDs + +Pumpe has 22 LEDs. + + +### Connect LCD: +* LCD Arduino +* VCC 5V +* GND GND +* SDA A4 +* SCL A5 + + +### Connect Poti: +* Red A0 +* Gray 5v +* Blue GND + + +### Connect Switch: +* White/Red D12 +* Black (LED) D11 + +### Bottle +* White (D IN) D10 + +### Connect Relay +* Input D13 + +### Connect Pump +* LED Output D9 or D11 + + +## Software +Cockstar uses new LiquidCrystal https://bitbucket.org/fmalpartida/new-liquidcrystal/wiki/Home diff --git a/cockstar.ino b/cockstar.ino new file mode 100755 index 0000000..7ecae1a --- /dev/null +++ b/cockstar.ino @@ -0,0 +1,309 @@ +#include +#include +#include +#include + + +// --- LEDS --- +#define LED_TYPE WS2811 +#define COLOR_ORDER RGB +#define MASTER_BRIGHTNESS 200 + +#define DATA_PIN_A 11 // update pin numbers for data lines as needed +#define DATA_PIN_B 10 +#define DATA_PIN_C 8 +#define DATA_PIN_D 9 + +#define NUM_LEDS_A 22 // adjust number of pixels as needed +#define NUM_LEDS_B 12 +#define NUM_LEDS_C 12 +#define NUM_LEDS_D 22 + +CRGB ledsA[NUM_LEDS_A]; +CRGB ledsB[NUM_LEDS_B]; +CRGB ledsC[NUM_LEDS_C]; +CRGB ledsD[NUM_LEDS_D]; + +static uint8_t hueA=123; + + + +// --- Robot Functionality --- + +// Initialize LCD +LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); + +LcdBarGraphX bar(&lcd, 20, 0, 3); // -- Second line at column 0 + +// Define ports +int poti_port=A0; +int poti_value=0; +int amount=0; +int poti_last_value; +int poti_read; +int poti_new_value; + +int button_port=12; +int button_pressed=0; + +int relay_port=13; +bool relay_status=false; + +bool pump_running=false; +char state='i'; + +int led_bottle = 1; +int led_pump = 2; +int led_glass= 3; + +unsigned long previousMillis=0; +unsigned long currentMillis=0; + +// 500ml/min mean 120ms per ml +int ms_per_ml=132; +int ml_pumped=0; + +void setup() +{ + + // --- Robot Functionality --- + + pinMode(button_port, INPUT); + pinMode(relay_port, OUTPUT); + + //Initialize lcd + lcd.begin(20,4); + + // Standard Set text + lcd.setCursor ( 0, 0 ); + lcd.print(" * * Cockstar * * "); + lcd.setCursor ( 0, 1 ); + lcd.print("Starting... "); + + Serial.begin(9600); + + // --- LEDS --- + delay(2500); //power up delay + FastLED.addLeds(ledsA, NUM_LEDS_A); + FastLED.addLeds(ledsB, NUM_LEDS_B); + FastLED.addLeds(ledsC, NUM_LEDS_C); + FastLED.addLeds(ledsD, NUM_LEDS_D); + FastLED.setBrightness(MASTER_BRIGHTNESS); + FastLED.clear(); + +} + +void loop() +{ + // --- Robot Functionality --- + + // Read status of poti + poti_read =analogRead(A0); + // + poti_new_value=map(poti_read,0,1023,0,101); +if(poti_value != poti_new_value && poti_last_value != poti_new_value) { + poti_last_value=poti_value; + poti_value=poti_new_value; +} + + + // Read status of button + int button_pressed=digitalRead(button_port); +Serial.println(button_pressed); + + // Reset title + lcd.setCursor ( 0, 0 ); + lcd.print(" * * Cockstar * * "); + +// States: +// i: idle +// w: waiting +// r: Running +// f: Finished + +// lcd.print(" "); + +switch(state){ + case 'i': + // Idle + lcd.setCursor ( 0, 1 ); + lcd.print("Ready. Place glass. "); + pump_running=false; + previousMillis=millis(); + + // Print bar graph only if pump running + if(poti_value>0){ + bar.drawValue(ml_pumped,poti_value); + } else { + lcd.print(" "); + } + + if(button_pressed){ + state='w'; + } + break; + + case 'w': + // Waiting until glass is finally placed + lcd.setCursor ( 0, 1 ); + lcd.print("Wait... "); + lcd.print(" "); + + if(!button_pressed){ + state='i'; + } + + // wait 500ms + if(millis()-previousMillis>500) { + state='r'; + previousMillis=millis(); + } + break; + + case 'r': + // Pump is running + pump_running=true; + + if(!button_pressed){ + state='i'; + } + + // Run pump only when poti at least 1ml + if(poti_value > 0){ + + // If poti is over 100ml, run forever + if(poti_value > 100) { + lcd.setCursor ( 0, 1 ); + lcd.print("Pump running. "); + } else { + + // Else, normal mode limited by poti_value + lcd.setCursor ( 0, 1 ); + lcd.print("Filling glass. "); + + ml_pumped=int((millis()-previousMillis)/ms_per_ml); + + if(ml_pumped >= poti_value) { + pump_running=false; + state='f'; + previousMillis=millis(); + } + + lcd.setCursor ( 0, 3 ); + + // Print bar graph only if pump running + if(poti_value>0){ + bar.drawValue(ml_pumped,poti_value); + } else { + lcd.print(" "); + } + } + } else { + lcd.setCursor ( 0, 1 ); + lcd.print("Pump deactivated. "); + pump_running=false; + + } + break; + + case 'f': + // Glass filled + lcd.setCursor ( 0, 1 ); + lcd.print("Ready, remove glass."); + + if(!button_pressed){ + state='i'; + } + break; +} + +// Update pump status +if(pump_running) { + digitalWrite(relay_port, 1); +} else { + digitalWrite(relay_port, 0); +} + +// Update fluid amount +//lcd.setCursor ( 0, 2 ); +//lcd.print(" "); +lcd.setCursor ( 0, 2 ); + +if(poti_value==0) { + lcd.print("Amount: None "); +} else { + if(poti_value>100) { + lcd.print("Amount: Infinite "); + } else { + lcd.print(String("Amount: ") + poti_value + "ml "); + } +} + + + // --- LEDS --- + EVERY_N_MILLISECONDS(50) { + //static uint8_t hueA; + fill_solid(ledsA, NUM_LEDS_A, CHSV(hueA, 255, 255)); + hueA++; + } + + + + //------code for the second strip, ledsB here------ + // Putting the ledsB pattern inside this EVERY_N section allows + // the speed for just this strip to be individually adjusted. + // This will run every 500 milliseconds. + // Use ledsB in this section, such as ledsB[i], and NUM_LEDS_B + // with for loops so it uses the correct length of strip B. + // For example: + +// EVERY_N_MILLISECONDS(20) { + +// } + + + + //------code for ledsC pattern------ + // This strip can run a similar or different pattern, and have + // it's own timing. This will run every 35 milliseconds. + // Use ledsC[i] and NUM_LEDS_C in this section. + + EVERY_N_MILLISECONDS(20) { + static uint8_t hueC; + static uint8_t brightnessC; + static uint8_t countC; + //fill_solid(ledsC, NUM_LEDS_B, CHSV(hueB, 255, 255)); + //hueB++; + + if(state=='f'){ + fill_solid(ledsC, NUM_LEDS_C, CHSV(255, 0, brightnessC)); + countC++; +if(countC==10){ + countC=0; +if(brightnessC<10){ + brightnessC=255; + } else { + brightnessC=0; + } +} +} else { + fill_solid(ledsC, NUM_LEDS_C, CHSV(hueC, 255, 255)); +} +hueC++; +} + + + + //------code for ledsLogo pattern------ + // This strip can also do it's own individual thing. + // Use ledsD and NUM_LEDS_D in this section. + + EVERY_N_MILLISECONDS(20) { + fill_rainbow( ledsD, NUM_LEDS_D, millis()/5, 12); + } + + + // Update the display for all strips. + FastLED.show(); + +}