发帖
8 0 0

LED多的可以尝试下GPT生成的音乐律动

odl
金牌会员

7

主题

17

回帖

1535

积分

金牌会员

积分
1535
小安派Cam 2076 8 2023-12-5 15:07:41
  1. #define NOTE_C4 262
  2. #define NOTE_D4 294
  3. #define NOTE_E4 330
  4. #define NOTE_F4 349
  5. #define NOTE_G4 392
  6. #define NOTE_A4 440
  7. #define NOTE_B4 494
  8. #define NOTE_C5 523

  9. // 定义音符和持续时间
  10. int melody[] = {NOTE_C4, NOTE_D4, NOTE_E4, NOTE_F4, NOTE_G4, NOTE_A4, NOTE_B4, NOTE_C5};
  11. int noteDuration = 200;

  12. // 定义LED矩阵的尺寸
  13. const int rows = 9;
  14. const int cols = 9;
  15. const int levels = 9;

  16. // 定义LED引脚
  17. int ledPins[rows][cols][levels] = {
  18.   // 你的LED引脚映射在这里
  19.   // 例如,ledPins[0][0][0]表示矩阵的第一个LED的引脚
  20. };

  21. void setup() {
  22.   // 初始化LED引脚
  23.   for (int i = 0; i < rows; ++i) {
  24.     for (int j = 0; j < cols; ++j) {
  25.       for (int k = 0; k < levels; ++k) {
  26.         pinMode(ledPins[i][j][k], OUTPUT);
  27.       }
  28.     }
  29.   }
  30. }

  31. void loop() {
  32.   for (int noteIndex = 0; noteIndex < sizeof(melody) / sizeof(melody[0]); ++noteIndex) {
  33.     // 播放当前音符
  34.     playTone(melody[noteIndex]);

  35.     // 更新LED矩阵
  36.     updateLEDMatrix(noteIndex);

  37.     // 等待一段时间
  38.     delay(noteDuration);
  39.   }
  40. }

  41. void playTone(int frequency) {
  42.   // 使用tone函数播放音符
  43.   tone(9, frequency, noteDuration);
  44. }

  45. void updateLEDMatrix(int noteIndex) {
  46.   // 更新LED矩阵的光效
  47.   // 这里可以根据需要自定义光效的规则
  48.   // 例如,可以使与当前音符对应的LED亮起,其他LED熄灭
  49.   // 也可以实现一些流光效果或者呼吸灯效果
  50. }
复制代码
──── 0人觉得很赞 ────

使用道具 举报

2023-12-5 16:13:35
流水灯
2023-12-5 17:23:13
拾音灯早就有了呀
2023-12-5 17:35:43
不懂就问, 这是做啥用的呀
2023-12-14 23:51:11
真羡慕你们会编程,
2023-12-15 09:35:00
2024-1-1 21:42:19
2024-11-23 23:57:29
2024-12-20 01:15:40
这代码没看到傅里叶变换呀,怎么实现的,靠谱吗
您需要登录后才可以回帖 立即登录
高级模式
返回
统计信息
  • 会员数: 28256 个
  • 话题数: 40218 篇