【花雕动手做】看见声音,基于Arduino系列音乐可视器(29)
偶然心血来潮,想要做一个音乐可视化的系列专题。这个专题的难度有点高,涉及面也比较广泛,相关的FFT和FHT等算法也相当复杂,不过还是打算从最简单的开始,实际动手做做试验,耐心尝试一下各种方案,逐步积累些有用的音乐频谱可视化的资料,也会争取成型一些实用好玩的音乐可视器项目。正好手头还有四片8X8硬屏,于是把它们拼在一起,组成一块16X16的WS2812B硬屏,继续尝试音乐可视化的项目。
【花雕动手做】有趣好玩的音乐可视化系列项目(29)--16X16硬屏灯
项目之四:256位音乐频谱灯
/*
【花雕动手做】有趣好玩的音乐可视化系列项目(29)--16X16硬屏灯
项目之四:256位音乐频谱灯
*/
#include "FastLED.h"
#define OCTAVE 1 // // Group buckets into octaves(use the log output function LOG_OUT 1)
#define OCT_NORM 0 // Don't normalise octave intensities by number of bins
#define FHT_N 256 // set to 256 point fht
#include <FHT.h> // include the library
//int noise[] = {204,188,68,73,150,98,88,68}; // noise level determined by playing pink noise and seeing levels {204,188,68,73,150,98,88,68}
// int noise[] = {204,190,108,85,65,65,55,60}; // noise for mega adk
int noise[] = {204, 195, 100, 90, 85, 80, 75, 75}; // noise for NANO
//int noise[] = {204,198,100,85,85,80,80,80};
float noise_fact[] = {15, 7, 1.5, 1, 1.2, 1.4, 1.7, 3}; // noise level determined by playing pink noise and seeing levels {204,188,68,73,150,98,88,68}
float noise_fact_adj[] = {15, 7, 1.5, 1, 1.2, 1.4, 1.7, 3}; // noise level determined by playing pink noise and seeing levels {204,188,68,73,150,98,88,68}
#define LED_PIN 6
#define LED_TYPE WS2812
#define COLOR_ORDER GRB
// Params for width and height
const uint8_t kMatrixWidth = 8;
const uint8_t kMatrixHeight = 32;
//#define NUM_LEDS (kMatrixWidth * kMatrixHeight)
#define NUM_LEDS 256
CRGB leds;
int counter2 = 0;
void setup() {
Serial.begin(9600);
delay(1000);
FastLED.addLeds<LED_TYPE, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
FastLED.setBrightness (33);
fill_solid(leds, NUM_LEDS, CRGB::Black);
FastLED.show();
// TIMSK0 = 0; // turn off timer0 for lower jitter
ADCSRA = 0xe5; // set the adc to free running mode
ADMUX = 0x40; // use adc0
DIDR0 = 0x01; // turn off the digital input for adc0
}
void loop() {
int prev_j;
int beat = 0;
int prev_oct_j;
int counter = 0;
int prev_beat = 0;
int led_index = 0;
int saturation = 0;
int saturation_prev = 0;
int brightness = 0;
int brightness_prev = 0;
while (1) { // reduces jitter
cli();// UDRE interrupt slows this way down on arduino1.0
for (int i = 0 ; i < FHT_N ; i++) { // save 256 samples
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
fht_input = k; // put real data into bins
}
fht_window(); // window the data for better frequency response
fht_reorder(); // reorder the data before doing the fht
fht_run(); // process the data in the fht
fht_mag_octave(); // take the output of the fhtfht_mag_log()
// every 50th loop, adjust the volume accourding to the value on A2 (Pot)
if (counter >= 50) {
ADMUX = 0x40 | (1 & 0x07); // set admux to look at Analogpin A1 - Master Volume
while (!(ADCSRA & 0x10)); // wait for adc to be ready
ADCSRA = 0xf5; // restart adc
delay(10);
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
float master_volume = (k + 0.1) / 1000 + .75; // so the valu will be between ~0.5 and 1.---------------------+.75 was .5
Serial.println (master_volume);
for (int i = 1; i < 8; i++) {
noise_fact_adj = noise_fact * master_volume;
}
ADMUX = 0x40 | (0 & 0x07); // set admux back to look at A0 analog pin (to read the microphone input
counter = 0;
}
sei();
counter++;
// End of Fourier Transform code - output is stored in fht_oct_out.
// i=0-7 frequency (octave) bins (don't use 0 or 1), fht_oct_out= amplitude of frequency for bin 1
// for loop a) removes background noise average and takes absolute value b) low / high pass filter as still very noisy
// c) maps amplitude of octave to a colour between blue and red d) sets pixel colour to amplitude of each frequency (octave)
for (int i = 1; i < 8; i++) {// goes through each octave. skip the first 1, which is not useful
int j;
j = (fht_oct_out - noise); // take the pink noise average level out, take the asbolute value to avoid negative numbers
if (j < 10) {
j = 0;
}
j = j * noise_fact_adj;
if (j < 10) {
j = 0;
}
else {
j = j * noise_fact_adj;
if (j > 180) {
if (i >= 7) {
beat += 2;
}
else {
beat += 1;
}
}
j = j / 30;
j = j * 30; // (force it to more discrete values)
}
prev_j = j;
// Serial.print(j);
// Serial.print(" ");
// this fills in 11 LED's with interpolated values between each of the 8 OCT values
if (i >= 2) {
led_index = 2 * i - 3;
prev_oct_j = (j + prev_j) / 2;
saturation = constrain(j + 50, 0, 255); //-----------50 was 30
saturation_prev = constrain(prev_oct_j + 50, 0, 255);
brightness = constrain(j, 0, 255);
brightness_prev = constrain(prev_oct_j, 0, 255);
if (brightness == 255) {
saturation = 50;
brightness = 200;
}
if (brightness_prev == 255) {
saturation_prev = 50;
brightness_prev = 200;
}
for (uint8_t y = 0; y < kMatrixHeight; y++) {
leds = CHSV(j + y * 30, saturation, brightness);
if (i > 2) {
prev_oct_j = (j + prev_j) / 2;
leds[ XY(led_index - 2, y)] = CHSV(prev_oct_j + y * 30, saturation_prev, brightness_prev);
}
}
}
}
if (beat >= 7) {
fill_solid(leds, NUM_LEDS, CRGB::Gray);
FastLED.setBrightness(200);
}
else {
if (prev_beat != beat) {
FastLED.setBrightness(40 + beat * beat * 5);
prev_beat = beat;
}
}
FastLED.show();
if (beat) {
counter2 += ((beat + 4) / 2 - 2);
if (counter2 < 0) {
counter2 = 1000;
}
if (beat > 3 && beat < 7) {
FastLED.delay (20);
}
beat = 0;
}
// Serial.println();
}
}
// Param for different pixel layouts
const bool kMatrixSerpentineLayout = false;
// Set 'kMatrixSerpentineLayout' to false if your pixels are
// laid out all running the same way, like this:
// Set 'kMatrixSerpentineLayout' to true if your pixels are
// laid out back-and-forth, like this:
uint16_t XY( uint8_t x, uint8_t y)
{
uint16_t i;
if ( kMatrixSerpentineLayout == false) {
i = (y * kMatrixWidth) + x;
}
if ( kMatrixSerpentineLayout == true) {
if ( y & 0x01) {
// Odd rows run backwards
uint8_t reverseX = (kMatrixWidth - 1) - x;
i = (y * kMatrixWidth) + reverseX;
} else {
// Even rows run forwards
i = (y * kMatrixWidth) + x;
}
}
i = (i + counter2) % NUM_LEDS;
return i;
}
【花雕动手做】有趣好玩的音乐可视化系列项目(29)--16X16硬屏灯
项目之二:RGB传输测试满屏变幻彩灯
/*
【花雕动手做】有趣好玩的音乐可视化系列项目(29)--16X16硬屏灯
项目之二:RGB传输测试满屏变幻彩灯
*/
#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
#include <avr/power.h> // Required for 16 MHz Adafruit Trinket
#endif
// Which pin on the Arduino is connected to the NeoPixels?
// On a Trinket or Gemma we suggest changing this to 1:
#define LED_PIN 6
// How many NeoPixels are attached to the Arduino?
#define LED_COUNT256
// NeoPixel brightness, 0 (min) to 255 (max)
#define BRIGHTNESS 30
// Declare our NeoPixel strip object:
Adafruit_NeoPixel strip(LED_COUNT, LED_PIN, NEO_GRBW + NEO_KHZ800);
// Argument 1 = Number of pixels in NeoPixel strip
// Argument 2 = Arduino pin number (most are valid)
// Argument 3 = Pixel type flags, add together as needed:
// NEO_KHZ800800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
// NEO_KHZ400400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
// NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products)
// NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
// NEO_RGBW Pixels are wired for RGBW bitstream (NeoPixel RGBW products)
void setup() {
// These lines are specifically to support the Adafruit Trinket 5V 16 MHz.
// Any other board, you can remove this part (but no harm leaving it):
#if defined(__AVR_ATtiny85__) && (F_CPU == 16000000)
clock_prescale_set(clock_div_1);
#endif
// END of Trinket-specific code.
strip.begin(); // INITIALIZE NeoPixel strip object (REQUIRED)
strip.show(); // Turn OFF all pixels ASAP
strip.setBrightness(50); // Set BRIGHTNESS to about 1/5 (max = 255)
}
void loop() {
// Fill along the length of the strip in various colors...
colorWipe(strip.Color(255, 0, 0) , 50); // Red
colorWipe(strip.Color(0, 255, 0) , 50); // Green
colorWipe(strip.Color(0, 0, 255) , 50); // Blue
colorWipe(strip.Color(0, 0, 0, 255), 50); // True white (not RGB white)
whiteOverRainbow(75, 5);
pulseWhite(5);
rainbowFade2White(3, 3, 1);
}
// Fill strip pixels one after another with a color. Strip is NOT cleared
// first; anything there will be covered pixel by pixel. Pass in color
// (as a single 'packed' 32-bit value, which you can get by calling
// strip.Color(red, green, blue) as shown in the loop() function above),
// and a delay time (in milliseconds) between pixels.
void colorWipe(uint32_t color, int wait) {
for(int i=0; i<strip.numPixels(); i++) { // For each pixel in strip...
strip.setPixelColor(i, color); //Set pixel's color (in RAM)
strip.show(); //Update strip to match
delay(3); //Pause for a moment
}
}
void whiteOverRainbow(int whiteSpeed, int whiteLength) {
if(whiteLength >= strip.numPixels()) whiteLength = strip.numPixels() - 1;
int head = whiteLength - 1;
int tail = 0;
int loops = 3;
int loopNum = 0;
uint32_t lastTime = millis();
uint32_t firstPixelHue = 0;
for(;;) { // Repeat forever (or until a 'break' or 'return')
for(int i=0; i<strip.numPixels(); i++) {// For each pixel in strip...
if(((i >= tail) && (i <= head)) || //If between head & tail...
((tail > head) && ((i >= tail) || (i <= head)))) {
strip.setPixelColor(i, strip.Color(0, 0, 0, 255)); // Set white
} else { // else set rainbow
int pixelHue = firstPixelHue + (i * 65536L / strip.numPixels());
strip.setPixelColor(i, strip.gamma32(strip.ColorHSV(pixelHue)));
}
}
strip.show(); // Update strip with new contents
// There's no delay here, it just runs full-tilt until the timer and
// counter combination below runs out.
firstPixelHue += 40; // Advance just a little along the color wheel
if((millis() - lastTime) > whiteSpeed) { // Time to update head/tail?
if(++head >= strip.numPixels()) { // Advance head, wrap around
head = 0;
if(++loopNum >= loops) return;
}
if(++tail >= strip.numPixels()) { // Advance tail, wrap around
tail = 0;
}
lastTime = millis(); // Save time of last movement
}
}
}
void pulseWhite(uint8_t wait) {
for(int j=0; j<256; j++) { // Ramp up from 0 to 255
// Fill entire strip with white at gamma-corrected brightness level 'j':
strip.fill(strip.Color(0, 0, 0, strip.gamma8(j)));
strip.show();
delay(3);
}
for(int j=255; j>=0; j--) { // Ramp down from 255 to 0
strip.fill(strip.Color(0, 0, 0, strip.gamma8(j)));
strip.show();
delay(3);
}
}
void rainbowFade2White(int wait, int rainbowLoops, int whiteLoops) {
int fadeVal=0, fadeMax=100;
// Hue of first pixel runs 'rainbowLoops' complete loops through the color
// wheel. Color wheel has a range of 65536 but it's OK if we roll over, so
// just count from 0 to rainbowLoops*65536, using steps of 256 so we
// advance around the wheel at a decent clip.
for(uint32_t firstPixelHue = 0; firstPixelHue < rainbowLoops*65536;
firstPixelHue += 256) {
for(int i=0; i<strip.numPixels(); i++) { // For each pixel in strip...
// Offset pixel hue by an amount to make one full revolution of the
// color wheel (range of 65536) along the length of the strip
// (strip.numPixels() steps):
uint32_t pixelHue = firstPixelHue + (i * 65536L / strip.numPixels());
// strip.ColorHSV() can take 1 or 3 arguments: a hue (0 to 65535) or
// optionally add saturation and value (brightness) (each 0 to 255).
// Here we're using just the three-argument variant, though the
// second value (saturation) is a constant 255.
strip.setPixelColor(i, strip.gamma32(strip.ColorHSV(pixelHue, 255,
255 * fadeVal / fadeMax)));
}
strip.show();
delay(3);
if(firstPixelHue < 65536) { // First loop,
if(fadeVal < fadeMax) fadeVal++; // fade in
} else if(firstPixelHue >= ((rainbowLoops-1) * 65536)) { // Last loop,
if(fadeVal > 0) fadeVal--; // fade out
} else {
fadeVal = fadeMax; // Interim loop, make sure fade is at max
}
}
for(int k=0; k<whiteLoops; k++) {
for(int j=0; j<256; j++) { // Ramp up 0 to 255
// Fill entire strip with white at gamma-corrected brightness level 'j':
strip.fill(strip.Color(0, 0, 0, strip.gamma8(j)));
strip.show();
}
delay(100); // Pause 1 second
for(int j=255; j>=0; j--) { // Ramp down 255 to 0
strip.fill(strip.Color(0, 0, 0, strip.gamma8(j)));
strip.show();
}
}
delay(5); // Pause 1/2 second
}
Arduino 系列传感器和执行器模块实验目录清单:
一块扩展板完成Arduino的10类37项实验(代码+图形+仿真)
https://mc.dfrobot.com.cn/thread-280845-1-1.html
连杆形式的腿机构十一种:盘点机器人行走背后的机械原理
https://mc.dfrobot.com.cn/thread-308097-1-1.html
【花雕动手做】超低成本,尝试五十元的麦克纳姆轮小车!
https://mc.dfrobot.com.cn/thread-307863-1-1.html
【花雕动手做】超迷你哦,用徽商香烟盒做个智能小车!
https://mc.dfrobot.com.cn/thread-307907-1-1.html
【花雕动手做】太搞笑啦,一支胶管制成二只蠕动机器人
https://mc.dfrobot.com.cn/thread-308046-1-1.html
【花雕动手做】快餐盒盖,极低成本搭建机器人实验平台
https://mc.dfrobot.com.cn/thread-308063-1-1.html
【花雕动手做】特别苗条,使用微波传感器控制的纤细小车
https://mc.dfrobot.com.cn/thread-308866-1-1.html
【花雕动手做】脑洞大开、五花八门的简易机器人66种
https://mc.dfrobot.com.cn/thread-307900-1-1.html
【花雕动手做】看见声音,基于Arduino系列音乐可视器(1)---LED节奏灯
https://mc.dfrobot.com.cn/thread-311167-1-1.html
【花雕动手做】看见声音,基于Arduino系列音乐可视器(2)---OLED频谱灯
https://mc.dfrobot.com.cn/thread-311174-1-1.html
【花雕动手做】看见声音,基于Arduino系列音乐可视器(3)---RGB律动灯
https://mc.dfrobot.com.cn/thread-311183-1-1.html
【花雕动手做】看见声音,基于Arduino系列音乐可视器(4)---WS2812条灯
https://mc.dfrobot.com.cn/thread-311190-1-1.html
【花雕动手做】看见声音,基于Arduino系列音乐可视器(5)---WS2812柱跳灯
https://mc.dfrobot.com.cn/thread-311192-1-1.html
【花雕动手做】看见声音,基于Arduino系列音乐可视器(6)---点阵频谱灯
https://mc.dfrobot.com.cn/thread-311201-1-1.html
【花雕动手做】看见声音,基于Arduino系列音乐可视器(7)---大方格频谱灯
https://mc.dfrobot.com.cn/thread-311364-1-1.html
【花雕动手做】看见声音,基于Arduino系列音乐可视器(8)---四位32段点阵屏
https://mc.dfrobot.com.cn/thread-311490-1-1.html
【花雕动手做】看见声音,基于Arduino系列音乐可视器(9)---X Music Spectrum
https://mc.dfrobot.com.cn/thread-311627-1-1.html
【花雕动手做】看见声音,基于Arduino系列音乐可视器(10)---WS2812硬板屏
https://mc.dfrobot.com.cn/thread-311641-1-1.html
【花雕动手做】看见声音,基于Arduino系列音乐可视器(11)---WS2812幻彩灯带
https://mc.dfrobot.com.cn/thread-313648-1-1.html
【花雕动手做】看见声音,基于Arduino系列音乐可视器(12)---米管快速节奏灯
https://mc.dfrobot.com.cn/thread-313708-1-1.html
【花雕动手做】看见声音,基于Arduino系列音乐可视器(13)---有机棒立柱灯
https://mc.dfrobot.com.cn/thread-313723-1-1.html
【花雕动手做】看见声音,基于Arduino系列音乐可视器(14)---水杯水瓶灯
https://mc.dfrobot.com.cn/thread-313803-1-1.html
【花雕动手做】看见声音,基于Arduino系列音乐可视器(15)--横排LED方管灯
https://mc.dfrobot.com.cn/thread-313811-1-1.html
【花雕动手做】看见声音,基于Arduino系列音乐可视器(16)--热干胶棒棒灯
https://mc.dfrobot.com.cn/thread-313844-1-1.html
【花雕动手做】有趣好玩音乐可视化系列(17)--光导纤维灯
https://mc.dfrobot.com.cn/thread-313867-1-1.html
【花雕动手做】看见声音,基于Arduino系列音乐可视器(18)--LED平面板灯
https://mc.dfrobot.com.cn/thread-313951-1-1.html
【花雕动手做】看见声音,基于Arduino系列音乐可视器(19)--通体光纤灯
https://mc.dfrobot.com.cn/thread-313962-1-1.html
【花雕动手做】看见声音,基于Arduino系列音乐可视器(20)--首饰盒镜子灯
https://mc.dfrobot.com.cn/thread-313969-1-1.html
【花雕动手做】看见声音,基于Arduino系列音乐可视器(21)--CD 光盘灯
https://mc.dfrobot.com.cn/thread-313984-1-1.html
【花雕动手做】看见声音,基于Arduino系列音乐可视器(22)--LED无限魔方
https://mc.dfrobot.com.cn/thread-313994-1-1.html
【花雕动手做】有趣好玩的音乐可视化(23)--3合1闪点光纤
https://mc.dfrobot.com.cn/thread-314168-1-1.html
【花雕动手做】有趣好玩的音乐可视化(24)--无限LED镜子灯
https://mc.dfrobot.com.cn/thread-314180-1-1.html
【花雕动手做】有趣好玩音乐可视化(25)--水龙卷旋涡灯
https://mc.dfrobot.com.cn/thread-314231-1-1.html
【花雕动手做】有趣好玩音乐可视化系列(26)--LED 超立方体
https://mc.dfrobot.com.cn/thread-314244-1-1.html
【花雕动手做】有趣好玩的音乐可视化(27)--磁搅LED水旋灯
https://mc.dfrobot.com.cn/thread-314273-1-1.html
【花雕动手做】有趣好玩的音乐可视化系列项目(28)--LED乒乓球灯
https://mc.dfrobot.com.cn/thread-314321-1-1.html
【花雕动手做】有趣好玩的音乐可视化系列项目(29)--16X16硬屏灯
https://mc.dfrobot.com.cn/thread-314474-1-1.html
【花雕动手做】有趣好玩的音乐可视化(30)--P6 LED单元板
https://mc.dfrobot.com.cn/thread-314540-1-1.html
实验一百五十八:QMC5883L电子指南针罗盘模块 三轴磁场传感器GY-271
https://mc.dfrobot.com.cn/thread-308195-1-1.html
实验一百六十三:BMI160 6轴惯性运动传感器 16位3轴加速度+超低功耗3轴陀螺仪I2C/SPI 14LGA
https://mc.dfrobot.com.cn/thread-310371-1-1.html
实验一百六十五:2.4 英寸 TFT LCD 触摸屏模块 XPT2046 PCB ILI9341 240x320 像素 8 位 SPI 串口显示器 300mA
https://mc.dfrobot.com.cn/thread-309803-1-1.html
实验一百七十六:6mm大尺寸8x8LED方块方格点阵模块 可级联 红绿蓝白色 可选8级亮度
https://mc.dfrobot.com.cn/thread-309845-1-1.html
实验一百七十九:0.66英寸OLED显示模块 液晶屏模块IIC/I2C接口 64*48像素 SSD1306驱动芯片
https://mc.dfrobot.com.cn/thread-311179-1-1.html
实验一百八十一:1.3寸OLED液晶屏I2C IIC通信 4针模块 1106/1306驱动 128*64像素
https://mc.dfrobot.com.cn/thread-311123-1-1.html
实验一百八十三:GY-530 VL53L0X 激光测距 ToF测距 飞行时间测距传感器模块 IIC通信协议
https://mc.dfrobot.com.cn/thread-310273-1-1.html
实验一百八十五:MAX4466声音传感器 驻极体话筒放大器 麦克风可调功放模块 microphone
https://mc.dfrobot.com.cn/thread-310193-1-1.html
实验一百八十九:TDA1308 硅麦克风 数字咪头放大模块 拾音器放大板 楼氏SUNLEPHANT
https://mc.dfrobot.com.cn/thread-310246-1-1.html
实验一百九十三:TCS34725颜色识别传感器 RGB IIC明光感应模块 ColorSensor
https://mc.dfrobot.com.cn/thread-310209-1-1.html
实验二百:RCWL-0515微波雷达感应开关 人体感应 智能感应探测传感器 12-15米远距离2.7G微波检测模块
https://mc.dfrobot.com.cn/thread-310313-1-1.html
实验二百零一:OPT101模拟光照传感器 TEMT6000光强度模块 单片光电二极管 YourCee
https://mc.dfrobot.com.cn/thread-311164-1-1.html
实验二百零三:Air724UG合宙 Cat14G模块 DTU物联网UART串口通信数据TCP透传 核心板组合套餐
https://mc.dfrobot.com.cn/thread-310342-1-1.html
实验二百零七:I2C红色8*8LED点阵模块ht16k33驱动1088BS树莓派物联网可扩展编程
https://mc.dfrobot.com.cn/thread-310951-1-1.html
实验二百零九:Gravity: I2C & UART BC20 NB-IoT & GNSS通信模块 NB-IoT广域低功耗无线通信 GPS/北斗精准定位
https://mc.dfrobot.com.cn/thread-310433-1-1.html
实验二百十一:LED 圆环内置IC全彩点控1-8-12-16-24-32 WS2812B 93灯 环形 圆盘
https://mc.dfrobot.com.cn/thread-314225-1-1.html
实验二百一十四:WS2812B全彩RGB像素屏 8x32点阵LED显示屏 可编程硬屏模块
https://mc.dfrobot.com.cn/thread-314378-1-1.html
实验二百一十七:2.9寸epd电子纸屏模块 spi电纸屏黑白红三色eink墨水屏QYEG0290BNS800F6
https://mc.dfrobot.com.cn/thread-311306-1-1.html#pid498640
实验二百一十八:1.3寸 TFT显示屏 ST7735S驱动高清ips 模块
https://mc.dfrobot.com.cn/thread-313540-1-1.html#pid518278
实验二百二十:P6全彩LED模组 16X32显示屏单元板 P6-RGB-16X32-8S室内全彩8扫电子屏(HX-P6-16X32-A)
https://mc.dfrobot.com.cn/thread-314576-1-1.html
【花雕测评】【AI】尝试搭建Maixduino几种开发环境
https://makelog.dfrobot.com.cn/article-311383.html
【花雕测评】【AI】MaixPy基本使用、显示文字及摄像机的22个小项目
https://makelog.dfrobot.com.cn/article-311389.html
【花雕测评】【AI】Mind+图片文字显示、呼吸灯和网络应用的22项小实验
https://makelog.dfrobot.com.cn/article-311386.html
【花雕测评】【AI】MaixPy机器视觉与Color识别的8个尝试
https://makelog.dfrobot.com.cn/article-311393.html
【花雕测评】【AI】Mind+机器视觉之数字图像处理和显示的22种小测试
https://makelog.dfrobot.com.cn/article-311405.html
【花雕测评】【AI】MaixPy之神经网络KPU与人脸识别的初步体验
https://makelog.dfrobot.com.cn/article-311400.html
【花雕测评】【AI】Mind+机器视觉之颜色、维码与形状识别的8个小实验
https://makelog.dfrobot.com.cn/article-311417.html
背面
拼装成16X16的像素WS2812灯
WS2812B
是一个集控制电路与发光电路于一体的智能外控LED光源。其外型与一个5050LED灯珠相同,每个元件即为一个像素点。像素点内部包含了智能数字接口数据锁存信号整形放大驱动电路,还包含有高精度的内部振荡器和12V高压可编程定电流控制部分,有效保证了像素点光的颜色高度一致。
数据协议采用单线归零码的通讯方式,像素点在上电复位以后,DIN端接受从控制器传输过来的数据,首先送过来的24bit数据被第一个像素点提取后,送到像素点内部的数据锁存器,剩余的数据经过内部整形处理电路整形放大后通过DO端口开始转发输出给下一个级联的像素点,每经过一个像素点的传输,信号减少24bit。像素点采用自动整形转发技术,使得该像素点的级联个数不受信号传送的限制,仅仅受限信号传输速度要求。
LED具有低电压驱动,环保节能,亮度高,散射角度大,一致性好,超低功率,超长寿命等优点。将控制电路集成于LED上面,电路变得更加简单,体积小,安装更加简便。
模块电原理图
【花雕动手做】有趣好玩的音乐可视化系列项目(29)--16X16硬屏灯
项目之一:WS2812FX库最简单的点亮形式
/*
【花雕动手做】有趣好玩的音乐可视化系列项目(29)--16X16硬屏灯
项目之一:WS2812FX库最简单的点亮形式
*/
#include <WS2812FX.h> //导入库
#define LED_COUNT 256 //WS2812B LED数量
#define LED_PIN 6 //WS2812B LED接脚
WS2812FX ws2812fx = WS2812FX(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800);
void setup() {
ws2812fx.init(); //初始化
ws2812fx.setBrightness(35); //设置亮度(0-255),可以控制总电流(重要!)
ws2812fx.setSpeed(100); // 设置速度
ws2812fx.setMode(FX_MODE_FIREWORKS_RANDOM);// 设置模式(内置63种模式)
ws2812fx.start(); //启动
}
void loop() {
ws2812fx.service(); //循环运行
}
实验场景图动态图
实验场景图
实验场景图
【花雕动手做】有趣好玩的音乐可视化系列项目(29)--16X16硬屏灯
项目之三:应用Adafruit_NeoPixel库的入门极简程序
/*
【花雕动手做】有趣好玩的音乐可视化系列项目(29)--16X16硬屏灯
项目之三:应用Adafruit_NeoPixel库的入门极简程序
*/
#include <Adafruit_NeoPixel.h>
#define PIN 6 //接脚
#define NUMPIXELS 256 //数量
Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
#define DELAYVAL 10 //延时
void setup() {
pixels.setBrightness(22);//亮度
pixels.begin();//启动
}
void loop() {
pixels.clear();
for (int i = 0; i < NUMPIXELS; i++) {
pixels.setPixelColor(i, pixels.Color(50, 250, 0));//绿色
pixels.show();
delay(1);
}
}
实验场景图
实验场景图动态图
实验的视频记录
优酷:https://v.youku.com/v_show/id_XNTkxNTA3OTM0NA==.html?spm=a2hcb.playlsit.page.1
B站:https://www.bilibili.com/video/BV1Wg411z7QR/?vd_source=98c6b1fc23b2787403d97f8d3cc0b7e5
https://v.youku.com/v_show/id_XNTkxNTA3OTM0NA==.html?spm=a2hcb.playlsit.page.1
实验场景图
【花雕动手做】有趣好玩的音乐可视化系列项目(29)--16X16硬屏灯
项目之五:多彩MegunoLink音乐节拍灯
/*
【花雕动手做】有趣好玩的音乐可视化系列项目(29)--16X16硬屏灯
项目之五:多彩MegunoLink音乐节拍灯
*/
#include<FastLED.h>
#include<MegunoLink.h>
#include<Filter.h>
#define N_PIXELS23
#define MIC_PIN A0
#define LED_PIN 6
#define NOISE 10
#define TOP (N_PIXELS+2)
#define LED_TYPEWS2811
#define BRIGHTNESS10
#define COLOR_ORDER GRB
CRGB leds;
int lvl = 0, minLvl = 0, maxLvl = 10;
ExponentialFilter<long> ADCFilter(5, 0);
void setup() {
FastLED.addLeds<LED_TYPE, LED_PIN, COLOR_ORDER>(leds, N_PIXELS).setCorrection(TypicalLEDStrip);
FastLED.setBrightness(BRIGHTNESS);
}
void loop() {
int n, height;
n = analogRead(MIC_PIN);
n = abs(1023 - n);
n = (n <= NOISE) ? 0 : abs(n - NOISE);
ADCFilter.Filter(n);
lvl = ADCFilter.Current();
//Serial.print(n);
//Serial.print(" ");
//Serial.println(lvl);
height = TOP * (lvl - minLvl) / (long)(maxLvl - minLvl);
if (height < 0L) height = 0;
else if (height > TOP) height = TOP;
for (uint8_t i = 0; i < N_PIXELS; i++) {
if (i >= height) leds = CRGB(0, 0, 0);
else leds = Wheel( map( i, 0, N_PIXELS - 1, 30, 150 ) );
}
FastLED.show();
}
CRGB Wheel(byte WheelPos) {
if (WheelPos < 85)
return CRGB(WheelPos * 3, 255 - WheelPos * 3, 0);
else if (WheelPos < 170) {
WheelPos -= 85;
return CRGB(255 - WheelPos * 3, 0, WheelPos * 3);
} else {
WheelPos -= 170;
return CRGB(0, WheelPos * 3, 255 - WheelPos * 3);
}
}
实验场景图动态图
实验的视频记录
优酷:
B站:https://www.bilibili.com/video/BV1kd4y1y75d/?vd_source=98c6b1fc23b2787403d97f8d3cc0b7e5
https://www.bilibili.com/video/BV1kd4y1y75d/?vd_source=98c6b1fc23b2787403d97f8d3cc0b7e5