大数跨境
0
0

当乐高遇上电子 | 情人节表白终极大杀器,横扫所有年龄阶层!

当乐高遇上电子 | 情人节表白终极大杀器,横扫所有年龄阶层! DF创客社区
2018-02-11
2
导读:既有恋人的浪漫,又有家人般的温暖,百变乐高给你最两全其美的礼物!
欢迎来到服“造”的世界


DF君掐指一算

一年一度的情(nue)人(gou)节又要来啦

单身的,表白的,未婚的,已婚的

是否又在纠结送礼这个世纪难题


太日常的没有惊喜

太奢侈又得逼人卖肾

太高冷的派不上用场

颜值低了又会被嫌弃

风格太犀利又怕对方 hold 不住

......


到!底!该!送什么好?!


选择困难症患者们已濒临崩溃

再逼就只能丢红包了......



其实吧

送礼这个事儿,需要对症下药

人设是最为关键的因素

最保险的做法就是投其所好


潮男/靓女

电子控

动手达人

文艺青年

……


DF君经过左思右想

拿出了终极大杀器——Lego!

乐高自带像素画风

还可以横扫所有年龄阶层!

加上电子设计,瞬间逼格妥妥的



首先高颜值,科技范儿,够炫酷

情人节最佳表白神器



还能兼具生活实用功能

比如带音乐频谱的蓝牙播放器



*本项目作者:Mingming.Zhang

*点击文末“阅读原文”查看完整教程


乐高版蓝牙播放器

教程专区


 1. 材料清单 


 ·  32x16 RGB LED Matrix 点阵屏
 .  DFRduino Mega2560 V3.0控制器 
 .  蓝牙音频模块
 .  无源音箱小喇叭
 .  乐高积木颗粒(40粒左右)

 .  I2C颜色识别传感器 - TCS34725 (可选做拓展应用)


 2. 硬件制作 


电子部分连接图

外观用乐高积木自行DIY搭建

电源接口、下载接口细节


 3. 音频变换 


从物理科学的角度来看

音乐的本质就是一个随着时间变化的震动



如何让音乐看得见?

傅里叶变换(FFT)就派上用场啦



当音乐播放时,点阵屏将显示

在32个频域上的幅度变化


(向下滑动可查看完整代码)


音频.c代码:


#define LOG_OUT 1 // use the log output function

#define FFT_N 256 // FFT采样数:16.32.64.128.256

//#define DEBUG

#include <FFT.h> //快速傅里叶转换头文件声明

#include <Adafruit_GFX.h>   // Core graphics library

#include <RGBmatrixPanel.h> // Hardware-specific library

 

#define Cycle 3 //因为单次采样会有极大的噪音干扰,故用多次采样取平均值的方法

#define SIZE_WIDTH 32    //rgb显示宽度

//#define MAX_SPECTRUM 32 

#define GAIN 2.3

//#define FREQUENCY_INDEX(I) ((I)*3 + 10)

int Spectrum[SIZE_WIDTH];//数组记录多次采样值并在最后取平均数

// Similar to F(), but for PROGMEM string pointers rather than literals

//#define F2(progmem_ptr) (const __FlashStringHelper *)progmem_ptr

#define CLK 11 // MUST be on PORTB! (Use pin 11 on Mega)

#define LAT A3

#define OE  9

#define A   A4

#define B   A1

#define C   A2

RGBmatrixPanel matrix(A, B, C, CLK, LAT, OE, false);

const unsigned char myBitmap [] PROGMEM = {

  // 'Designbolts-Free-Valentine-Heart-Heart, 16x16px

  0x00, 0x00, 0x1c, 0x38, 0x7e, 0x7e, 0x7f, 0xfe, 0x7f, 0xfe, 0x7f, 0xfe, 0x7f, 0xfe, 0x7f, 0xfe, 

  0x3f, 0xfc, 0x1f, 0xf8, 0x1f, 0xf8, 0x0f, 0xf0, 0x03, 0xc0, 0x01, 0x80, 0x00, 0x00, 0x00, 0x00, 

};

void setup() {

   Serial.begin(115200); // use the serial port

   TIMSK0 = 0; // turn off timer0 for lower jitter - delay() and millis() killed

   ADCSRA = 0xe5; // set the adc to free running mode

   ADMUX = 0x40; // use adc0

   DIDR0 = 0x01; // turn off the digital input for adc0

 

   matrix.begin();

//           matrix.fillScreen(matrix.Color888(0, 150, 255));

//while(true);

 }

  

