Line comment //: Anything written after the // is not used by the program and they are optional. They are also be found separating elements in a for loop. Missing a semicolon will also produce an error while compiling the code. Semicolon : Are used to define the end of a statement. Example:Ĭurly braces otherwise the code will produce an error when compiling. PinMode(Pin, Mode): The Pin can be any physical pin on the Arduino, you can use Pin number like 1, 2, 3 etc… or you can use the variable name assigned to this pin, example LED1, pinLed, etc… The Mode is OUTPUT or INPUT in capital letters. INPUT is used to prepare the pin to receive information from a connected device like a sensor. OUTPUT means that this pin will produce a result like turning on or off an LED. The job of the pinMode statement is to set the Arduino pins to OUTPUT or INPUT. Within this function there is a statement called pinMode(). We already established that the void setup() is a function that runs only once at the beginning of the sketch. PinMode(13, OUTPUT) // initialize digital pin 13 as an output.ĭigitalWrite(13, HIGH) // turn the LED on (HIGH is the voltage level)ĭigitalWrite(13, LOW) // turn the LED off by making the voltage LOW You will need and Arduino, a solder less bread board, an LED, and two jumper wires.Ĭonnect the short –ve prong of the LED to the GND on the Arduino and the long +ve prong to PIN 13 on the Arduino. It can be found in File then Examples then 01.Basics and select Blink. To follow this example, load the blink sketch from the Arduino IDE. ![]() In this example I will introduce you to three statements that will be used in almost all Sketches. You can also call upon local and global variables as well as other functions. The functions in the void loop() usually manipulates the Arduino’s I/Os, example: Write a HIGH or LOW to a certain pin, and the data collected from them, example: Change the temperature sensor value from Celsius to Fahrenheit. The void loop() is a function that executes indefinitely until you power off the Arduino. There are other statements that can be included in the void setup(),the above functions were only examples, but the important thing is to remember that the setup() is a statement that runs only once at the beginning of the sketch. Or to start the serial monitor example: serial.begin(9600) It usually contains statements that set the pin modes on the Arduino to OUTPUT and INPUT, example: The void setup() is the first function to be executed in the sketch and it is executed only once. ![]() The sketch will not compile without either one. ![]() It is important to understand this code structure because every Arduino sketch will contain a void setup() and a void loop() functions even if they are empty. put your main code here, to run repeatedly:Įssentially this is a complete code, it complies and can be uploaded to the Arduino but there is nothing in this code. ![]() put your setup code here, to run once: To load the most basic Arduino sketch, open the Arduino IDE click on file then examples then 01.Basics and select the BareMinimum.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |