Hello RadhikaGupta,
Your code is incomplete. There is no way to compile or test what you have poses and it poses mores questions than answers.
There is no way of telling where
button.rise(...)
comes from and the same for
cycle_ticker.attach(CycleTicker, cycle_time_interval)
. Also with the second function call is "CycleTicker" a variable or a function?
"t" is used in
void CycleTicker(void)
and "main", but where and how is it defined. Also the "void" in the () is not needed. This leads one to believe that you are being taught a very old way of coding which makes people wonder how old the compiler is.
Not understanding what
cycle_ticker.attach()
is and where you are trying to turn the LEDs on and off it makes it hard to see where the program might be going wrong.
There may be some here that have more experience working with this type of program that might have some suggestions based on what they have done and are guessing when it comes to what you did.
Most times it is better to post the whole program and all the files that make up the program along with any input files or at least a fair sample of the input file. This way people can compile and test your program and everyone will be using the same information.
For what its worth some tips:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
|
Ticker cycle_ticker;
float cycle_time_interval = 1.0;
void CycleTicker()
{
select_led(t);
t = (t % 3) + 1;
}
int main()
{
t = 1;
button.rise(onButtonPress);
while (iterations < N)
{
cycle_ticker.attach(CycleTicker, cycle_time_interval);
}
return 0;
}
|
I find this use of the {}s along with the blank lines makes the code easier to read and easy to read is more important in the end than running all your code together.
"double" is the preferred floating point type, but if your numbers are small enough a float will work.
Using a single letter for a variable name is not always a good idea. In for loops the variable is local and only lasts as long as the for loop. Otherwise give the variable a name that describes what it is or what it does. It is a great help to others and to yourself in the future when you look back at a program to see what you did.
The "return 0;" at the end of main is not necessary or required, but it makes a good place for a break point when debugging the program.
Hope that helps,
Andy