I am trying to replace the electronics in an old commercial vacuum packer to get it functional again, without modifying the hardware. To do this, I have an Arduino Duemilanove attached to a relay board.
I am having an issue with the timer portion. Previously potentiometers had been used to set the vacuum and seal times. I have these connected to the analog inputs. Heres the code I used for the timer:
start_time = millis();
do{
delay(10);
current_time = millis();
timer = current_time - start_time;
seal_time_bytes = analogRead(seal_pot);
seal_time_fraction = seal_time_bytes / analog_max;
seal_time = seal_time_fraction * seal_time_max;
}
while(timer<seal_time);
The goal is to have it loop so that the timer can be adjusted on the fly. analog_max and seal_time_max are set earlier in code.
When I run this code, there is no delay. If I comment out this portion, and replace it with a simple delay(), the code seems to run fine.
I've gone over it looking for issues many times, but I am completely new to arduino's and have very little experience coding, so I am probably missing something obvious. Any suggestions would be appreciated.
Here's my complete code, just in case:
The existing start button for the cycle shorted the ground and wiper of the pot, so that is what the first loop checks. This seems to be working fine. Otherwise, its just two of the timers above along with the required relay switches at each phase.
int green = 5;
int orange = 6;
int motor = 1;
int seal = 2;
int bleed = 3;
int bladder = 4;
int hatch = 10;
int vac_pot = 5;
int seal_pot = 0;
int bleed_time = 1000;
int bladder_delay = 500;
int vac_time_bytes = 0;
int seal_time_bytes = 500;
float seal_time = 30000;
float vac_time = 30000;
float vac_time_fraction = .5;
float seal_time_fraction = .5;
int analog_max = 875;
int current_time = 0;
int start_time = 0;
int timer = 0;
int seal_time_max = 10000;
int vac_time_max = 60000;
void setup() {
pinMode(green, OUTPUT);
pinMode(orange, OUTPUT);
pinMode(motor, OUTPUT);
pinMode(seal, OUTPUT);
pinMode(bleed, OUTPUT);
pinMode(bladder, OUTPUT);
pinMode(hatch, INPUT);
pinMode(seal_pot, INPUT);
pinMode(vac_pot, INPUT);
digitalWrite(green, LOW);
digitalWrite(orange, HIGH);
digitalWrite(motor, HIGH);
digitalWrite(seal, HIGH);
digitalWrite(bleed, HIGH);
digitalWrite(bladder, HIGH);
}
void loop() {
do{
vac_time_bytes = analogRead(vac_pot);
if(digitalRead(hatch)==LOW)
{vac_time_bytes = vac_time_bytes + 1000;};
delay(10);
}
while(
vac_time_bytes>2
);
start_time = millis();
digitalWrite(motor, LOW);
digitalWrite(orange, LOW);
digitalWrite(green, HIGH);
do{
delay(10);
current_time = millis();
timer = current_time - start_time;
vac_time_bytes = analogRead(vac_pot);
vac_time_fraction = vac_time_bytes / analog_max;
vac_time = vac_time_fraction * vac_time_max;
}
while(timer<vac_time);
digitalWrite(motor, HIGH);
digitalWrite(orange, HIGH);
digitalWrite(bladder, LOW);
delay(bladder_delay);
digitalWrite(seal, LOW);
start_time = millis();
do{
delay(10);
current_time = millis();
timer = current_time - start_time;
seal_time_bytes = analogRead(seal_pot);
seal_time_fraction = seal_time_bytes / analog_max;
seal_time = seal_time_fraction * seal_time_max;
}
while(timer<seal_time);
digitalWrite(seal, HIGH);
digitalWrite(bladder, HIGH);
digitalWrite(bleed, LOW);
delay(bleed_time);
digitalWrite(bleed, HIGH);
digitalWrite(green, LOW);
}
Again, many thanks for any help you can provide.