
Receiver Code
1./*
2.* Arduino Wireless Communication Tutorial
3.* Example 2 - Receiver Code
4.*
5.* by Dejan Nedelkovski, www.HowToMechatronics.com
6.*
7.* Library: TMRh20/RF24, https://github.com/tmrh20/RF24/
8.*/
9.#include <SPI.h>
10.#include <nRF24L01.h>
11.#include <RF24.h>
12.#include <Servo.h>
13.#define button 4
14.RF24 radio(7, 8); // CE, CSN
15.const byte addresses[][6] = {"00001", "00002"};
16.Servo myServo;
17.boolean buttonState = 0;
18.void setup() {
19.pinMode(button, INPUT);
20.myServo.attach(5);
21.radio.begin();
22.radio.openWritingPipe(addresses[0]); // 00002
23.radio.openReadingPipe(1, addresses[1]); // 00001
24.radio.setPALevel(RF24_PA_MIN);
25.}
26.void loop() {
27.delay(5);
28.radio.startListening();
29.if ( radio.available()) {
30.while (radio.available()) {
31.int angleV = 0;
32.radio.read(&angleV, sizeof(angleV));
33.myServo.write(angleV);
34.}
35.delay(5);
36.radio.stopListening();
37.buttonState = digitalRead(button);
38.radio.write(&buttonState, sizeof(buttonState));
39.}
40.}
Содержание NRF24L01
Страница 8: ...Joystick Module Amazon Arduino Board Amazon Servo Motor Amazon Pushbutton Amazon LED Amazon...
Страница 14: ......