My replacement laptop just came in, so I got a chance to test the code.
I have to find another way to get the LEDs to flash in the main loop only once at startup. The flashing LEDs inside the setup() did not work the way I wanted. I would like the LEDs to flash every one second for six seconds.
I showed you how to execute something once in the main loop earlier. Refer to that... and then actually have a go at writing some code. If you have specific problems then I'm sure we can assist, but we're not going to write your code for you - well I'm not anyway...
What you are asking is trivial in the extreme - you need to a) keep track of how many times you've flashed the LED, and b) keep track of the 1 second spacing...
Xenia2:
My replacement laptop just came in, so I got a chance to test the code.
I have to find another way to get the LEDs to flash in the main loop only once at startup. The flashing LEDs inside the setup() did not work the way I wanted. I would like the LEDs to flash every one second for six seconds.
What was the code you used to do this? What did it do? What did you want to be different?
This is just enhancement to my current code, which monitor the water level, if water fall below the sensor it will turn on the pump.
Right now every six seconds it read the sensor value, if LOW turn on the pump (yellow LED on), after six seconds if HIGH turn off the pump (green LED on). So at startup it will wait six seconds before anything happens, after six second one of the LED turn on (either pump on or pump off state). I wanted to take that only intial six seconds and have the all LEDs to flash before one of the LED remain solid on.
Nick, below is what I took it from your example. It stay on for 1 second and off, its doesn't flash.
int red = 8; // LED red
int green = 4; // LED green
int amber = 2; // LED amber
void setup()
{
.....
pinMode(red, OUTPUT); // set the digital pin 81 as output
pinMode(green, OUTPUT); // set the digital pin 4 as output
pinMode(amber, OUTPUT); // set the digital pin 2 as output
digitalWrite(green, HIGH);
for (int x=0; x<1000; x++)
{
delay(1);
}
digitalWrite(green, LOW);
for (int x=0; x<1000; x++)
{
delay(1);
}
}
void loop()
........
val = digitalRead(inPin);
if (val == HIGH)
{
digitalWrite(green, LOW);
digitalWrite(amber, HIGH); //amber LED on
digitalWrite(relayPin, HIGH);
if ( 0 == shutDownTime) // <<< changed
shutDownTime = relay_on_time + 30000; // <<< changed
}
if (val == LOW)
If "val" isn't HIGH as a result of a digitalRead, it is unlikely to be anything other than LOW, so retesting it is a bit of a waste of time.
A simple "else" would suffice
for (byte i = 0; i < 6; i++)
{
digitalWrite (green, HIGH);
delay (1000);
digitalWrite (green, LOW);
delay (1000);
}
I haven't try it yet, but just curious will the flashing still work if I use mills() instead of delay()? Of course the coding structure will change too.
Anything's possible, so you could re-write that to use millis() instead of delay(), but why would you want to?? You'd have to spin in a tight loop waiting for millis() to go beyond a previously recorded value from millis(), which is basically what delay() does...
^^ This. Or to put it another way, using millis is useful when you want your code to do other things during the delay, which is often the case and can give the illusion of doing many things at once. Here, you have no such need, so why complicate your code?