DF has calculated
The annual Valentine’s Day is coming!
Singles, confessors, unmarried, married
Are you struggling with the gift dilemma of the century?
Too ordinary with no surprises
Too extravagant and forces one to sell a kidney
Too aloof to be useful
Low beauty will be disliked
Style too sharp and afraid the other can’t handle it
……
What on earth should I give?!
Those with difficulty in choosing are on the verge of collapse
If pushed, they can only give red envelopes…
Actually,
giving gifts needs to be targeted
Character is the key factor
The safest approach is to cater to their preferences
Trendy guys/beautiful girls
Electronics enthusiasts
Hands-on experts
Artisticyouth
……
After much thought,
I have come up with the ultimate weapon—Lego!
LEGO comes with a pixel art style
and can appeal to all age groups!
With electronic design, it instantly elevates the class!
First, it has high aesthetics, a tech vibe, and is cool enough
the best confession tool for Valentine’s Day!
It can also serve practical life functions
such as a Bluetooth speaker with music spectrum!
*Project Author: Mingming.Zhang
*Click on “Read the original text” at the end to see the complete tutorial
LEGO Bluetooth Speaker
Tutorial Area
1. Material List
· 32×16 RGB LED Matrix . DFRduino Mega2560 V3.0 controller . Bluetooth audio module . Passive speaker . LEGO bricks (about 40 pieces)
. I2C color recognition sensor – TCS34725 (optional for extension applications)
2. Hardware Production
Electronic connection diagram
Appearance DIY build with LEGO bricks
Power interface, download interface details
3. Audio Transformation
From the perspective of physical science,
the essence of music is a vibration that changes over time
How to make music visible?
Fourier transformation (FFT) comes into play
When the music plays, the matrix screen will display
the amplitude changes across 32 frequency domains
(Scroll down to see the complete code)
Audio.c code:
#define LOG_OUT 1 // use the log output function
#define FFT_N 256 // FFT sampling number: 16.32.64.128.256
//#define DEBUG
#include <FFT.h> // Fast Fourier Transform header file declaration
#include <Adafruit_GFX.h> // Core graphics library
#include <RGBmatrixPanel.h> // Hardware-specific library
#define Cycle 3 // Use multiple samples to average due to significant noise interference in single samples
#define SIZE_WIDTH 32 // RGB display width
//#define MAX_SPECTRUM 32
#define GAIN 2.3
#define FREQUENCY_INDEX(I) ((I)*3 + 10)
int Spectrum[SIZE_WIDTH];// Array records multiple sample values and averages at last
// 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 records the number of samples
//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]); // <–output to serial
}*/
//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. Emoji Production
First, gather your favorite emojis
Click to enter the modeling software
(http://javl.github.io/image2cpp/) select the already drawn graphics
Settings can be changed or previewed
Then set the data output format and drawing mode
(horizontal or vertical)
By controlling the LED lights to alternately turn on and off,
dynamic emojis can be formed on the matrix screen
(Scroll down to see the complete code)
Emoji.c code:
#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 16×32 RGB LED matrix:
// [url=http://www.adafruit.com/products/420]http://www.adafruit.com/products/420[/p>
// 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
}
The matrix display has many ways to play
You can also add more new ideas!
For example, display the text “Confession of Love”
Use a color sensor for color changes
Then build a romantic surprise appearance with LEGO
……
When Valentine’s Day meets Spring Festival
It should have both the romance of lovers and the warmth of family
Hope your gift can achieve both
Then happily return home together!
*Welcome to share with friends. If you need to reprint, please indicate the source and original author.
Project resources click here
2017 Annual Editor’s Choice Award Part 1
2017 Annual Editor’s Choice Award Part 2
DIY Raspberry Pi Game Console | Which Jumping Game is the Best
IMA Final Project Exhibition | Boston Dynamics Robot Latest Video
Micro:bit Christmas Project Collection | DIY Mini Loader | Sparrow
Selected IoT Projects | Most Beautiful Programmer Returns to Victoria’s Secret Show | Poem of Palmistry
3D Printed Crawler | WiFi Weather Station | Minimalist Induction Light | Lululu Clock Deer
3D Printed Private Cloud Case |Smart Home—Siri Voice Control Rotating Light
Music Pad Launchpad | Singapore ITE Student Works Special
Click“Read the original text” to see the complete tutorial!!!