Hola!

Si tu mujer no está cerca y te toca hacer el disfraz de cadete espacial de tu niña, es probable que te salgas un poco del molde. En mi caso fue simple; Arduino, un sensor de movimiento, un led y Visual Studio 2013.

Nota: No me canso de repetir lo útil que es Visual Micro para crear proyectos.

He aquí un video del resultado final, a medida que el sensor de movimiento “se mueve” se envía diferentes valores para el brillo de la tira de LEDs. Esto con una batería de 9V y luego me toca ponerlo dentro del disfraz de cadete espacial.

El código fuente es el siguiente:


#include <Wire.h>
#include "MMA7660.h"
MMA7660 acc;
int brightness = 0; // how bright the LED is
int ledStrip = 6; // the pin that the LED is attached to
int accelerometer = 13; // the pin that the accelerometer sensor is attached
int fadeAmount = 5; // how many points to fade the LED by
void setup()
{
acc.init();
pinMode(accelerometer, OUTPUT);
}
void loop()
{
static long cnt = 0;
static long cntout = 0;
float ax, ay, az;
int8_t x, y, z;
acc.getXYZ(&x, &y, &z);
analogWrite(ledStrip, brightness);
brightness = z;
if (brightness == 0 || brightness == 255) {
fadeAmount = -fadeAmount;
}
delay(30);
}

Importante: solo 32 líneas de código!

image

Referencias:

One response to “[#CODING4FUN] No mas disfrazes aburridos, si tienes un #Arduino, un sensor de movimiento y una tira de LEDs !!!”

  1. […] lambdas en C++ y algunas nuevas opciones de depuración! (que por cierto las puedes aprovechar para otras plataformas como Arduino o […]

    Like

Leave a comment

Discover more from El Bruno

Subscribe now to keep reading and get access to the full archive.

Continue reading