I’m very new to arduino and programming in general. I began reading a book- “Beginning C for Arduino” (by Jack Purdam) .
I have been doing somewhat ok until I got to a certain point, now i feel stuck. Screenshots of the 2 pages are attached (i hope).
basically, when I typed this code, it didn’t do anything. almost seems like IDE didn’t reconize it or I missed a step that the Author maybe assumed i should know.
I tried searching the forum for “counter” and the results seem over my head.
Let me know any more info I can give. I don’t understand the lingo yet, still trying to sort out what functions, statements, operations are… take it easy on me
counter in those examples is just a number. Most probably a variable of type int or char.
It is simply incremented at the end of the loop() function, which is called in a endless loop...
The if statement is effectively checking whether the counter variable is even or odd. (% is the modulus operator ), also in C/C++ 0 naturally converts to false, whereas any other number (positive or negative) converts to true.
pYro_65:
counter in those examples is just a number. Most probably a variable of type int or char.
It is simply incremented at the end of the loop() function, which is called in a endless loop...
The if statement is effectively checking whether the counter variable is even or odd. (% is the modulus operator ), also in C/C++ 0 naturally converts to false, whereas any other number (positive or negative) converts to true.
In your code, you have duplicated the if, they can be combined using the else explained in that article.
Also you need to declare 'counter'. I added it as a local static, however you could declare it outside the functions as a global variable (like led1, led2).
This appears to work, (no LED in pin 12, but 13 flashes fine.)
pYro_65:
In your code, you have duplicated the if, they can be combined using the else explained in that article.
Also you need to declare 'counter'. I added it as a local static, however you could declare it outside the functions as a global variable (like led1, led2).
This appears to work, (no LED in pin 12, but 13 flashes fine.)
Cool! thankyou. Another question..
why is the variable (counter) exactly the same as the (counter) in operator?
counter = counter + 1;
This question may not make sense but i'm not sure how to word it.
is not an equation. It is not an algebraic problem for you to solve. Indeed, as an algebra problem, it would be impossible to solve in any normal kind of arithmetic.
it is an assignment statement. Calculate the value on the right hand side, and assign that value to the variable on the left hand side.
is not an equation. It is not an algebraic problem for you to solve. Indeed, as an algebra problem, it would be impossible to solve in any normal kind of arithmetic.
it is an assignment statement. Calculate the value on the right hand side, and assign that value to the variable on the left hand side.