For instance, the variable type int has to be in all lowercase, otherwise you will get an error.
Also, you must end every line of code with a semicolon. (unless it has parentheses or brackets) For instance,
Variables can be named whatever you want them to be.
For instance, in all examples in Jewelbot tutorials, the LED object has always been declared as led. However, you can totally declare it as whatever you want!
Programmers will often put comments next to their code to help other users understand what their code does. All comments start with "//", and are ignored by the compiler, meaning they do not affect your code.
The setup() function is called when a sketch starts. Use it to initialize variables, pin modes, etc. The setup function will only run once, after each power up or reset of the Arduino board. For example,
These are logical arithmetic statements you can implement into your program in order to control different functions or loops.
For instance, you can use these conditional statements to turn your Jewelbot into a calculator! Let's say you have variables called x and y.
You can set these variables to equal your math homework problems!
Now you can use the conditional statements to test which variable is bigger!
This is a conditional statement that performs an activity only if something specific happens.
This block of code states that if the variable x is greater than y then your Jewelbot will light up purple on LED pin 1. The second conditional states that if the variable y is greater than x then your Jewelbot will light up red on LED pin 2.
This is a conditional statement that performs an activity if something specific happens, but in any situation where that specific thing doesn't happen, then it will do something else.
This block of code programs your Jewelbot to turn the LED on pin 1 to light up purple if variable x is greater than y. Otherwise, your Jewelbot will turn the LED on pin 2 to light up red for all other conditions, without having to set up a conditional for if y is greater than x.
A loop is a sequence of instructions that continually repeats.
The loop() function does precisely what its name suggests, and loops consecutively whatever you coded your program to do over and over again!
This is different from the if-then or if-else conditionals, as this will set a conditional that causes your program to loop itself a specific amount of times.
The for loop has a set of 3 parameters. A declaration of an int, a condition for running the loop, and an increment. For instance, a for loop could start as for(int z = 0, z < 10, z++). This means that there is a variable of z with the value of 0, that will increase by 1 for as long as it is less than 10. However, the value of z will only increment when the for loop completes one cycle of the steps you programmed within it.