Hello from greece... I am an very new to arduino uno and any help will be appreciate
...
I am trying to make some led's to work with a very specific way ...
I have led 1 led 2 led 3 led 4 and led 5 and a on off switch
The plan is when the switch goes to on position to trigger the following sequence:
Led 4 opens , 3 seconds later led 2 is opening (led 4 remains on) after 1 sec led 1 & 2 are opening and remain on and 1 sec later led 4 turn off (led 1,2,3 remains on and staying like that until the switch goes to off position)
When the switch goes to off
(The sequence start with led's 1,2,3,on )
Led 4 is open ...after 1 sec led's 1, 2, 3 are off after that led 5 is opens and stay open from 5 sec after that time led 5 and 4 are closing and remain close untill the switch goes to on position again
Sorry to be the one to tell you this, but you must use current limiting resistors with LEDs. And you can get more help by showing how you have everything connected in the next post, rather than people guessing what you have done.
Hi @kostakef
It's been a while since I made any programs with Arduino, and unfortunately I don't have one to test with right now. At least it should get you going it the right direction, try this program:
If you use main(), setup() will not be executed unless you call it from main(). So the pins will not be set to OUTPUT. Further no initialisations are done so delay might (or will) not work.
this is the code untill now but not work well at least the second part (it just looping )
const int switchPin = 13; //Switch Connected to PIN 13
const int led8 = 8; //LED Connected to PIN 8
const int led9 = 9; //LED Connected to PIN 9
const int led10 = 10; //LED Connected to PIN 10
const int led11 = 11; //LED Connected to PIN 11
const int led12 = 12; //LED Connected to PIN 12
int switchState = 0; // Variable for reading Switch status
void setup()
{
pinMode(led8, OUTPUT); //LED PIN is Output
pinMode(led9, OUTPUT); //LED PIN is Output
pinMode(led10, OUTPUT); //LED PIN is Output
pinMode(led11, OUTPUT); //LED PIN is Output
pinMode(led12, OUTPUT); //LED PIN is Output
pinMode(switchPin, INPUT); //Switch PIN is input with PULLUP
}
void loop()
{
switchState = digitalRead(switchPin); //Reads the status of the switch.
if (switchState == LOW) //If the switch is pressed
{
digitalWrite(led9, HIGH); //LED ON
delay(3000); //3 Second Delay
digitalWrite(led8, HIGH); //LED ON
delay(3000); //3 Second Delay
digitalWrite(led10, HIGH); //LED ON
digitalWrite(led11, HIGH); //LED ON
delay(1000); //1 Second Delay
digitalWrite(led9, LOW); //LED OFF
}
switchState = digitalRead(switchPin); //Reads the status of the switch.
if (switchState == HIGH) //If the switch is pressed
{
digitalWrite(led8, HIGH);
digitalWrite(led10, HIGH);
digitalWrite(led11, HIGH);
digitalWrite(led9, HIGH);
delay(1000);
digitalWrite(led8, LOW);
digitalWrite(led10, LOW);
digitalWrite(led11, LOW);;
digitalWrite(led12, HIGH);
delay(5000);
digitalWrite(led9, LOW);
digitalWrite(led12, LOW);
}
}
a. Use the switch to enable or reset a timer.
b. If the timer is enabled and the timer value is between X and Y produce a number which the state machine (switch/case construct) uses to select which case to execute.
c. if timer value is between R and S produce a different number for the state machine. And so on.
d. Important - if the timer is NOT enabled you need to generate a state for that, too.
here is the project if you can help will be perfect
problem is that the led 9 is not turned off (digitalWrite(led9, LOW); ) in the first part and in the second is looping the second part
Try INPUT_PULLUP for you pinMode() on that switch.
Also, in the else part, the logic will turn off led9 then immediately (next loop) turn it back on. Place a delay() after the last digitalWrite() to give yourself time to see that it went off.
Pro tip: in the wokwi, you can set all the delays quite a bit smaller, then you aren't wasting time a few seconds at a time to see if something works.
You could
# define THREE_SECONDS 700 // lie! should be 3000
and use THREE_SECONDS everywhere instead of 3000 - when the time does arrive for "real time" testing, just change the one lie 700 to 3000 and the thing will get r e a l s l o w like you want.
Then it's time to learn. Put your project on hold and put "millis arduino timing" or something like that in your favorite search engine. You'll get hundreds of hits.
my main problem is i can not understand why is not folowing the switch..
in theory if switch is low it must do the first part and if high the second part but i can make it work
the oposite i have read all the replies and now i am reading about milis.
that is actually my first code as i am in arduino for only 15 days with no prior coding expirience