Led Controlled By 3d Gesture Sensor

Made by DoYouKnowArduino

About the project

I tried controlling the display of flexible LED matrix with 3D gesture sensor. By H0meMadeGarbage

Project info

Difficulty:

Estimated time:

5 days

Published:

11th May 2018

Items used in this project


Hardware components

DFRobot 3D Gesture Sensor

x 1
DFRobot Flexible 8x8 RGB LED Matrix

x 1
Arduino UNO & Genuino UNO

x 1

Software app and online services

Arduino IDE

Story


I tried controlling the display of flexible LED matrix with 3D gesture sensor.

Configuration

Display the eye on the LED matrix and move with the 3D gesture sensor.

Flexible 8x8 RGB LED Matrix

It has a 8x8 full color LED (NeoPixel) and soft by flexible board. The Arduino library for Neopixels is located in the following.

https://github.com/adafruit/Adafruit_NeoPixel

Please refer below for product details.

https://www.dfrobot.com/wiki/index.php/3D_Gesture_Sensor_Mini_SKU:_SEN0202

Arduino Programming

Display the eyeball on the LED matrix, move the eyes right and left with the left and right sensing of the gesture sensor, open and close the eyelids by vertical sensing. The pupil faces the front in clockwise or counterclockwise sensing.

LED Array:

Code:

#include <Adafruit_NeoPixel.h>

#include <DFRobot_Gesture.h>

#include <Wire.h>

int sensePin= A1;

unsigned char cmd;

DFRobot_Gesture myGesture;

#define DIN A0

Adafruit_NeoPixel led = Adafruit_NeoPixel(64, DIN, NEO_GRB + NEO_KHZ800);

int LR = 5;

int eyelid = 0;

int whiteNum = 52;

int blackNum = 20;

int pupilNum = 12;

//white eye

int whiteLED[52] = { 2, 3, 4, 5, 9, 10, 11, 12, 13, 14, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,

32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 49, 50, 51, 52, 53, 54, 58, 59, 60, 61};

//black eye

int blackLED[11][20] = {{50, 51, 52, 53, 58, 61, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64},

{42, 43, 44, 45, 49, 50, 53, 54, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64},

{34, 35, 36, 37, 41, 42, 45, 46, 49, 54, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64},

{26, 27, 28, 29, 33, 34, 37, 38, 41, 46, 54, 49, 58, 61, 61, 64, 64, 64, 64, 64},

{18, 19, 20, 21, 25, 26, 29, 30, 33, 38, 41, 46, 49, 50, 53, 54, 58, 59, 60, 61},

{10, 11, 12, 13, 17, 18, 21, 22, 25, 30, 33, 38, 41, 42, 45, 46, 50, 51, 52, 53},

{ 2, 3, 4, 5, 9, 10, 13, 14, 17, 22, 25, 30, 33, 34, 37, 38, 42, 43, 44, 45},

{ 2, 5, 9, 14, 17, 22, 25, 26, 29, 30, 34, 35, 36, 37, 64, 64, 64, 64, 64, 64},

{ 9, 14, 17, 18, 21, 22, 26, 27, 28, 29, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64},

{ 9, 10, 13, 14, 18, 19, 20, 21, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64},

{ 2, 5, 10, 11, 12, 13, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64}};

//pupil

int pupilLED[11][12] = {{59, 60, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64},

{51, 52, 58, 59, 60, 61, 64, 64, 64, 64, 64, 64},

{43, 44, 50, 51, 52, 53, 58, 59, 60, 61, 64, 64},

{35, 36, 42, 43, 44, 45, 50, 51, 52, 53, 59, 60},

{27, 28, 34, 35, 36, 37, 42, 43, 44, 45, 51, 52},

{19, 20, 26, 27, 28, 29, 34, 35, 36, 37, 43, 44},

{11, 12, 18, 19, 20, 21, 26, 27, 28, 29, 35, 36},

{ 3, 4, 10, 11, 12, 13, 18, 19, 20, 21, 27, 28},

{ 2, 3, 4, 5, 10, 11, 12, 13, 19, 20, 64, 64},

{ 2, 3, 4, 5, 11, 12, 64, 64, 64, 64, 64, 64},

{ 3, 4, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64}};

//eyelid

int eyelidNum[8] = {0,4,8,14,20,28,36,44};

int eyelidLED[56] = {23, 24, 39, 40, 22, 25, 38, 41, 9, 21, 26, 37, 42, 54, 10, 20, 27, 36, 43, 53, 5, 11,

19, 28, 35, 44, 52, 58, 4, 12, 18, 29, 34, 45, 51, 59, 3, 13, 17, 30, 33, 46, 50, 60};

void setup(){

Wire.begin(); // join i2c bus (address optional for master)

Serial.begin(115200); // start serial for output

pinMode(sensePin, INPUT);

led.begin();

led.setBrightness(100); //LED brightness 0-255

blink(LR, eyelid);

}

void loop(){

if(digitalRead(sensePin)==0){

myGesture.I2C1_MasterRead(md.buf,26,0x42); //The address is:0x42

cmd = myGesture.mgcProcMsg(); //process the message

if(cmd != GI_NOGESTURE ){

switch(cmd){

case GI_FLICK_R:

Serial.println("RIGHT");

//Move the eye right

for(int i = LR; i <= 10; i++){

blink(i, eyelid);

delay(100);

}

LR = 10;

break;

case GI_FLICK_L:

Serial.println("LEFT");

//Move the eye left

for(int i = LR; i >= 0; i--){

blink(i, eyelid);

delay(100);

}

LR = 0;

break;

case GI_FLICK_D:

Serial.println("DOWN");

//Eyelid close

for(int i = eyelid; eyelid <= 8; eyelid++){

blink(LR, eyelid);

delay(100);

}

eyelid = 8;

break;

case GI_FLICK_U:

Serial.println("UP");

//Eyelid open

for(int i = eyelid; eyelid >= 0; eyelid--){

blink(LR, eyelid);

delay(100);

}

eyelid = 0;

break;

case GI_AIRWHEEL_CW://Clockwise in circles

Serial.println("CW");

//Return eye to the front

Return();

break;

case GI_AIRWHEEL_CCW://Counterclockwise circles

Serial.println("CCW");

//Return eye to the front

Return();

break;

default: break;

}

}

}

}

void blink( int LR, int eyelid) {

if (eyelid != 8){

//white eye

for(uint16_t i=0; i<whiteNum; i++) {

led.setPixelColor(whiteLED[i], led.Color(66, 66, 66));

}

//black eye

for(uint16_t i=0; i<blackNum; i++) {

led.setPixelColor(blackLED[LR][i], led.Color(0, 177, 55));

}

//pupil

for(uint16_t i=0; i<pupilNum; i++) {

led.setPixelColor(pupilLED[LR][i], led.Color(0, 0, 66));

}

//eyelid

for(int i=0; i < eyelidNum[eyelid]; i++) {

led.setPixelColor(eyelidLED[i], 0);

}

} else if (eyelid == 8){

led.clear();

}

led.show();

}

void Return() {

if(LR == 0){

for(int i = LR; i <= 5; i++){

blink(i, eyelid);

delay(100);

}

}

if(LR == 10){

for(int i = LR; i >= 5; i--){

blink(i, eyelid);

delay(100);

}

}

LR = 5;

}

Operation

Credits


DoYouKnowArduino

Offering quality microcontroller, shield, sensors, electronic components, iot gateway/node and robot kit with arduino, lattepanda, raspberry pi and intel edison/cuire/joule.


Leave your feedback...