LAB7
LAB7
Arquitectura de Computadoras
I. Control Remoto
Infra-Red Light
Although we humans can't see the Infra-Red light emitted from a remote control
doesn't mean we can't make it visible.
A video camera or digital photo camera can "see" the Infra-Red light as you can see
in this picture. Even the cheapest cell phones have built in cameras these days.
Simply point your remote to such a camera, press any button and you'll see the LED
flicker.
Unfortunately for us there are many more sources of Infra-Red light. The sun is the
brightest source of all, but there are many others, like: light bulbs, candles, central
heating system, and even our body radiates Infra-Red light. In fact everything that
radiates heat, also radiates Infra-Red light. Therefore we have to take some
precautions to guarantee that our IR message gets across to the receiver without
errors.
2 FF629D
3 FFE21D
4 FF22DD
5 FF02FD
6 FFC23D
7 FFE01F
8 FFA857
9 FF906F
1 FF6897
0
1 FF9867
1
1 FFB04F
2
1 FF30CF
3
1 FF18E7
4
1 FF7A85
5
1 FF10EF
6
1 FF38C7
7
1 FF5AA5
8
1 FF42BD
9
2 FF4AB5
0
2 FF52AD
1
void setup() {
pinMode(ledPin, OUTPUT);
pinMode(buttonPin, INPUT);
void loop(){
buttonState = digitalRead(buttonPin);
if (buttonState == HIGH) {
digitalWrite(ledPin, HIGH);
else {
digitalWrite(ledPin, LOW);
}
Usando el mismo circuito le agregamos la librería IRremote, que nos servirá para detectar
las teclas que se están presionando. He aquí el código.
#include "IRremote.h"
Serial.begin(9600);
Serial.println("IR Receiver Raw Data + Button Decode Test");
translateIR();
switch(results.value)
{
case 0xFFA25D:
break;
case 0xFF629D:
Serial.println(" CH ");
break;
case 0xFFE21D:
break;
case 0xFF22DD:
break;
case 0xFF02FD:
break;
case 0xFFC23D:
break;
case 0xFFE01F:
break;
case 0xFFA857:
break;
case 0xFF906F:
Serial.println(" EQ ");
break;
case 0xFF6897:
Serial.println(" 0 ");
break;
case 0xFF9867:
break;
case 0xFFB04F:
break;
case 0xFF30CF:
Serial.println(" 1 ");
break;
case 0xFF18E7:
Serial.println(" 2 ");
break;
case 0xFF7A85:
Serial.println(" 3 ");
break;
case 0xFF10EF:
Serial.println(" 4 ");
break;
case 0xFF38C7:
Serial.println(" 5 ");
break;
case 0xFF5AA5:
Serial.println(" 6 ");
break;
case 0xFF42BD:
Serial.println(" 7 ");
break;
case 0xFF4AB5:
Serial.println(" 8 ");
break;
case 0xFF52AD:
Serial.println(" 9 ");
break;
default:
delay(500);
} //END translateIR
*/
#include "IRremote.h"
#define REPEAT_DELAY 500 // Delay before checking for another button / repeat
Serial.begin(9600);
ButtonValue = translateIR();
Serial.println(ButtonValue, DEC);
switch(results.value)
case 0xFFA25D:
break;
case 0xFF629D:
return 11; // CH
break;
case 0xFFE21D:
break;
case 0xFF22DD:
break;
case 0xFF02FD:
break;
case 0xFFC23D:
break;
case 0xFFE01F:
break;
case 0xFFA857:
break;
case 0xFF906F:
return 18; // EQ
break;
case 0xFF6897:
return 0; // ZERO
break;
case 0xFF9867:
break;
case 0xFFB04F:
break;
case 0xFF30CF:
return 1; // 1 etc.. to 9
break;
case 0xFF18E7:
return 2;
break;
case 0xFF7A85:
return 3;
break;
case 0xFF10EF:
return 4;
break;
case 0xFF38C7:
return 5;
break;
case 0xFF5AA5:
return 6;
break;
case 0xFF42BD:
return 7;
break;
case 0xFF4AB5:
return 8;
break;
case 0xFF52AD:
return 9; // 9
break;
case 0xFFFFFFFF:
break;
default:
} //END case
} //END translateIR
El ejemplo producido puede modificarse, pero esta vez manejando un led conectado al pin
13, que parpadeara n veces (de acuerdo al número devuelto por el código de la tecla).
/*
IR Remote Kit Test: Blinks Pin 13 when numeric buttons pressed
http://arduino-direct.com/sunshop/index.php?l=product_detail&p=153
based on code by Ken Shirriff - http://arcfn.com
[email protected] */
{
// Serial.println(results.value, HEX); // UN Comment to see raw values
ButtonValue = translateIR();
Serial.println(ButtonValue, DEC);
BlinkNum(ButtonValue); // Blink Pin 13 LED
delay(REPEAT_DELAY); // Adjust for repeat / lockout time
irrecv.resume(); // receive the next value
}
}/* --(end main loop )-- */
switch(results.value)
case 0xFFA25D:
return 10; // CH-
break;
case 0xFF629D:
return 11; // CH
break;
case 0xFFE21D:
return 12; // CH+
break;
case 0xFF22DD:
return 13; // PREV
break;
case 0xFF02FD:
return 14; // NEXT
break;
case 0xFFC23D:
return 15; // PLAY/PAUSE
break;
case 0xFFE01F:
return 16; // VOL-
break;
case 0xFFA857:
return 17; // VOL+
break;
case 0xFF906F:
return 18; // EQ
break;
case 0xFF6897:
return 0; // ZERO
break;
case 0xFF9867:
return 100; // 100+
break;
case 0xFFB04F:
return 200; // 200+
break;
case 0xFF30CF:
return 1; // 1 etc.. to 9
break;
case 0xFF18E7:
return 2;
break;
case 0xFF7A85:
return 3;
break;
case 0xFF10EF:
return 4;
break;
case 0xFF38C7:
return 5;
break;
case 0xFF5AA5:
return 6;
break;
case 0xFF42BD:
return 7;
break;
case 0xFF4AB5:
return 8;
break;
case 0xFF52AD:
return 9; // 9
break;
case 0xFFFFFFFF:
return -2; // REPEAT: Button Held down longer than
break;
default:
return -1; // Other Button / Bad Code
} //END case
} //END translateIR
/*
*/
#include "IRremote.h"
Serial.begin(9600);
translateIR();
switch(results.value)
default:
Serial.println(" other button ");
} //END translateIR
II. I2C
Otros acelerómetros se pueden centrar en torno materiales piezoeléctricos.
Generan pequeña carga eléctrica de salida en la estructura cristalinas cuando
se coloca bajo tensión mecánica (por ejemplo aceleración).
Para la mayoría de los acelerómetros , las conexiones básicas que se
requieren para la operación son el poder y las líneas de comunicación. Como
siempre, leer la hoja de datos para una correcta conexión.
Out of the box, the ADXL345 is an I2C 3-axis accelerometer with user
selectable sensitivity and 10-13 bit resolution (depending on sensitivity).
And… It is pretty decent all around, but were not really going to spend much
time talking about boring stuff today. Today, we are talking about getting the
special features of the ADXL345 up and running. (tap, double tap, free fall,
activity and inactivity)
These special detection features have the ability to trigger 2 interrupt pins,
making the pin go HIGH the moment one of the events is sensed. You can
select what events to watch for, and what interupt pin to trigger when it is
sensed (I had issues with INT2, it would not reset). You can take these
interrupt pins and connect them to your Arduino to trigger an interrupt. An
interrupt, when sensed on the Arduino, pauses the system instantly, even if it
is in the middle of something, and responds to that interrupt how ever you
have it setup before returning to the normal code. Like a police officer
coming down the street with its lights on… Even if you have a green light, you
stop and let them go. But using interrupts is a little beyond the scope of this
article, so we are going to just keep checking for these actions in code and
respond to them when we see them.
Circuito
#include <Wire.h>
#include <ADXL345.h>
void setup(){
Serial.begin(9600);
Serial.println("Inicio de medicion");
adxl.powerOn();
adxl.setActivityX(1);
adxl.setActivityY(1);
adxl.setActivityZ(1);
adxl.setInactivityX(1);
adxl.setInactivityY(1);
adxl.setInactivityZ(1);
adxl.setTapDetectionOnX(0);
adxl.setTapDetectionOnY(0);
adxl.setTapDetectionOnZ(1);
//set values for what is a tap, and what is a double tap (0-255)
adxl.setInterruptMapping( ADXL345_INT_SINGLE_TAP_BIT,
ADXL345_INT1_PIN );
adxl.setInterruptMapping( ADXL345_INT_DOUBLE_TAP_BIT,
ADXL345_INT1_PIN );
adxl.setInterruptMapping( ADXL345_INT_FREE_FALL_BIT,
ADXL345_INT1_PIN );
adxl.setInterruptMapping( ADXL345_INT_ACTIVITY_BIT,
ADXL345_INT1_PIN );
adxl.setInterruptMapping( ADXL345_INT_INACTIVITY_BIT,
ADXL345_INT1_PIN );
void loop(){
int x,y,z;
adxl.readAccel(&x, &y, &z); //read the accelerometer values and store them
in variables x,y,z
// Output x,y,z values - Commented out
// Serial.print(x);
// Serial.print(y);
// Serial.println(z);
//Fun Stuff!
//so do not call again until you need to recheck for triggered actions
// freefall
if(adxl.triggered(interrupts, ADXL345_FREE_FALL)){
Serial.println("freefall");
//inactivity
if(adxl.triggered(interrupts, ADXL345_INACTIVITY)){
//Serial.println("inactivo");
Serial.println("Que aburrido, sin hacer nada..");
//activity
if(adxl.triggered(interrupts, ADXL345_ACTIVITY)){
//Serial.println("actividad");
//double tap
if(adxl.triggered(interrupts, ADXL345_DOUBLE_TAP)){
//Serial.println("doble golpe");
//tap
if(adxl.triggered(interrupts, ADXL345_SINGLE_TAP)){
//Serial.println("golpe");
Serial.println("Auu! me dolio!!");
//add code here to do when a tap is sensed
Giroscopio
Los giroscopios miden la velocidad angular, la forma casi algo está girando
sobre el eje. Si se está tratando de controlar la orientación de un objeto en
movimiento en el acelerómetro junio no le dan suficiente información para
saber exactamente cómo se orienta. A diferencia de los acelerómetros
giroscopios no se ven afectadas por la gravedad, por lo que hacen un gran
complemento a unos de otros. Por lo general, usted verá velocidad angular
representado en unidades de revoluciones por minuto (RPM), o grados por
segundo (° / s). Los tres ejes de giro o son referenciados como x, y, z,
Codigo:
#include <Wire.h>
int y;
int z;
void setup(){
Wire.begin();
Serial.begin(9600);
Serial.println("iniciando L3G4200D");
void loop(){
Serial.print("X:");
Serial.print(x);
Serial.print(" Y:");
Serial.print(y);
Serial.print(" Z:");
Serial.println(z);
delay(100); //Just here to slow down the serial to make it more readable
void getGyroValues(){
// If you'd like to adjust/use the HPF, you can edit the line below to
configure CTRL_REG2:
if(scale == 250){
// if you'd like:
int v;
Wire.beginTransmission(deviceAddress);
Wire.endTransmission();
Wire.requestFrom(deviceAddress, 1); // read a byte
while(!Wire.available()) {
// waiting
v = Wire.read();
return v;
Compass
Codigo
#include <Wire.h>
#include <HMC5883L.h>
HMC5883L compass;
void setup(){
Serial.begin(9600);
Wire.begin();
void loop(){
Serial.println(heading);
}
void setupHMC5883L(){
int error;
float getHeading(){
//Get the reading from the HMC5883L and calculate the heading