I'm designing this carousel style cocktail machine and I have:
- motor i to turn alcohols (rotatory table)
- motor ii to dispense alcohol (push to release)
- motor iii and iv dispense mixer (peristaltic pumps)
The machine:
a. As button is pressed, depending on the drink, C and/or D will start dispensing the mixer.
b. At the same time as button is pressed, i turns the table to a specific alcohol(by controlling steps), then stop.
c. ii starts the dispensing mechanism, drink poured, ii then needs to clear out(reverse steps) the way before i can move again to the next alcohol.
I have codes for controlling the lcd display for drinks. User can switching between drinks using potentiometer:
#include <Wire.h> //
#include <LiquidCrystal_I2C.h>//
#include <avr/pgmspace.h>
const char string_0[] PROGMEM = "Welcome!";
const char string_1[] PROGMEM = "Manhattan";
const char string_2[] PROGMEM = "Cosmo";
const char string_3[] PROGMEM = "Mojito";
const char string_4[] PROGMEM = "BlackRussian";
const char string_5[] PROGMEM = "LongIslandIceTea";
const char string_6[] PROGMEM = "DRINK#6";
const char string_7[] PROGMEM = "DRINK#7";
const char string_8[] PROGMEM = "DRINK#8";
const char string_9[] PROGMEM = "DRINK#9";
const char string_10[] PROGMEM = "DRINK#10";
const char* const string_table[] PROGMEM = {string_0, string_1, string_2, string_3, string_4, string_5, string_6, string_7, string_8, string_9, string_10};
char buffer[50]; // make sure this is large enough for the largest string it must hold
int analogPin = 0;
int result = 0;
int oldResult = 0;
int i = 0;
LiquidCrystal_I2C lcd(0x3F,16,2);//
void setup()
{
Serial.begin(9600);
while (!Serial);
Serial.println("OK");
lcd.init();//
// Turn on the backlight
lcd.backlight();//
delay(100);
}
void loop()
{
result = analogRead(analogPin);
i = result / 100; //more drinks --> try result / 50
if (i != oldResult)
{
lcd.clear();//
strcpy_P(buffer, (char*)pgm_read_word(&(string_table[i]))); // Necessary casts and dereferencing, just copy.
lcd.home();//
lcd.print(buffer);//
delay(200);
}
oldResult = i;
}
I still need to incorporate a button for user to select the chosen drink and to run motors.
The code to run 2 motors in sequence:
// (1) Pin Setup
int pulsePinA = 12;
int dirPinA = 11;
int pulsePinB = 5;
int dirPinB = 4;
// (2) Timing Setup
int PWMicros = 1000;
int millisbetweenSteps = 1;
int del = 2000;
void setup() {
Serial.begin(9600);
pinMode(pulsePinA, OUTPUT);
pinMode(pulsePinB, OUTPUT);
pinMode(dirPinA, OUTPUT);
pinMode(dirPinB, OUTPUT);
// (3) Running motor sequences---------need to save (3) (as cases?) for different mix of cocktail, and be able to call each case by controlling potentiometer, and select button.
motorA(200,0); //motorfucntion(steps, direction) //I need motor C and/or motor D to start together with motor A, and able to call a stop independently.
motorB(400,0);
delay(del); //delay to pour drinks-------If i want to have motor C and/or motor D running but need motor B to pause for a while, I shouldn't use delay?
motorB(400,1);
}
// (4) motor A function
void motorA(int stepsA,int dirA) {
for(int n = 0; n <= stepsA; n++) { //------code from Robin2 on Arduino forum(Thank you!)
digitalWrite(dirPinA, dirA);
digitalWrite(pulsePinA, HIGH);
delayMicroseconds(PWMicros);
digitalWrite(pulsePinA, LOW);
delay(millisbetweenSteps);
}
}
// (5) motor B function
void motorB(int stepsB, int dirB) {
for(int n = 0; n <= stepsB; n++) {
digitalWrite(dirPinB, dirB);
digitalWrite(pulsePinB, HIGH);
delayMicroseconds(PWMicros);
digitalWrite(pulsePinB, LOW);
delay(millisbetweenSteps);
}
}
// (6) motor C function
//(7) motor D function
void loop() {
}
Questions:
How do you compile everything together?
How to make motors running simultaneously while another motor needs to pause for a while?
What is the approach here?
I'm using a Arduino Mega 2560, 3 easy drivers, and a HY-DIV268N-5A stepper motor drive. Not too worried about the wiring but I'm really struggles with the programming.
Thank you