请问大大们有玩过声音播放机吗?
本帖最后由 v60i 于 2017-2-9 20:48 编辑我想做对讲机
在网上查了一下,有人说利用RF24Audio Library可以做
下载后在RF24Audio Library示例 - > GettingStarted中
成功的在A0说话喇叭立即播放声音
可是有一点看不明白
由他的源码看不出为什么他可以
直接放声音
这是代码
希望有大大可以帮忙解惑
GettingStarted code
#include <RF24.h>
#include <SPI.h>
#include <RF24Audio.h>
#include "printf.h" // General includes for radio and audio lib
RF24 radio(7,8); // Set radio up using pins 7 (CE) 8 (CS)
RF24Audio rfAudio(radio,1); // Set up the audio using the radio, and set to radio number 0
void setup() {
Serial.begin(115200); // Enable Arduino serial library
printf_begin(); // Radio library uses printf to output debug info
radio.begin(); // Must start the radio here, only if we want to print debug info
radio.printDetails(); // Print the info
rfAudio.begin(); // Start up the radio and audio libararies
}
void loop() {
if(Serial.available()){ // Receive and analyze incoming serial data
switch(Serial.read()){
case 'r': rfAudio.transmit(); break; // Send an r or an s over serial to control playback
case 's': rfAudio.receive();break;
case '=': rfAudio.volume(1);break; // Control volume by sending = or - over serial
case '-': rfAudio.volume(0);break;
}
}
Serial.println("test");
delay(1000);
}
RF24Audio code
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 = 1; buffEmpty = 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); // Set up reading and writing pipes
radi.openReadingPipe(1,pipes);
radi.startListening(); // Exit sending mode
TIMSK1 = _BV(ICIE1); // Enable the capture interrupt vector (handles buffering and starting of playback)
} 亲你这个不是一个有效的库文件,压缩包里面只有一个h文件 zjz5717 发表于 2017-2-1 19:38
亲你这个不是一个有效的库文件,压缩包里面只有一个h文件
对不起我已重重传一次,在麻烦下载 本帖最后由 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
但是不成功
请问大大该在哪正确着手呢?
我想问你这样改的目的? zjz5717 发表于 2017-2-8 17:05
我想问你这样改的目的?
因为单纯透过analogRead读取值在利用NRF24 radio.write或radio.read来控制硬件来工作,我还可以应付,
可是我对Registers有点陌生,我想了解他是怎么输入,怎么透过NRF24传送资料出去,怎么接收,..等等想要學習。
看网上有人利用语音控制硬件,这比较有噱头。
你改的这部分应该不包括你说的内容,这部分主要是根据芯片判断有多少个可用的针脚,比如你的328,在库文件中定义允许14个针脚(即0-13),当pin>=14时,pin将减去14,这个作用。
你修改之后就变成了额外允许1415也就是A0A1两个针脚,不知道你说的不成功指的是什么 zjz5717 发表于 2017-2-9 15:54
你改的这部分应该不包括你说的内容,这部分主要是根据芯片判断有多少个可用的针脚,比如你的328,在库文件 ...
谢谢大大的讲解,原来是我自己误会定义。
我重新读一次数据表后,有成功变成我想希望的情形,例如:原本A0输入改成A2输入...
在ADMUX里多设定一组_BV(MUX1)就可以了,其他我在自行研究\如有问题再麻烦大大帮忙解答,谢谢。
页:
[1]