void loop() {

  int ave;

//  matrix.fillScreen(0);

  for (int m=0;m<SIZE_WIDTH;m++){

    Spectrum[m]=0;

  }

  for (int n=0;n<Cycle;n++){   //n记录采样次数

  //while(1) { // reduces jitter

    for (int i = 0 ; i < 512 ; i += 2) { // save 256 samples

         // cli();  // UDRE interrupt slows this way down on arduino1.0

      while(!(ADCSRA & 0x10)); // wait for adc to be ready

        ADCSRA = 0xf5; // restart adc

        byte m = ADCL; // fetch adc data

        byte j = ADCH;

         int k = (j << 8) | m; // form into an int

         k -= 0x0200; // form into a signed int

         k <<= 6; // form into a 16b signed int

         fft_input[i] = k; // put real data into even bins

         fft_input[i+1] = 0; // set odd bins to 0

       }

            // sei(); // turn interrupts back on

       // window data, then reorder, then run, then take output

       fft_window(); // window the data for better frequency response

       fft_reorder(); // reorder the data before doing the fft

       fft_run(); // process the data in the fft

       fft_mag_log(); // take the output of the fft

      /* for (byte i = 0 ; i < FFT_N/2 ; i++) 

       { 

          Serial.println(fft_log_out[i]); // <--输出到串口  

       }*/

       //Serial.write(255); // send a start byte

       //Serial.write(fft_log_out, 128); // send out the data

      }

 

 

       

      static int times = 0;

 

        if(times++ == 0){

          times=0;

                for(int m=0;m<SIZE_WIDTH;m++){

        ave=0;

        for (byte i=m*4;i<(m+1)*4;i++){

          ave+=fft_log_out[i];

        }

        ave/=4;

        ave/=2;

        Spectrum[m]=ave;

        Spectrum[m]/=Cycle;

        Serial.print(Spectrum[m]);

        Serial.print("-");

        if (m ==15)

        {

          Serial.println("||");

        }

         

          Spectrum[0] = Spectrum[1]-22;

          //Spectrum[1] = Spectrum[1]-7;

          //Spectrum[2] = Spectrum[2]-6;

          //Spectrum[3] = Spectrum[3]-6;

          

           

        int y = Spectrum[m]-8;

        if(y>26)

        y = 15;

         

        /*if(y<=7){

           

           //y = 0;

           matrix.fillScreen(0);

        }*/

         

       matrix.drawLine(m, 0, m, y, matrix.Color888(0, 150, 255));

       matrix.drawLine(m, y+1, m, 15, matrix.Color888(0, 0, 0));

      }

        }

    

}





 4. 表情制作 


先将你喜欢的表情搜罗好


点击进入取模软件

(http://javl.github.io/image2cpp/)
选择已经绘制好的图形

可更改设置或预览


然后设置数据输出格式和绘制模式

(水平或者垂直)


通过控制LED 灯的交替亮灭

形成点阵屏上的动态表情


(向下滑动可查看完整代码)


表情.c代码:


#include <Adafruit_GFX.h>

#include <Adafruit_SPITFT.h>

#include <Adafruit_SPITFT_Macros.h>

#include <gfxfont.h>

 

// testshapes demo for Adafruit RGBmatrixPanel library.

// Demonstrates the drawing abilities of the RGBmatrixPanel library.

// For 16x32 RGB LED matrix:

// [url=http://www.adafruit.com/products/420]http://www.adafruit.com/products/420[/url]

 

// Written by Limor Fried/Ladyada & Phil Burgess/PaintYourDragon

// for Adafruit Industries.

// BSD license, all text above must be included in any redistribution.

 

 

#include <RGBmatrixPanel.h> // Hardware-specific library

 

#define CLK 11  // MUST be on PORTB! (Use pin 11 on Mega)

#define LAT A4

#define OE  9

#define A   A0

#define B   A1

#define C   A2

RGBmatrixPanel matrix(A, B, C, CLK, LAT, OE, false);

 // 'Designbolts-Free-Valentine-Heart-Heart', 16x16px

const unsigned char myBitmap [] PROGMEM = {

  0xff, 0xff, 0xe3, 0xc7, 0x81, 0x81, 0x80, 0x01, 0x80, 0x01, 0x80, 0x01, 0x80, 0x01, 0x80, 0x01, 

  0xc0, 0x03, 0xe0, 0x07, 0xe0, 0x07, 0xf0, 0x0f, 0xfc, 0x3f, 0xfe, 0x7f, 0xff, 0xff, 0xff, 0xff

};

 

void setup() {

 

  matrix.begin();

  matrix.drawBitmap(0,0,myBitmap,16,16,0xff);

   

}

 

void loop() {

  // do nothing

}




点阵屏的玩法很多

你也可以自己添加更多新创意!

比如显示文字“爱的告白”

用颜色传感器进行颜色变幻

然后用乐高搭建浪漫惊喜的外观

......



当情人节遇上春节

既要有恋人的浪漫,又要家人般的温暖

希望你的礼物能两全其美

然后愉快双双把家还!



*欢迎转发朋友圈。如需转载,请注明出处和原作者。


项目干货戳这里


2017年度编辑选择奖 上篇

2017年度编辑选择奖 下篇

DIY树莓派游戏机 | 跳一跳外挂哪家强

IMA期末作业展 | 波士顿动力机器人最新视频

 Micro:bit圣诞项目合辑 | DIY迷你装载机 | Sparrow

物联网项目精选 | 最美程序媛重返维密秀 | 手相之诗

3D打印履带车 | wifi 气象站 | 极简感应灯 | lululu时钟鹿

 3D打印私有云机箱 |智能家居——Siri语音控制旋转灯

 音乐打击垫Launchpad 新加坡ITE学生作品特辑


点击“阅读原文”,查看完整教程!!!


【声明】内容源于网络
0
0
DF创客社区
我们是专注于创新和开源硬件开发的公司——DFRobot成立的创客社区,无论你是资深创客还是小白,这里都有你的一席之地。一个人玩自己的项目,你只是寂寞宅;一群人看你玩项目,你就是技术牛!快来分享你的项目吧!
内容 1282
粉丝 0
DF创客社区 我们是专注于创新和开源硬件开发的公司——DFRobot成立的创客社区,无论你是资深创客还是小白,这里都有你的一席之地。一个人玩自己的项目,你只是寂寞宅;一群人看你玩项目,你就是技术牛!快来分享你的项目吧!
总阅读1.7k
粉丝0
内容1.3k