Thats a green and a red led , they will light every high edge , I use delay function to do this wave for both of them digitalWrite(4, LOW); // turn the red LED on digitalWrite(5, HIGH); // turn the green LED on delay(1000);
ect...
but I want as next step to install a button that will turn of green led when i press it without affecting the red light . I was thinking to code it with pulsln() but i dont have periodic signal (red led). (info to know : The green/red led will have only 5 steps as shown on picture.)
The problem is : They told me its easy to code it but my mind said "timers party"
Anyway...thanks for reading guys ! <3
Hello andreas_hacked
Post your current sketch, well formated, with comments and in so called code tags "</>" and a schematic, not a Fritzy diagram, to see how we can help.
Have a nice day and enjoy coding in C++.
Дайте миру шанс
digitalWrite(4, LOW); // turn the red LED on ...................... LOW led ON????
digitalWrite(5, HIGH); // turn the green LED on ,,,,,,,,,,,,,,,,,,,,,,, HIGH led ON????
It’s quite an interesting challenge for a novice….
You need to look at the fundamentals differently…
The LEDs are not on or off at a specific ‘time’, but you need to account for the ‘edges’, the ‘change of state’.
Look at the diagram more closely, and consider the ‘constant timebase’ of the edges, then consider what you need to keep track of.
In it simplest understanding, the green simply goes on and off with every clock edge.
Now count the edges to determine the red state…
Ok, with that understood, and everything working normally - the red has no dependence on the green, it’s only looking at the clocking edges.
You can simply stop blinking the green when the button is pressed.
Your next challenge is when to re-enable the green blink..! Asynchronously, or on the next edge, or dependent,on the red state… then carry on.
Hello andreas_hacked
It seems to be a XY problem.
In which cases the Arduino will be a either a consumer, producer or both for the LED "data"s?
Provide more details of your project.
Have a nice day and enjoy coding in C++.
Дайте миру шанс!
@andreas_hacked
karma for the timing diagram.
But a question:
if I just expand / repeat your diagram there will be a long sequence of green LED (V1). Is this really you want to get?
If I add one additional low phase (V2), the pulses stay in sync.
// 1 tick = 1/1024 second that means 0,00097sec near 1 msec so if I need 15.000 tick in a pulse means 12000 milli seconds
// the setup function runs once when you press reset or power the board
void setup() {
int inPin= 6;//push button
// initialize digital pin LEDs 4 for red and 5 for green as an output.
pinMode(4, OUTPUT); // consider pin 4 will be red led
pinMode(5, OUTPUT); // consider pin 5 will be green led
pinMode(inPin, INPUT);
}
int TLR=0; //Times that Loop will be Reapeted
// the loop function runs for once only!
void loop() {
while(TLR<1)
{
digitalWrite(5, HIGH); // turn the green LED on
delay(2000); // wait for 15 sec
digitalWrite(5, LOW); // turn the green LED off
digitalWrite(4, HIGH); // turn the red LED on
delay(2000); // wait for 15 sec
digitalWrite(4, LOW); // turn the red LED off
digitalWrite(5, HIGH); // turn the green LED on
delay(2000); // wait for 15 sec
digitalWrite(5, LOW); // turn the green LED off
delay(2000); // wait for 15 sec
digitalWrite(4, HIGH); // turn the red LED on
digitalWrite(5, HIGH); // turn the green LED on
delay(2000); // wait for 15 sec
digitalWrite(5, LOW);
digitalWrite(4, LOW);
TLR=TLR+1;
}
}
thats the problem : i) Program the LED (1,1) (Red diagram) and the Led (1,5) (green diagram) of the development to implement 5 complete cycles of the following sequence. Consider that the time that each green pulse is high, in the following waveforms is 15,000 clock cycles.
** idk what is (1,1 and 1,5) i just pass it...
ii) ii) Modify your program so that the green pulse does not flash when you press the A development switch