INFOSTATION CORP
  • Home
  • Gallery
  • Contact
  • About
  • Digital Goods
  • Home
  • Gallery
  • Contact
  • About
  • Digital Goods
Search

Examine an existing Arduino blink code

17/5/2019

Comments

 
Let us see inside the Blink code below. 
// the setup function runs once when you press reset or power the board
void setup() {
  // initialize digital pin LED_BUILTIN as an output.
  pinMode(LED_BUILTIN, OUTPUT);
}

// the loop function runs over and over again forever
void loop() {
  digitalWrite(LED_BUILTIN, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);                       // wait for a second
  digitalWrite(LED_BUILTIN, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);                       // wait for a second
}
There are two regular functions here, the setup() and the loop(). Let's discuss these functions.
setup function:
  • The setup function is the first function to be executed by Arduino, but it only run once.
  • Inside the setup function, it calls the built-in pinMode function. The pinMode() has two parameters, the LED_BUILTIN and OUTPUT. The LED_BUILTIN is a built-in integer constant in Arduino where it denotes the number of the pin to which the on-board LED is connected. For Arduino UNO or Mega, the default value of LED-BUILTIN is 13, while other boards have other values.
  • ​The built-in OUTPUT constant represents the pin assigned is set to be in low-impedance state. It means that it can provide enough amount of current to other circuits, typically 40 milliamps (mA) of current to other devices/circuits. This current is useful to power the common LEDs. Motors typically use greater than 40mA, where it needs either an external power to drive the power or include a transistor or other electronic circuits.
  • Note: If the pin is  connected to the ground or to power source, and the pin is configured as output, it could damage the pin or worse, it could destroy the board.  So be careful on the connection.
loop function:
  • The loop function is the next function to be executed by Arduino after the task of setup function is done.  The loop function will run again after all the tasks inside has been completed. The code in the loop will run forever until the power in the Arduino goes off or another code has been uploaded to the Arduino.
  • The digitalWrite function is a command to turn the power on or off to other component, like LED. This function  has two parameters, namely: the LED_BUILTIN and HIGH or LOW. For the HIGH constant in reference to a pin,  when a pin is configured to OUTPUT with pinMode(), and set to HIGH with digitalWrite(), the pin is 5 volts ( if the power source connected in the board is 5V) or 3.3 volts (if the power source connected in the board is 3.3V). In this state, it can drive to light the LED that is connected through a series resistor to power source (+5V or +3.3V). For the LOW constant in referene to a pin, when a pin is configured to OUTPUT with pinMode(), and set to LOW with digitalWrite(), the pin is 0 volts (both 5V and 3.3V boards). In this state it can drop the current of the light of the LED that is connected through a series resistor to power source (+5V or +3.3V).
  • The delay function pauses the program for the amount of time (in milliseconds) specified as parameter.
Note: delay() is a blocking function. Blocking function prevents a program to execute the next code until this delay function task has been completed. If you need to do several tasks without pausing to execute to the next code, then avoid using the delay() function. Instead, use millis() function with if condition as an alternative to delay() function.

​ 
​
Comments

    Noel Anonas

    Author, coder, Innovator
    email:
    ​noelqanonas@gmail.com
    My Resume
    ​Couse Outline for Java

    Picture

    Archives

    July 2019
    June 2019
    May 2019
    June 2017

    Categories

    All

    RSS Feed

    View my profile on LinkedIn
  • Home
  • Gallery
  • Contact
  • About
  • Digital Goods