Maker Pro
Maker Pro

How to use switch statement

vead

Nov 27, 2011
473
Joined
Nov 27, 2011
Messages
473
Good. Now you need to find a delay() function that can supply our time periods.
Usually, delay(1000); will wait for 1 second (1000 ms).
Having a function such as delay() makes it much easier to get accurate timing than
trying to use for loops, because the for loop can vary with processor speed, load, etc.

For step 1, you want to turn the LED1 on, then off, every 1/4 second, for 10 seconds.

for total_time = 1 to 10 # total time for step 1 in seconds
for one_second = 1 to 4 # number of times required to blink for one second


turn off LED1; #how you do this is hardware dependent
delay(125); #wait 1/8 second

// each time thru this loop will take 250 ms or 1/4 second.
// so you need to do it 4 times to add up to 1 second

end for one_second
end for total_time

Steps 2 and 3 would work in the same way - but no good programmer would simply write three copies of his code, and change the numbers. Ask why not.
I tried to understand your explanations but sorry I couldn't understand
turn on LED1; #how you do this is hardware dependent
delay(125); #wait 1/8 second (125 ms)
I understand meaning of above two line. you are making LED on for 125ms
turn off LED1; #how you do this is hardware dependent
delay(125); #wait 1/8 second
same, you are making LED off for 125 seconds

I don't understand how is explanations related to my question. Its very good for me if you can make some hand made code or algorithm to understand basics. so that I can try to fix issues. I am not getting what are you doing.

Code:
#include <REG51.h>
#define

void main()
{
 
    while (1)
    {
       
     //write your code here
    }
}
 
Last edited:

pmwelec

Jul 6, 2017
3
Joined
Jul 6, 2017
Messages
3
I haven't the time to read through the code but could I suggest you use some good old fashioned debugging. You can use a puts() statement to output to screen which stattements are executed and hence track the logic flow
 
Top