Arduino爱好者

 找回密码
 立即注册

QQ登录

只需一步,快速开始

楼主: eagler8

[经验] 【Arduino】168种传感器模块系列实验(123)---P10V706LED屏模组

[复制链接]
 楼主| 发表于 2022-11-23 15:14 | 显示全部楼层
  1. #define LIN_OUT 1
  2. #define FHT_N 128 // set to 256 point fht 128

  3. #include <FHT.h> // include the library
  4. #include <SPI.h>
  5. #include <DMD.h>        //
  6. #include <TimerOne.h>   //
  7. #include "SystemFont5x7.h"
  8. #include "Arial_black_16.h"

  9. #define DISPLAYS_ACROSS 1
  10. #define DISPLAYS_DOWN 1
  11. DMD dmd(DISPLAYS_ACROSS, DISPLAYS_DOWN);

  12. //-------------------------------------------------------------------------------
  13. // Change this to MONO to for a one-channel full-display or STEREO for two-channel
  14. //
  15. String displayType = "MONO";
  16. //
  17. // Change this to MONO to for a one-channel full-display or STEREO for two-channel
  18. //-------------------------------------------------------------------------------

  19. byte sampleR[64]; //64
  20. byte sampleL[64];
  21. unsigned long startTime, endTime, oldTime;
  22. String displayText = "DY";
  23. String sampleSet;
  24. int displaySize;

  25. void ScanDMD()
  26. {
  27.   dmd.scanDisplayBySPI();
  28. }

  29. void setup() {

  30.   if (displayType == "MONO") {displaySize = 32;} else {displaySize = 16;}
  31.   
  32.   //TIMSK0 = 0; // turn off timer0 for lower jitter
  33.   ADCSRA = 0xe7; // set the adc to free running mode
  34.   ADMUX = 0x45; // use adc5
  35.   DIDR0 = 0x20; // turn off the digital input for adc5

  36.   Timer1.initialize( 5000 );           //period in microseconds to call ScanDMD. Anything longer than 5000 (5ms) and you can see flicker.
  37.   Timer1.attachInterrupt( ScanDMD );   //attach the Timer1 interrupt to ScanDMD which goes to dmd.scanDisplayBySPI()
  38.   dmd.clearScreen( true );   //true is normal (all pixels off), false is negative (all pixels on)

  39.   dmd.selectFont(Arial_Black_16); // show off who wrote the app... :p
  40.   dmd.drawString(6,1,"DY",2,GRAPHICS_NORMAL);
  41.   delay(3000);
  42.   dmd.drawString(6,1,"CJ",2,GRAPHICS_NORMAL);
  43.   delay(3000);
  44.   dmd.selectFont(SystemFont5x7);
  45.   dmd.drawString(2,0,"Audio",5,GRAPHICS_NORMAL);
  46.   dmd.drawString(2,9,"Analy",5,GRAPHICS_NORMAL);
  47.   delay(3000);

  48. }

  49. void loop() {

  50.   startTime = millis();
  51.   sampleSet = "L";
  52.   sampleInput();
  53.   sampleFix();
  54.   if (displaySize == 16) {
  55.     sampleSet = "R";
  56.     sampleInput();
  57.     sampleFix();
  58.   }
  59.   drawSpectrum();
  60.   endTime = millis();
  61. }

  62. void drawSpectrum () {

  63.   if (displaySize == 16) {
  64.     dmd.clearScreen(true);
  65.     for (int disX; disX < 16; disX++) {
  66.       dmd.drawLine (disX, 16, disX, 16-sampleL[disX+1], GRAPHICS_NORMAL );
  67.       dmd.drawLine (17+disX, 16, 17+disX, 16-sampleR[disX+1], GRAPHICS_NORMAL );
  68.     }
  69.   }
  70.   else {
  71.     dmd.clearScreen(true);
  72.     for (int disX; disX < 33; disX++) {
  73.       dmd.drawLine (disX, 16, disX, 16-sampleL[disX+1], GRAPHICS_NORMAL );
  74.     }
  75.   }
  76. }

  77. void sampleInput() {
  78.   cli();  // UDRE interrupt slows this way down on arduino1.0
  79.   for (int x=0; x<FHT_N; x++) {
  80.     while(!(ADCSRA & 0x10)); // wait for adc to be ready
  81.     ADCSRA = 0xf5; // restart adc
  82.     if (sampleSet == "L") {
  83.       ADMUX = 0x45; // use adc5
  84.     } else {
  85.       ADMUX = 0x44; // use adc4
  86.     }
  87.     byte m = ADCL; // fetch adc data
  88.     byte j = ADCH;
  89.     int k = (j << 8) | m; // form into an int 8
  90.     k -= 0x0200; // form into a signed int
  91.     k <<= 6; // form into a 16b signed int 6
  92.     fht_input[x] = k; // put real data into bins
  93.   }
  94.   sei();
  95.   fht_window(); // window the data for better frequency response
  96.   fht_reorder(); // reorder the data before doing the fht
  97.   fht_run(); // process the data in the fht
  98.   fht_mag_lin();

  99. }

  100. void sampleFix() {

  101.   int newPos;
  102.   float fhtCount, tempY;
  103.   for (int x=0; x < displaySize; x++) {
  104.     fhtCount = FHT_N/2;  // 2
  105.     newPos = x * (fhtCount / displaySize); // single channel half-display 15-LED wide
  106.     tempY = fht_lin_out[newPos];
  107.     if (sampleSet == "L") {
  108.     sampleL[x] = ((tempY/256)*16); // single channel full 16 LED high
  109.     } else {
  110.     sampleR[x] = ((tempY/256)*16); // single channel full 16 LED high
  111.     }
  112.   }  
  113. }
复制代码


 楼主| 发表于 2022-11-23 15:18 | 显示全部楼层
45.jpg
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|Archiver|手机版|Arduino爱好者

GMT+8, 2023-2-4 23:12 , Processed in 0.079156 second(s), 21 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表