-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathreceiver.ino
More file actions
50 lines (41 loc) · 1.15 KB
/
receiver.ino
File metadata and controls
50 lines (41 loc) · 1.15 KB
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
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#include <Servo.h>
RF24 radio(9, 10);
const byte address[][6] = {"1Node", "2Node", "3Node", "4Node", "5Node", "6Node"};
Servo servos[5];
const int SERVO_PINS[5] = {2, 3, 4, 5, 6};
int gotByte[5];
void setup() {
Serial.begin(9600);
radio.begin();
radio.setAutoAck(true);
radio.setRetries(3, 15);
radio.enableAckPayload();
radio.setPayloadSize(sizeof(gotByte));
radio.openReadingPipe(1, address[0]);
radio.setChannel(0x60);
radio.setPALevel(RF24_PA_MAX);
radio.setDataRate(RF24_250KBPS);
radio.powerUp();
radio.startListening();
for (int i = 0; i < 5; i++) {
servos[i].attach(SERVO_PINS[i]);
servos[i].write(90); // center position on startup
}
}
void loop() {
byte pipeNo;
if (radio.available(&pipeNo)) {
radio.read(&gotByte, sizeof(gotByte));
Serial.print("Received: ");
for (int i = 0; i < 5; i++) {
gotByte[i] = constrain(gotByte[i], 1, 180);
servos[i].write(gotByte[i]);
Serial.print(gotByte[i]);
Serial.print("\t");
}
Serial.println();
}
}