-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.ino
84 lines (60 loc) · 2.07 KB
/
main.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/*
DESCRIPTION
Simple example for creating a walkie talkie by sending audio
using the nRF24L01 RF transceiver module.
DISCLAIMER
This code is in the public domain. Please feel free to modify,
use, etc however you see fit. But, please give reference to
original authors as a courtesy to Open Source developers.
Modified example from RF24 Audio Library by TMRh20. Comments
from TMRh20 below.
*/
/* RF24 Audio Library TMRh20 2014
This sketch is intended to demonstrate the basic functionality of the audio library.
Requirements:
2 Arduinos (Uno,Nano,Mega, etc supported)
2 NRF24LO1 Radio Modules
1 or more input devices (microphone, ipod, etc)
1 or more output devices (speaker, amplifier, etc)
Setup:
1. Change the CE,CS pins below to match your chosen pins (I use 7,8 on 328 boards, and 48,49 on Mega boards)
2. Upload this sketch to two or more devices
3. Default Pin Selections:
Speaker: pins 9,10 on UNO, Nano, pins 11,12 on Mega 2560
Input/Microphone: Analog pin A0 on all boards
*/
#include <RF24.h>
#include <SPI.h>
#include "printf.h" // General includes for radio and audio lib
#include <RF24Audio.h>
RF24 radio(7, 8); // Set radio up using pins 7 (CE) 8 (CS)
RF24Audio rfAudio(radio, 0); // Set up the audio using the radio, and set to radio number 0
int talkButton = 3;
void setup() {
Serial.begin(115200);
printf_begin();
radio.begin();
radio.printDetails();
rfAudio.begin();
pinMode(talkButton, INPUT);
//sets interrupt to check for button talk abutton press
attachInterrupt(digitalPinToInterrupt(talkButton), talk, CHANGE);
//sets the default state for each module to recevie
rfAudio.receive();
}
//void talk()
//Called in response to interrupt. Checks the state of the button.
//If the button is pressed (and held) enters transmit mode to send
//audio. If button is release, enters receive mode to listen.
void talk()
{
if (digitalRead(talkButton)) {
rfAudio.transmit();
}
else {
rfAudio.receive();
}
}
void loop()
{
}