Hi, I'm currently building a Cocktail machine and I want to add one more Pump.
I have a Visual C Program that sends the dosing times to the arduino.
First I had 4, now I have 5 Pumps so I need to send one more time value to the arduino.
The old Program with 4 Pumps works, but with 5 I doesn't.
I'm not a good programmer, I found that Arduino code on the Internet and don't know how to code it to work with 5 values
Thats the 4 Pump code (forget the Variable "sicherung")
int Y1 = 13, Y2 = 12, Y3 = 11, Y4 =10, sicherung =9;
int zeit1 = 0, zeit2 = 0, zeit3 = 0, zeit4 = 0;
const int SERIAL_BUFFER_SIZE = 100;
char serialBuffer[SERIAL_BUFFER_SIZE];
const int NUMBER_OF_VALUES = 4;
unsigned int values[NUMBER_OF_VALUES];
void setup()
{
Serial.begin(9600);
pinMode(Y1, OUTPUT);
pinMode(Y2, OUTPUT);
pinMode(Y3, OUTPUT);
pinMode(Y4, OUTPUT);
pinMode(sicherung, INPUT);
digitalWrite(Y1, HIGH);
digitalWrite(Y2, HIGH);
digitalWrite(Y3, HIGH);
digitalWrite(Y4, HIGH);
}
void loop()
{
if (sicherung == HIGH)
{digitalWrite(Y1, HIGH);
digitalWrite(Y2, HIGH);
digitalWrite(Y3, HIGH);
digitalWrite(Y4, HIGH);}
else if (readSerial(Serial))
{
parseSerial();
Serial.write(0);
digitalWrite(Y1, LOW);
delay(values[0]);
digitalWrite(Y1, HIGH);
delay(100);
Serial.write(1);
digitalWrite(Y2, LOW);
delay(values[1]);
digitalWrite(Y2, HIGH);
delay(100);
Serial.write(2);
digitalWrite(Y3, LOW);
delay(values[2]);
digitalWrite(Y3, HIGH);
delay(100);
Serial.write(3);
digitalWrite(Y4, LOW);
delay(values[3]);
digitalWrite(Y4, HIGH);
delay(100);
Serial.write(4);
delay(100);
Serial.write(5);
}
}
void parseSerial()
{
byte index = 0;
char* ptr = strtok(serialBuffer, ",;");
while (ptr != NULL && index < NUMBER_OF_VALUES)
{
values[index++] = atol(ptr);
ptr = strtok(NULL, ",;");
zeit1 = values[0];
zeit2 = values[1];
zeit3 = values[2];
zeit4 = values[3];
}
}
/* for (byte i = 0; i < index; i++) //nur zum Test! Kann entfernt werden
Serial.println(values[i]);
Serial.println(F("---"));
}*/
bool readSerial(Stream& stream)
{
static byte index;
while (stream.available())
{
char c = stream.read();
if (c == '\n' && index > 0)
{
serialBuffer[index] = '\0';
index = 0;
return true;
}
else if (c >= 32 && index < SERIAL_BUFFER_SIZE - 1)
{
serialBuffer[index++] = c;
}
}
return false;
}
And this is how I changed it to work with 5, but it doesnt
int Y1 = 13, Y2 = 12, Y3 = 11, Y4 =10, Y5 =9;
int zeit1 = 0, zeit2 = 0, zeit3 = 0, zeit4 = 0, zeit5 = 0;
const int SERIAL_BUFFER_SIZE = 125;
char serialBuffer[SERIAL_BUFFER_SIZE];
const int NUMBER_OF_VALUES = 5;
unsigned int values[NUMBER_OF_VALUES];
void setup()
{
Serial.begin(9600);
pinMode(Y1, OUTPUT);
pinMode(Y2, OUTPUT);
pinMode(Y3, OUTPUT);
pinMode(Y4, OUTPUT);
pinMode(Y5, OUTPUT);
digitalWrite(Y1, HIGH);
digitalWrite(Y2, HIGH);
digitalWrite(Y3, HIGH);
digitalWrite(Y4, HIGH);
digitalWrite(Y5, HIGH);
}
void loop()
{
parseSerial();
Serial.write(0);
digitalWrite(Y1, LOW);
delay(values[0]);
digitalWrite(Y1, HIGH);
delay(100);
Serial.write(1);
digitalWrite(Y2, LOW);
delay(values[1]);
digitalWrite(Y2, HIGH);
delay(100);
Serial.write(2);
digitalWrite(Y3, LOW);
delay(values[2]);
digitalWrite(Y3, HIGH);
delay(100);
Serial.write(3);
digitalWrite(Y4, LOW);
delay(values[3]);
digitalWrite(Y4, HIGH);
delay(100);
Serial.write(4);
digitalWrite(Y5, LOW);
delay(values[4]);
digitalWrite(Y5, HIGH);
delay(100);
Serial.write(5);
delay(100);
Serial.write(6);
}
void parseSerial()
{
byte index = 0;
char* ptr = strtok(serialBuffer, ",;");
while (ptr != NULL && index < NUMBER_OF_VALUES)
{
values[index++] = atol(ptr);
ptr = strtok(NULL, ",;");
zeit1 = values[0];
zeit2 = values[1];
zeit3 = values[2];
zeit4 = values[3];
zeit5 = values[4];
}
}
/* for (byte i = 0; i < index; i++) //nur zum Test! Kann entfernt werden
Serial.println(values[i]);
Serial.println(F("---"));
}*/
bool readSerial(Stream& stream)
{
static byte index;
while (stream.available())
{
char c = stream.read();
if (c == '\n' && index > 0)
{
serialBuffer[index] = '\0';
index = 0;
return true;
}
else if (c >= 40 && index < SERIAL_BUFFER_SIZE - 1)
{
serialBuffer[index++] = c;
}
}
return false;
}
The Visual C Program sends this 1000,1000,1000,1000,1000,
The Problem is, that the Outputs aren't doing anything and it's looping forever in the void loop()
I mean it sends the serial.write values, but not with the delay it gets from the serial