Skip to content

Commit f745c93

Browse files
committed
Changes to button handling
- Remove IRQ driven button handling due to a bug where a device would stop receiving audio after a button press - Add handleButtons() function to public interface due to changes - Fix example missing serial.begin()
1 parent 8516dd6 commit f745c93

File tree

7 files changed

+51
-47
lines changed

7 files changed

+51
-47
lines changed

RF24Audio.cpp

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,6 @@ void RF24Audio::begin()
8989
timerStart(); // Get the timer running
9090
RX(); // Start listening for transmissions
9191

92-
#if !defined (MANUAL_BUTTON_HANDLING)
93-
TIMSK0 |= _BV(OCIE0B);
94-
#endif
9592
}
9693

9794

@@ -124,9 +121,8 @@ void RF24Audio::timerStart()
124121
TCCR1B = _BV(WGM13) | _BV(WGM12) | _BV(CS10); //CS10 = no prescaling
125122
}
126123

127-
#if !defined (MANUAL_BUTTON_HANDLING)
128124

129-
void handleButtons()
125+
void RF24Audio::handleButtons()
130126
{
131127
boolean state = digitalRead(TX_PIN); //Get the state of the transmitting pin
132128

@@ -172,7 +168,7 @@ void handleButtons()
172168
}
173169
}
174170

175-
#endif //Manual button handling override
171+
//#endif //Manual button handling override
176172

177173
void rampDown()
178174
{
@@ -258,14 +254,6 @@ void RF24Audio::receive()
258254
RX();
259255
}
260256

