Experiments Program LED Flashing 100% working

When you first open the Arduino IDE, it will automatically appear sketch as follows:
Experiments Program LED Flashing 100% working
Experiments Program LED Flashing 100% working


void setup() {
// put your setup code here, to run once:

}

void loop() {
// put your main code here, to run repeatedly:

}

Function setup () and loop function () function is required and there should be. Function setup () is used to initialize the program, this function is only executed once when the program is first run (when arduino first turned on). While the function of the loop () will run continuously (looping forever) to Arduino is turned off.

The above program can already uploaded to the Arduino by clicking the Upload button. Only when the program is uploaded, Arduino will not do anything because the sketch is indeed no orders to do.

In this ebook, if there is a sketch that you should try, then we'll show you a sketch first, then we will explain the function and logic of the sketch. To initiate the primordial in learning the microcontroller, then you should try this sketch. Here is a sketch to make the LED blink.


    // www.ioisalman.com
   // coder ioisalman
    const int pinLED = 8;
   void setup() {
      pinMode(pinLED, OUTPUT);
  }
  void loop() {
     digitalWrite(pinLED, HIGH);
      delay(500);
       digitalWrite(pinLED, LOW);
       delay(500);
  }

Well, let us examine one by one the rows sketch above.

const int pinLED = 8;

The names of the pins on the Arduino same as it appears on the board. On one side of the board, the names of the pins is 0 to 13, and then on the other hand the names of the pins A0 to A5, and so on. Command on line 5 means: Variable pinLED are constants in the form of an integer that refers to the 8 pin Arduino board.

Please remember well, for ease of programming, initialization pins should be used as constants and are determined at the beginning of the program. Thus, for example, when we want to change the pin to be referred to, we would not be in distress. We simply change the value of the pin variables, then we do not need to repeat changing other variables.


void setup() {
pinMode(pinLED, OUTPUT);
}


PinMode function () tells that pinLED is output. Thus microcontroller will not be "read" the logic of the pin, but he will only "write" logic at the pin. In other words, if we want to define that this pin is input, then we just change into INPUT OUTPUT.


void loop() {
      digitalWrite(pinLED, HIGH);
       delay(500);
       digitalWrite(pinLED, LOW);
      delay(500);
  } 

his line is at the core of the program that will be executed during the Arduino connected to electricity or for Arduino does not reset. pinLED set HIGH means the LED will be 5 volts, whereas the mean LOW LED will apply a voltage of 0 volts. Therefore, a series of LED above will light up when given the HIGH and LOW would die when given.

Delay function () is used to stop for a millisecond. Because 1 second = 1000 milliseconds, then the introduction of a value of 500 means the Arduino will pause for half a second when the LED turns on and ½ second when the LED is off. So what if the program you're trying not to walk and error? Look, there are some that need to be considered when you are programming:


  1. Writing sketch it is case sensitive, meaning, the words "pinLED" is not synonymous with "PinLED". If an error occurs, try to see if there are any false writing?
  2. If you copy-paste sketch of the PDF file to the Arduino IDE, then it is likely there will be changes in whitespace (spaces, tabs, blank line). If a space or tab characters replaced denan blank line, the sketch will be error. Feel free to check every space, if the size of its space is different from the other spaces, please removed and replaced with a space.
  3. Each block of code must be enclosed in curly braces '{' and '}'. If parentheses less than one, then it would be an error.
  4. Every opening parenthesis '(', there should be a closing parenthesis ')'. So if it turns parentheses less, it could cause errors.
  5. Writing figures without frills coma. Suppose you want to write in 1000, it is not necessary to write with 1,000 or 1,000. Writing with 1000 error will occur, whereas if you write to 1000 will be considered first, not 1000.
  6. Each line of code will be closed with a semicolon (semicolon) ';', except at the end blokkode covered with curly braces '}'.

Subscribe to receive free email updates:

0 Response to "Experiments Program LED Flashing 100% working"

Post a Comment