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:
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #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!
Referencias:
- Grove System
http://www.seeedstudio.com/wiki/Grove - Grove 3 axis accelerometer
http://www.seeedstudio.com/wiki/Grove_-_3-Axis_Digital_Accelerometer(%C2%B11.5g) - Grove Led String
http://www.seeedstudio.com/wiki/Grove_-_LED_String_Light
Leave a comment