#include

Descripción

#include se utiliza para incluir las bibliotecas externas en el programa. Esto le da al programador acceso a un amplio grupo de bibliotecas estándar de C (grupos de funciones prefabricadas), y también bibliotecas escritas especialmente para Arduino.

La página principal de referencia para las bibliotecas AVR C (AVR es una referencia a los chips Atmel en que se basa el Arduino) está aquí.

Tenga en cuenta que # include, similarmente a #define, no tiene un terminador de punto y coma, y el compilador dará lugar a mensajes de error si se agrega una.

Ejemplo

Ejemplo 1

This example includes the Servo library so that its functions may be used to control a Servo motor.

#include <Servo.h> Servo myservo; // create servo object to control a servo void setup() { myservo.attach(9); // attaches the servo on pin 9 to the servo object } void loop() { for (int pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees // in steps of 1 degree myservo.write(pos); // tell servo to go to position in variable 'pos' delay(15); // waits 15ms for the servo to reach the position } for (int pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees myservo.write(pos); // tell servo to go to position in variable 'pos' delay(15); // waits 15ms for the servo to reach the position } }

Ejemplo 2

This example includes the pitches.h file, which is placed in the same directory with the sketch (the sketch's folder).

/* * This example code is in the public domain * Tutorial page: https://arduinogetstarted.com/tutorials/arduino-piezo-buzzer */ #include "pitches.h" int melody[] = { NOTE_C4, NOTE_G3, NOTE_G3, NOTE_A3, NOTE_G3, 0, NOTE_B3, NOTE_C4 }; int noteDurations[] = { 4, 8, 8, 4, 4, 4, 4, 4 }; void setup() { for (int thisNote = 0; thisNote < 8; thisNote++) { int noteDuration = 1000 / noteDurations[thisNote]; tone(8, melody[thisNote], noteDuration); int pauseBetweenNotes = noteDuration * 1.30; delay(pauseBetweenNotes); noTone(8); } } void loop() { }

ARDUINO BUY RECOMMENDATION

Arduino UNO R3
Arduino Starter Kit
Please note: These are Amazon affiliate links. If you buy the components through these links, We will get a commission at no extra cost to you. We appreciate it.

※ OUR MESSAGES