261-
// Allows users to totally customize button handling or disable it
262-
#if !defined MANUAL_BUTTON_HANDLING
263-
ISR(TIMER0_COMPB_vect) { // Non-blocking interrupt vector for button management. Is triggered ~1000 times/second by default on Arduino
264-
handleButtons(); // Check for external button presses at the default timer0 rate
265-
}
266-
#endif
267-
268-
269257
uint64_t RF24Audio::getAddress(byte addressNo)
270258
{
271259
return pipes[addressNo];

RF24Audio.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,11 @@ class RF24Audio
120120
*/
121121
uint64_t getAddress(byte addressNo);
122122

123-
123+
/**
124+
* Handle button inputs. Must be called regularly for button functionality
125+
*/
126+
void handleButtons();
127+
124128
private:
125129
RF24& radio;
126130
void timerStart();

examples/GettingStarted/GettingStarted.ino

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,33 +24,40 @@ Input/Microphone: Analog pin A0 on all boards
2424
#include <RF24.h>
2525
#include <SPI.h>
2626
#include <RF24Audio.h>
27-
#include "printf.h" // General includes for radio and audio lib
27+
#include "printf.h" // General includes for radio and audio lib
2828

29-
RF24 radio(7,8); // Set radio up using pins 7 (CE) 8 (CS)
30-
RF24Audio rfAudio(radio,1); // Set up the audio using the radio, and set to radio number 0
29+
RF24 radio(7,8); // Set radio up using pins 7 (CE) 8 (CS)
30+
RF24Audio rfAudio(radio,1); // Set up the audio using the radio, and set to radio number 0
3131

32-
void setup() {
33-
Serial.begin(115200); // Enable Arduino serial library
32+
void setup() {
33+
Serial.begin(115200); // Enable Arduino serial library
3434

3535
printf_begin(); // Radio library uses printf to output debug info
3636
radio.begin(); // Must start the radio here, only if we want to print debug info
3737
radio.printDetails(); // Print the info
3838

39-
rfAudio.begin(); // Start up the radio and audio libararies
39+
rfAudio.begin(); // Start up the radio and audio libararies
4040
}
4141

42+
uint32_t printTimer = 0;
43+
4244
void loop() {
4345

44-
if(Serial.available()){ // Receive and analyze incoming serial data
46+
rfAudio.handleButtons(); //Handling of button inputs
47+
48+
if(Serial.available()){ // Receive and analyze incoming serial data
4549
switch(Serial.read()){
46-
case 'r': rfAudio.transmit(); break; // Send an r or an s over serial to control playback
50+
case 'r': rfAudio.transmit(); break; // Send an r or an s over serial to control playback
4751
case 's': rfAudio.receive(); break;
48-
case '=': rfAudio.volume(1); break; // Control volume by sending = or - over serial
52+
case '=': rfAudio.volume(1); break; // Control volume by sending = or - over serial
4953
case '-': rfAudio.volume(0); break;
5054
}
5155
}
52-
Serial.println("test");
53-
delay(1000);
56+
57+
if(millis() - printTimer > 1000){
58+
printTimer = millis();
59+
Serial.println("test");
60+
}
5461
}
5562

5663

examples/Minimal/Minimal.ino

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,21 +34,23 @@ Note: Pin selections can be overridden by modifying the userConfig.h file includ
3434
#include <SPI.h>
3535
#include <RF24Audio.h>
3636

37-
RF24 radio(7,8); // Set radio up using pins 7 (CE) 8 (CS)
38-
RF24Audio rfAudio(radio,1); // Set up the audio using the radio, and set to radio number 0.
37+
RF24 radio(7,8); // Set radio up using pins 7 (CE) 8 (CS)
38+
RF24Audio rfAudio(radio,1); // Set up the audio using the radio, and set to radio number 0.
3939
// Setting the radio number is only important if one-to-one communication is desired
40-
// in a multi-node radio group. See the privateBroadcast() function.
40+
// in a multi-node radio group. See the privateBroadcast() function.
4141

42-
void setup() {
42+
void setup() {
4343

44-
rfAudio.begin(); // The only thing to do is initialize the library.
44+
rfAudio.begin(); // Initialize the library.
4545

4646
}
4747

4848
void loop() {
4949

50-
// Audio playback and button handling is all managed internally.
50+
rfAudio.handleButtons();
51+
// Audio playback is all managed internally.
5152
// In this example, the radio is controlled by external buttons, so there is nothing to do here
53+
// except handle the buttons.
5254

5355
}
5456

examples/PrivateChannels/PrivateChannels.ino

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,21 +31,24 @@ to establish node-to-node communication between each other.
3131
#include <SPI.h>
3232
#include <RF24Audio.h>
3333

34-
RF24 radio(7,8); // Set radio up using pins 7 (CE) 8 (CS)
34+
RF24 radio(7,8); // Set radio up using pins 7 (CE) 8 (CS)
3535

3636
/********* Set the Radio Identifier Here ************/
37-
RF24Audio rfAudio(radio,0); // Set up the audio using the radio, and set to radio number 0.
38-
// Setting the radio number is only important if one-to-one communication is desired
39-
// in a multi-node radio group. See the private
37+
RF24Audio rfAudio(radio,0); // Set up the audio using the radio, and set to radio number 0.
38+
// Setting the radio number is only important if one-to-one communication is desired
39+
// in a multi-node radio group. See the private
40+
41+
void setup() {
4042

41-
void setup() {
4243
Serial.begin(115200);
43-
rfAudio.begin(); // The only thing to do is initialize the library.
44+
rfAudio.begin(); // The only thing to do is initialize the library.
4445

4546
}
4647

4748
void loop() {
4849

50+
rfAudio.handleButtons();
51+
4952
if(Serial.available()){
5053
switch(Serial.read()){
5154
case 'r': rfAudio.transmit(); break;

examples/PrivateGroups/PrivateGroups.ino

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ Note: Pin selections can be overridden by modifying the userConfig.h file includ
3030
#include <RF24Audio.h>
3131
//#include "printf.h"
3232

33-
RF24 radio(7,8); // Set radio up using pins 7 (CE) 8 (CS)
34-
RF24Audio rfAudio(radio,0); // Set up the audio using the radio, and set to radio number 0.
35-
// Setting the radio number is only important if one-to-one communication is desired
36-
// in a multi-node radio group. See the privateBroadcast() function.
33+
RF24 radio(7,8); // Set radio up using pins 7 (CE) 8 (CS)
34+
RF24Audio rfAudio(radio,0); // Set up the audio using the radio, and set to radio number 0.
35+
// Setting the radio number is only important if one-to-one communication is desired
36+
// in a multi-node radio group. See the privateBroadcast() function.
3737

3838

3939
// This is a sketch used for demonstrating the multicast capabilities of the radios
@@ -50,10 +50,10 @@ Read Addy: 11 11 10 10 11 4 // Any radio listening on an address that is s
5050
Read Addy: 13 12 12 12 13 5
5151
*/
5252

53-
void setup() {
54-
53+
void setup() {
54+
5555
//Serial.begin(115200);
56-
rfAudio.begin(); // The only thing to do is initialize the library.
56+
rfAudio.begin(); // The only thing to do is initialize the library.
5757
//printf_begin();
5858
//radio.printDetails();
5959

@@ -71,7 +71,8 @@ broadcast to that address **/
7171

7272
void loop() {
7373

74-
// Audio playback and button handling is all managed internally.
74+
rfAudio.handleButtons();
75+
// Audio playback is all managed internally.
7576
// In this example, the radio is controlled by external buttons, so there is nothing to do here
7677

7778
}

userConfig.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@
4646

4747
/************ Optional/Advanced User Variables ************/
4848

49-
//#define MANUAL_BUTTON_HANDLING // Disables button handling via timer0. Allow users to customize button handling
5049

5150
/** Button pin to trigger recording & transmission */
5251
#define TX_PIN A1

0 commit comments

Comments
 (0)