hi
is it possible to have more than 1 void loop?
hi
is it possible to have more than 1 void loop?
No, there can be only one function named loop(). You can have other loops inside loop() though. If you tell us what you want to do we can probably help.
but you can certainly create multiple sub-functions doing various things that are called by loop()
As an Arduino can only do one thing at a time it is best not to think of a problem as a collection of loops. Have a look at how the code is organized in Several Things at a Time
Note how each function runs very briefly and returns to loop() so the next one can be called. None of the functions tries to complete a task in one call. And there may be dozens of calls to a function before it is actually time for it to do anything.
...R
ok so im trying to have a relay run and a LCD screen say something each time a relay turns on so my idea was to have 1 loop run the relays and the 2nd loop control my LCD screen
Or just have a couple of state machines running on a single loop()
lyrad:
ok so im trying to have a relay run and a LCD screen say something each time a relay turns on so my idea was to have 1 loop run the relays and the 2nd loop control my LCD screen
Why do you need two loops for that? Just update the LCD whenever you update the relay.
aarg:
Why do you need two loops for that? Just update the LCD whenever you update the relay.
because when i try that im always 1 off
because when i try that im always 1 off
Post what you tried
UKHeliBob:
Post what you tried
changing the delays and every time i can not get right
No, really, this is the programming section so, post your code.
TheMemberFormerlyKnownAsAWOL:
No, really, this is the programming section so, post your code.
this is the code
#include <LiquidCrystal.h>
LiquidCrystal lcd(7, 6, 5, 4, 3, 2);
int L = 13;
int G = 12;
int B = 11;
int T = 10;
int Q = 9;
int P = 8;
void setup() {
//the lcd sign setup
lcd.begin(16, 2);
lcd.setCursor(0, 0);
lcd.print("Project by Daryl");
lcd.setCursor(2, 2);
lcd.print("Joe & Marie");
//making my sign pins as outputs
pinMode(L, OUTPUT);
pinMode(G, OUTPUT);
pinMode(B, OUTPUT);
pinMode(T, OUTPUT);
pinMode(Q, OUTPUT);
pinMode(P, OUTPUT);
}
void loop() {
//truning letters on in a buld up and have the lcd change
digitalWrite(L, LOW); //Turn on relay
delay(1000);
lcd.begin(16, 2);
lcd.setCursor(0, 0);
lcd.print("lesbian");
delay(1);
digitalWrite(G, LOW); //Turn on relay
delay(1000);
lcd.begin(16, 2);
lcd.setCursor(0, 0);
lcd.print("gay");
delay(1);
digitalWrite(B, LOW); //Turn on relay
delay(1000);
lcd.begin(16, 2);
lcd.setCursor(0, 0);
lcd.print("bisexual");
delay(1);
digitalWrite(T, LOW); //Turn on relay
delay(1000);
lcd.begin(16, 2);
lcd.setCursor(0, 0);
lcd.print("trans");
delay(1);
lcd.begin(16, 2);
lcd.setCursor(0, 0);
lcd.print("queer");
delay(1);
digitalWrite(Q, LOW); //Turn on relay
delay(1000);
lcd.begin(16, 2);
lcd.setCursor(0, 0);
lcd.print("plus");
delay(1);
digitalWrite(P, LOW); //Turn on relay
delay(500);
//turning all letters off simultaneously and a 1 sec delay
digitalWrite(L, HIGH); //Turn off relay
delay(1);
digitalWrite(G, HIGH); //Turn off relay
delay(1);
digitalWrite(B, HIGH); //Turn off relay
delay(1);
digitalWrite(T, HIGH); //Turn off relay
delay(1);
digitalWrite(Q, HIGH); //Turn off relay
delay(1);
digitalWrite(P, HIGH); //Turn off relay
delay(250);
//all on and a haff a sec delay
digitalWrite(L, LOW); //Turn on relay
delay(60);
digitalWrite(G, LOW); //Turn on relay
delay(60);
digitalWrite(B, LOW); //Turn on relay
delay(60);
digitalWrite(T, LOW); //Turn on relay
delay(60);
digitalWrite(Q, LOW); //Turn on relay
delay(60);
digitalWrite(P, LOW); //Turn on relay
delay(60);
delay(500);
//all off and a 1/4 delay
digitalWrite(L, HIGH); //Turn off relay
delay(1);
digitalWrite(G, HIGH); //Turn off relay
delay(1);
digitalWrite(B, HIGH); //Turn off relay
delay(1);
digitalWrite(T, HIGH); //Turn off relay
delay(1);
digitalWrite(Q, HIGH); //Turn off relay
delay(1);
digitalWrite(P, HIGH); //Turn off relay
delay(250);
//all on and a haff a sec delay
digitalWrite(L, LOW); //Turn on relay
delay(60);
digitalWrite(G, LOW); //Turn on relay
delay(60);
digitalWrite(B, LOW); //Turn on relay
delay(60);
digitalWrite(T, LOW); //Turn on relay
delay(60);
digitalWrite(Q, LOW); //Turn on relay
delay(60);
digitalWrite(P, LOW); //Turn on relay
delay(60);
delay(500);
//all off and haff a sec delay
digitalWrite(L, HIGH); //Turn off relay
delay(1);
digitalWrite(G, HIGH); //Turn off relay
delay(1);
digitalWrite(B, HIGH); //Turn off relay
delay(1);
digitalWrite(T, HIGH); //Turn off relay
delay(1);
digitalWrite(Q, HIGH); //Turn off relay
delay(1);
digitalWrite(P, HIGH); //Turn off relay
delay(500);
}
Obvious. You have placed the delays BETWEEN the relay and LCD updates.
//turning all letters off simultaneously and a 1 sec delay
No, and no.
Please remember to use code tags when posting code
Yeah, what are those 1/1000 second delays for? Can anyone read that fast?
aarg:
Obvious. You have placed the delays BETWEEN the relay and LCD updates.
so what can i do ? this is my first project that was not done for me so i'm bad at this sorry if this is a stupid mistake
aarg:
Yeah, what are those 1/1000 second delays for? Can anyone read that fast?
and for this i can, on the display it is changing with the build up it just 1 ahed
As a newbie, that’s a good start at linear, sequential programming...
(not so good for the lack of code tags).
Your next learning experience will involve functions and event-driven code that responds more easily to your inputs.
There is a lot you’ll come across in the next few weeks..., sadly that’s often how long it takes at a steady pace with lots of commitment.
Try, fail, ask, retry, learn. There’s no shortcut unless you pay someone else to do it for you.
lyrad:
so what can i do ? this is my first project that was not done for me so i'm bad at this sorry if this is a stupid mistake
You can do a "structured walk through" your code. Keep track of the time in milliseconds, and all the variable values at each line.
lyrad:
so what can i do ?
Have you carefully studied the code in the link I gave you in Reply #3?
It has most, if not all, of what you need to know.
...R