极客工坊

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 14923|回复: 8

请问大大们有玩过声音播放机吗?

[复制链接]
发表于 2017-1-31 21:44:16 | 显示全部楼层 |阅读模式
本帖最后由 v60i 于 2017-2-9 20:48 编辑

我想做对讲机
在网上查了一下,有人说利用RF24Audio Library可以做
下载后在RF24Audio Library示例 - > GettingStarted中
成功的在A0说话喇叭立即播放声音
可是有一点看不明白
由他的源码看不出为什么他可以
直接放声音


这是代码
希望有大大可以帮忙解惑
GettingStarted code

  1. #include <RF24.h>
  2. #include <SPI.h>
  3. #include <RF24Audio.h>
  4. #include "printf.h"                // General includes for radio and audio lib

  5. RF24 radio(7,8);                // Set radio up using pins 7 (CE) 8 (CS)
  6. RF24Audio rfAudio(radio,1);        // Set up the audio using the radio, and set to radio number 0

  7. void setup() {                       
  8.   Serial.begin(115200);                // Enable Arduino serial library
  9.   
  10.   printf_begin();               // Radio library uses printf to output debug info  
  11.   radio.begin();                // Must start the radio here, only if we want to print debug info
  12.   radio.printDetails();         // Print the info
  13.   
  14.   rfAudio.begin();                // Start up the radio and audio libararies
  15. }

  16. void loop() {

  17.     if(Serial.available()){                                           // Receive and analyze incoming serial data
  18.         switch(Serial.read()){
  19.             case 'r': rfAudio.transmit(); break;                        // Send an r or an s over serial to control playback
  20.             case 's': rfAudio.receive();  break;
  21.             case '=': rfAudio.volume(1);  break;                      // Control volume by sending = or - over serial
  22.             case '-': rfAudio.volume(0);  break;
  23.         }
  24.     }
  25.     Serial.println("test");
  26.     delay(1000);
  27. }
复制代码



RF24Audio code

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x
回复

使用道具 举报

发表于 2017-2-4 18:45:26 | 显示全部楼层
v60i 发表于 2017-2-3 00:35
对不起我已重重传一次,在麻烦下载

rfAudio.receive();命令连接到了库文件RF24Audio.cpp,在这个文件里面有一个receive函数,连到了一个叫RX的函数,
void RF24Audio::receive(){
        RX();
}

然后还有一段 Reception (RX) Section
里面有RX函数的内容
void RX(){                                                                                         // Start Receiving

                TIMSK1 &= ~_BV(OCIE1B) | _BV(OCIE1A);                // Disable the transmit interrupts
                ADCSRA = 0; ADCSRB = 0;                                // Disable Analog to Digital Converter (ADC)
        buffEmpty[0] = 1; buffEmpty[1] = 1;                    // Set the buffers to empty
        #if defined (oversampling)                                        // If running the timer at double the sample rate
          ICR1 = 10 * (800000/SAMPLE_RATE);                    // Set timer top for 2X oversampling
        #else
          ICR1 = 10 * (1600000/SAMPLE_RATE);                // Timer running at normal sample rate speed
        #endif

        radi.openWritingPipe(pipes[0]);                       // Set up reading and writing pipes
        radi.openReadingPipe(1,pipes[1]);
        radi.startListening();                                // Exit sending mode
        TIMSK1 = _BV(ICIE1);                                  // Enable the capture interrupt vector (handles buffering and starting of playback)



}
回复 支持 1 反对 0

使用道具 举报

发表于 2017-2-1 19:38:57 | 显示全部楼层
亲你这个不是一个有效的库文件,压缩包里面只有一个h文件
回复 支持 反对

使用道具 举报

 楼主| 发表于 2017-2-3 00:35:45 | 显示全部楼层
zjz5717 发表于 2017-2-1 19:38
亲你这个不是一个有效的库文件,压缩包里面只有一个h文件

对不起我已重重传一次,在麻烦下载
回复 支持 反对

使用道具 举报

 楼主| 发表于 2017-2-7 16:15:09 | 显示全部楼层
本帖最后由 v60i 于 2017-2-7 21:48 编辑
zjz5717 发表于 2017-2-4 18:45
rfAudio.receive();命令连接到了库文件RF24Audio.cpp,在这个文件里面有一个receive函数,连到了一个叫RX ...



我的是 ATmega328P-PU的
其中程式有写
        #if defined(__AVR_ATmega32U4__)
                if (pin >= 18) pin -= 18; // allow for channel or pin numbers
        #endif
                pin = analogPinToChannel(pin);
        #elif defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
                if (pin >= 54) pin -= 54; // allow for channel or pin numbers
        #elif defined(__AVR_ATmega32U4__)
                if (pin >= 18) pin -= 18; // allow for channel or pin numbers
        #elif defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__) || defined(__AVR_ATmega644__) || defined(__AVR_ATmega644A__) || defined(__AVR_ATmega644P__) || defined(__AVR_ATmega644PA__)
                if (pin >= 24) pin -= 24; // allow for channel or pin numbers
        #else
                if (pin >= 14) pin -= 14; // allow for channel or pin numbers
        #endif

查看datasheet 有写A0=14

我把if (pin >= 14) pin -= 14; // allow for channel or pin numbers
改成if (pin >= 16) pin -= 16; // allow for channel or pin numbers

但是不成功

请问大大该在哪正确着手呢?

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x
回复 支持 反对

使用道具 举报

发表于 2017-2-8 17:05:11 | 显示全部楼层
我想问你这样改的目的?
回复 支持 反对

使用道具 举报

 楼主| 发表于 2017-2-8 22:33:59 | 显示全部楼层
zjz5717 发表于 2017-2-8 17:05
我想问你这样改的目的?

因为单纯透过analogRead读取值在利用NRF24 radio.write或radio.read来控制硬件来工作,我还可以应付,
可是我对Registers有点陌生,我想了解他是怎么输入,怎么透过NRF24传送资料出去,怎么接收,..等等想要學習。
看网上有人利用语音控制硬件,这比较有噱头。
回复 支持 反对

使用道具 举报

发表于 2017-2-9 15:54:20 | 显示全部楼层
你改的这部分应该不包括你说的内容,这部分主要是根据芯片判断有多少个可用的针脚,比如你的328,在库文件中定义允许14个针脚(即0-13),当pin>=14时,pin将减去14,这个作用。
你修改之后就变成了额外允许1415也就是A0A1两个针脚,不知道你说的不成功指的是什么
回复 支持 反对

使用道具 举报

 楼主| 发表于 2017-2-9 20:48:20 | 显示全部楼层
zjz5717 发表于 2017-2-9 15:54
你改的这部分应该不包括你说的内容,这部分主要是根据芯片判断有多少个可用的针脚,比如你的328,在库文件 ...

谢谢大大的讲解,原来是我自己误会定义。
我重新读一次数据表后,有成功变成我想希望的情形,例如:原本A0输入改成A2输入...
在ADMUX里多设定一组_BV(MUX1)就可以了,其他我在自行研究\如有问题再麻烦大大帮忙解答,谢谢。
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则 需要先绑定手机号

Archiver|联系我们|极客工坊

GMT+8, 2024-3-28 18:31 , Processed in 0.047023 second(s), 20 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2021, Tencent Cloud.

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