I am wanting to cycle two pins that will control solid state relays. I would like to have a push button start the loop and the loop continue to run until I reach a specific number of loop cycles.After that condition has been met the loop stops and does not run until I reset the controller.
I am using a Uno and have hacked out some basic code that has the sequence of the pins correct but I am using delays as my programming skills are still at the NOOB stage, can't quite seem to wrap my head around this.
I have a LCD display that is displaying the # of cycles but the display does not update naturally until I get through all of the delays. Now saying that I do not need anything to run at the same time just would like to update the display quicker. I know that the delay command is not what I want but don't understand how to implement the blink without delay example.
Sequence of events that I want to happen.
1 Push button to start loop
2 pin 7 goes high to start stirring motor
3 pin 7 stays high for 1hr & 5 min. // How do I do this long duration cleanly???
4 pin 7 goes low (motor off)
5 delay 3 sec
6 Pin 6 goes high 6.5 sec.
7 pin 6 goes low
8 delay 3 sec
9 count pin 6 cycle
10 display on LCD
11 loop back to step 2
12 cycle until given # of cycles have been reached then stop
Please be patient with me as I am trying to learn.
My Code attempt:
Please note that the times do not match the above sequence as these times are for testing the code quickly.
/*
Feeding System Delivery code based on time
Pin 5 connected to pinch valve solid state relay
Pin 7 connected to stirring motor solid state relay
Pin 6 start button
16 Nov. 2014
*/
#include <LiquidCrystal.h>
// Define LCD pins
LiquidCrystal lcd (12, 11, 3, 2, 1, 0);
const int pinchPin=5;
const int startPin=6;
const int motorPin=7;
int maxnum =22;
int count =0;
//int buttonState = 0; // variable for reading the pushbutton status
// the setup function runs once when you press reset or power the board
void setup() {
// initialize digital pins 5,7 as an output.
// initialize digital pin 6 as an input.
pinMode(pinchPin,OUTPUT);
pinMode(startPin,INPUT);
pinMode(motorPin, OUTPUT);
lcd.begin(16,2);
}
void loop() {
//buttonState = digitalRead(startPin);
lcd.setCursor(2,0);
lcd.print("# OF FEEDINGS");
lcd.setCursor(7,1);
//if ((buttonState == HIGH)&&(count < maxnum)){
digitalWrite(pinchPin,LOW); // pinch valve off for startup
digitalWrite(motorPin, LOW); // turn off stirring motor
delay(5000); // off time of pin 7 delay for stirring system
digitalWrite(pinchPin,HIGH); // pinch valve on
delay (635); // Feeding amount time
digitalWrite(pinchPin,LOW); //pinch valve off
delay (1500);
digitalWrite(motorPin,HIGH); // Stirring Motor ON
delay (15000); //stirring motor run time set to 1hr5min
count++; //count the number of feedings
lcd.print(count);
//while (buttonState == LOW);
}
_24hr_feeding.ino (1.51 KB)