You are on page 1of 28

ARDUINO BASICO

Leobardo Trujillo Vieyra

Arduino de tipo serial

Arduino de tipo USB

Diagrama esquemtico

Tabla comparativa

Comentarios
// Blink LED sketch /* Arduino Blink LED Sketch */

Parameters
Microcontroller ATmega328 Operating Voltage 5V Input Voltage (recommended) 7-12V Input Voltage (limits) 6-20V Digital I/O Pins 14 (of which 6 provide PWM output) Analog Input Pins 6 DC Current per I/O Pin 40 mA DC Current for 3.3V Pin 50 mA Flash Memory 32 KB (ATmega328) of which 0.5 KB used by bootloader SRAM 2 KB (ATmega328) EEPROM 1 KB (ATmega328) Clock Speed 16 MHz

The Setup Function


void setup() { } This function contains a set of instructions for the Arduino to execute once only, each time it is reset or turned on. Use it to initialize variables, pin modes, start using libraries, etc. The setup function will only run once, after each powerup or reset of the Arduino board.

The Loop Function


void loop() { // place your main loop code here: }

Delay
delay(250); // pause for one-quarter of one second The time is in miliseconds

/* Arduino Blink LED Sketch */ void setup() { pinMode(13, OUTPUT); // set digital pin 13 to output } void loop() { digitalWrite(13, HIGH); // turn on digital pin 13 delay(1000); // pause for one second digitalWrite(13, LOW); // turn off digital pin 13 delay(1000); // pause for one second }

STRUCTURE
An Arduino program run in two parts: void setup() void loop() setup() is preparation, and loop() is execution. In the setup section, always at the top of your program, you would set pinModes, initialize serial communication, etc. The loop section is the code to be executed -- reading inputs, triggering outputs, etc. Variable Declaration Function Declaration void

Control Structures
if if...else for switch case while do... while break continue return

Further Syntax
;(semicolon) {}(curly braces) //(single line comment) /* */(multi-line comment)

Arithmetic Operators
+ (addition) -(subtraction) *(multiplication) /(division) %(modulo)

Comparison Operators
==(equal to) !=(not equal to) <(less than) >(greater than) <=(less than or equal to) >=(greater than or equal to)

Boolean Operators
&&(and) ||(or) !(not)

Compound Operators
++(increment) --(decrement) +=(compound addition) -=(compound subtraction) *=(compound multiplication) /=(compound division)

Bitwise Operators
&(bitwise and) |(bitwise or) ^(bitwise xor) ~(bitwise not) <<(bitshift left) >>(bitshift right)

VARIABLES
Variables are expressions that you can use in programs to store values, such as a sensor reading from an analog pin.

Constants
Constants are particular values with specific meanings. HIGH| LOW INPUT| OUTPUT true| false Integer Constants

Data Types
Variables can have various types, which are described below. boolean char byte int unsigned int long unsigned long float double string array

FUNCTIONS
Digital I/O pinMode(pin, mode) digitalWrite(pin, value) int digitalRead(pin)

Analog I/O int analogRead(pin) analogWrite(pin, value) - PWM Advanced I/O shiftOut(dataPin, clockPin, bitOrder, value) unsigned long pulseIn(pin, value)

Time unsigned long millis() delay(ms) delayMicroseconds(us) Math min(x, y) max(x, y) abs(x) constrain(x, a, b) map(value, fromLow, fromHigh, toLow, toHigh) pow(base, exponent) sqrt(x)

Trigonometry sin(rad) cos(rad) tan(rad) Random Numbers randomSeed(seed) long random(max) long random(min, max)

Serial Communication
Used for communication between the Arduino board and a computer or other devices. This communication happens via the Arduino board's serial or USB connection and on digital pins 0 (RX) and 1 (TX). Thus, if you use these functions, you cannot also use pins 0 and 1 for digital i/o. Serial.begin(speed) int Serial.available() int Serial.read() Serial.flush() Serial.print(data) Serial.println(data)

Variable Scope & Qualifiers

static volatile const PROGMEM

Interrupts
interrupts() noInterrupts()
Utilities

cast(cast operator) sizeof() (sizeof operator)

You might also like