You are on page 1of 27

ARDUINO Y FABRICACIÓN DIGITAL

PRÁCTICA II – ENTRADAS Y SALIDAS ANALÓGICAS


Por Juan Felipe Saldarriaga Colorado
juanf.saldarriaga@upb.edu.co
AGENDA – PRÁCTICA II
1. Entrada/Salida digital
2. Conceptos de programación
3. Entradas analógicas
4. Salidas PWM y comunicación serial
5. Entrega Informe taller I.
PLANEACIÓN GENERAL DEL TALLER
Práctica #1: El circuito eléctrico
Práctica #2: Analog I/O
Práctica #3: El Condicional
Práctica #4: Taller de soldadura en electrónica
Práctica #5: Control de motores DC
Práctica #6: Fabricación del controlador
Práctica #7: Detección de línea y detección de objetos
Práctica #8: Reto con los robots
PRÁCTICA ENTRADA/SALIDA DIGITAL
Montaje, ejemplo, código y tarea
Tarea Entrada/Salida Digital
A partir del programa básico, generar las siguientes variaciones:
1. Agregar un botón adicional para controlar un segundo led.
2. Agregar comentarios explicando cada línea de código.
CONCEPTOS DE PROGRAMACIÓN
Bibliografía, recomendaciones, IDE de Arduino, Programming languages,
programming steps, aplicación básica de Arduino, comentarios y librería de
funciones.
BIBLIOGRAFÍA
Beginning C for Arduino, is written
for those who have no prior
experience with microcontrollers or
programming but would like to
experiment and learn both.
With projects and Arduino boards,
this book introduces you to the C
programming language, reinforcing
each programming structure with a
simple demonstration of how you
can use C to control the Arduino
family of microcontrollers.
www.apress.com/us/book/9781484209417
RECOMENDACIONES INICIALES
1. You must take the time to type in the sample programs and run
them yourself.
2. Mentally telling yourself “I got that!” and actually writing your own
program to implement the concept are two entirely different things.
3. You’ll have a temptation to skip the basics and find out why your
project isn’t working. Don’t. You need a strong foundation to build a
solid understanding.
THE ARDUINO IDE
An IDE is a single program that combines all of the functions required
to progress from the C language source code you are writing to an
executable program.
The better you understanding what is going on with the language, the
quicker you will be able to detect, isolate, and fix program bugs.
A little depth of understanding frequently yields a more efficient and
unbreakable, yet elegant, solution.
The Building Blocks of All Programming
Languages
Expressions: An expression is created by combining operands and
operators. An operand is typically a piece of data. An operator is often a
mathematical or logical action.
a+b m – 3000 g<d
Statements: A statement is a complete C instruction for the computer.
All C statements end with a semicolon (;).
i = 50; a = b + c; m = d / 2;
The semicolon at the end of the statement that tells the compiler it has
all the intermediate expressions it needs to resolve the statement.
The Building Blocks of All Programming
Languages (Cont.)
Statement blocks: A statement block
consists of one or more statements grouped
together so they are viewed by the compiler
as though they are a single statement.
Statement blocks start with an opening
brace character { and end with a closing
brace character }.
Function blocks: A function block is a block
of code that is designed to accomplish a
single task.
APLICACIÓN BÁSICA DE ARDUINO
Initialization: this element contains all the variables and values that will
be used throughout the program.
Setup() statement: code within that statement runs once when the
application first starts up. All applications must have a setup() method,
even if nothing is done in them.
Loop() statement: runs over and over again. Usually we want to check
any values that might be input from a control or another program,
determine what to do with the input, and then send any information or
instructions to any other components or programs that might need
them.
COMENTARIOS
Comment lines are used to document what’s going on in a program for
whomever may be reading the code. There are two basic types of
comments: single-line and multi-line.
Single-line comments begin with a pair of slash ( // ) characters. There
can be no spaces between the two slashes.
Multi-line comments begin with a slash-asterisk pair ( /* ) and end with
an asterisk-slash pair ( */ ).
Comments should be used any time you wish to document what a
program is doing or about to do.
FUNCIONES ARDUINO C

pinMode(pin, mode) / INPUT - OUTPUT


digitalWrite(pin, value) / HIGH - LOW
delay(ms) / 0 – 4.292’967.295
int digitalRead(pin)
Fuente: mechatronics.colostate.edu/figures/6-1.jpg

PRÁCTICA ENTRADA ANALÓGICA


Montaje, ejemplo, código y tarea
Montaje Entrada analógica
Ejemplo Entrada analógica
Código Entrada analógica
Tarea Entrada analógica
A partir de la práctica básica,
generar las siguientes variaciones:
1. Conectar dos leds con
resistencias a pines diferentes.
2. Modificar el programa para
controlar los dos leds.
3. Agregar comentarios
explicando las líneas de código
agregadas.
MONTAJE
SALIDA PWM Y
COMUNICACIÓN
SERIAL
Montaje, ejemplo y código

Fuente: fabricadigital.org/leccion/salidas-analogicas-pwm
Montaje Salida PWM y comunicación serial
Ejemplo Salida PWM y comunicación serial
Programa
Salida PWM y
comunicación
serial

Práctica: agregar un segundo


led que tenga
comportamiento inverso al
anterior.
Entrada: 0 – 1023
Salida: 0 - 255
PRÁCTICA DE CLASE I
Escribir un programa desde cero para cambiar el volumen del buzzer
con el potenciómetro.
1. Declarar las constantes y variables e inicializarlas.
2. Configurar pines de entrada y salida.
3. Leer el sensor.
4. Mapear la entradas.
5. Escribir el resultado en la salida.
PRÁCTICA DE CLASE II
Un equipo de sonido tiene una perilla para controlar el volumen y 3 indicadores luminosos (LED)
dispuestos uno tras otro en una línea recta, en la medida que el valor del potenciómetro va
aumentando al girarlo, se va encendiendo el LED1, luego el LED2 hasta el LED3.
Si se llega al valor de 1023 todos los LED deberían estar prendidos y si comienzas a girar el
potenciómetro en sentido contrario se van apagando los LED uno tras otro en el sentido inverso en
que se encendieron, al final en el valor 0 todos los LED deben estar apagados.
Fuente: Guía básica de Arduino por aprender.tdrobotica.co
Tarea Entrada analógica
A partir de la práctica básica,
generar las siguientes variaciones:
1. Conectar dos leds con
resistencias a pines diferentes.
2. Conectar un potenciómetro
adicional.
3. Modificar el programa para
controlar cada led con un
potenciómetro diferente.
4. Agregar comentarios explicando
las líneas de código agregadas.
ARDUINO Y FABRICACIÓN DIGITAL
PRÁCTICA II – ENTRADAS Y SALIDAS ANALÓGICAS
Por Juan Felipe Saldarriaga Colorado

You might also like