Merhaba. Ben uygulamalarımda RF24-master kütüphanesini kullanıyorum. Örnek uygulama kodları aşağıda mevcut. Kütüphaneyi ekten indirebilirsin.
Alıcı kodları
#include <SPI.h>
#include &#38;#38;#34;RF24.h&#38;#38;#34;
int bilgi[1];
RF24 radio(9,10);
const uint64_t pipe = 0xE8E8F0F0E1LL;
int reset = 5;
int motor = 4;
void setup()
{
radio.begin();
radio.openReadingPipe(1,pipe);
radio.startListening();
Serial.begin(9600);
pinMode(reset, OUTPUT);
pinMode(motor, OUTPUT);
}
void loop()
{
if (radio.available())
{
bool done = false;
done = radio.read(bilgi, 1);
Serial.println(bilgi[0]);
delay(10);
}
if (bilgi[0] == 252) &#38;#38;#47;&#38;#38;#47; baslat
{
digitalWrite(motor, HIGH);
delay(5000);
digitalWrite(motor, LOW);
digitalWrite(reset,HIGH);
delay(1000);
digitalWrite(reset,LOW);
delay(1000);
}
if (bilgi[0] == 251) &#38;#38;#47;&#38;#38;#47; durdur
{
digitalWrite(motor, LOW);
digitalWrite(reset,HIGH);
delay(1000);
digitalWrite(reset,LOW);
delay(1000);
}
if (bilgi[0] == 250) &#38;#38;#47;&#38;#38;#47; calistir
{
digitalWrite(motor, HIGH);
}
}
Verici kodları:
#include <SPI.h>
#include &#38;#34;RF24.h&#38;#34;
int bilgi[1];
RF24 radio(9,10);
const uint64_t pipe = 0xE8E8F0F0E1LL;
#include <Keypad.h>
#include <Wire.h>
char customKey;
const byte ROWS = 3;
const byte COLS = 1;
char keys[ROWS][COLS] =
{
{&#38;#39;3&#38;#39;},
{&#38;#39;6&#38;#39;},
{&#38;#39;9&#38;#39;}
};
byte rowPins[ROWS] = {4, 3, 7};
byte colPins[COLS] = {2};
Keypad customKeypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS);
int reset = 5;
void setup() {
Serial.begin(9600);
radio.begin();
radio.openWritingPipe(pipe);
pinMode(reset, OUTPUT);
}
void loop()
{
customKey = customKeypad.getKey();
if (customKey == &#38;#39;3&#38;#39;) {baslat();}
if (customKey == &#38;#39;6&#38;#39;) {durdur();}
if (customKey == &#38;#39;9&#38;#39;) {calistir();}
}
void baslat()
{
Serial.println(&#38;#34;Baslat&#38;#34;);
for (int RobotikCenter = 1; RobotikCenter <= 20; RobotikCenter ++)
{
bilgi[0] = 252;
radio.write(bilgi, 1);
Serial.println(bilgi[0]);
}
digitalWrite(reset, HIGH);
delay(500);
digitalWrite(reset, LOW);
delay(500);
}
void durdur()
{
Serial.println(&#38;#34;Durdur&#38;#34;);
for (int RobotikCenter = 1; RobotikCenter <= 20; RobotikCenter ++)
{
bilgi[0] = 251;
radio.write(bilgi, 1);
Serial.println(bilgi[0]);
}
digitalWrite(reset, HIGH);
delay(500);
digitalWrite(reset, LOW);
delay(500);
}
void calistir()
{
Serial.println(&#38;#34;Calistir&#38;#34;);
for (int RobotikCenter = 1; RobotikCenter <= 20; RobotikCenter ++)
{
bilgi[0] = 250;
radio.write(bilgi, 1);
Serial.println(bilgi[0]);
}
digitalWrite(reset, HIGH);
delay(500);
digitalWrite(reset, LOW);
delay(500);
}