My for loop count cycle is not stopping when I place it in void setup
If I use similar code with port settings, the loop stops after the count is over.
The two codes are shown below:
Can someone let me know what I'm doing wrong?
int SV1 = 22;
int SV2 = 23;
int SV3 = 24;
int SV4 = 25;
int SV5 = 26;
int SV6 = 27;
int SV7 = 28;
void setup () {
pinMode(SV1, OUTPUT);
pinMode(SV2, OUTPUT);
pinMode(SV3, OUTPUT);
pinMode(SV4, OUTPUT);
pinMode(SV5, OUTPUT);
pinMode(SV6, OUTPUT);
pinMode(SV7, OUTPUT);
int maxnumber = 1; // set cycle count
for (int count = 0; count < maxnumber;) //Counter will stop counting after certain amount of cycles
{
delay(4000);
digitalWrite(SV1, HIGH);
digitalWrite(SV2, HIGH);
digitalWrite(SV3, HIGH);
digitalWrite(SV4, HIGH);
digitalWrite(SV5, HIGH);
digitalWrite(SV6, HIGH);
digitalWrite(SV7,HIGH);
delay(4000);
digitalWrite(SV1, LOW);
digitalWrite(SV2, LOW);
digitalWrite(SV3, LOW);
digitalWrite(SV4, LOW);
digitalWrite(SV5, LOW);
digitalWrite(SV6, LOW);
digitalWrite(SV7,LOW);
}
}
void loop();
It works for when I use the ports to turn the relays on/off and it stops.
unsigned long TOn = 6000; // delay time to turn relay on/off (60,000 ms = 1 minute)
unsigned long TOff = 6000;
void setup () {
DDRA = B11111111; // set PORTA (digital 22-29) to outputs
int maxnumber = 4; // set cycle count
for (int count = 0; count < maxnumber;) //Counter will stop counting after certain amount of cycles
{
PORTA = B00000000;
delay(TOn); //relay on time
PORTA = B11111111;
delay(TOff); //relay off time
}
DDRA = B00000000;
}
void loop(void){
}
C:\Users\ADMINI~1\AppData\Local\Temp\ccQEoQmi.ltrans0.ltrans.o: In function `main':
<artificial>:(.text.startup+0x158): undefined reference to `loop'
collect2.exe: error: ld returned 1 exit status
exit status 1
Error compiling for board Arduino/Genuino Mega or Mega 2560
SPECIFIC_RELAYS_ON_OFF_CYCLE_TESTING:20:48: error: expected primary-expression before ')' token
for (int count = 0; count < maxnumber; count++;) //Counter will stop counting after certain amount of cycles
^
exit status 1
expected ')' before ';' token
int SV1 = 22; // pin assigned for solenoid valve 1
int SV2 = 23;
int SV3 = 24;
int SV4 = 25;
int SV5 = 26;
int SV6 = 27;
int SV7 = 28;
void setup () {
pinMode(SV1, OUTPUT);
pinMode(SV2, OUTPUT);
pinMode(SV3, OUTPUT);
pinMode(SV4, OUTPUT);
pinMode(SV5, OUTPUT);
pinMode(SV6, OUTPUT);
pinMode(SV7, OUTPUT);
int maxnumber = 1; // set cycle count
for (int count = 0; count < maxnumber; count++;) //Counter will stop counting after certain amount of cycles
{
delay(4000);
digitalWrite(SV1, HIGH);
digitalWrite(SV2, HIGH);
digitalWrite(SV3, HIGH);
digitalWrite(SV4, HIGH);
digitalWrite(SV5, HIGH);
digitalWrite(SV6, HIGH);
digitalWrite(SV7,HIGH);
delay(4000);
digitalWrite(SV1, LOW);
digitalWrite(SV2, LOW);
digitalWrite(SV3, LOW);
digitalWrite(SV4, LOW);
digitalWrite(SV5, LOW);
digitalWrite(SV6, LOW);
digitalWrite(SV7,LOW);
}
}
void loop();
True. I was just trying it. If i use just count++ on its own I still get a compile error.
C:\Users\ADMINI~1\AppData\Local\Temp\ccXpQl1G.ltrans0.ltrans.o: In function `main':
<artificial>:(.text.startup+0x158): undefined reference to `loop'
collect2.exe: error: ld returned 1 exit status
exit status 1
Error compiling for board Arduino/Genuino Mega or Mega 2560.
I'm assuming you are using a relay package designed for the arduino hobbyist- like myself; if this is the case, when you remove the trigger (signal) wire for relay 1 and reconnect the trigger (signal) wire- does relay 1 turn off and remain off? If so, you purchased a relay package with an inferior design flaw.
I tried to unplug it and plug it back in.
It does work after plugging it back in.
I am going to try to use a relay off command outside of the for loop at the end of the program to see if that turns off the relays when it's done cycling.