//VERICI KODUM include <spi.h> //Call SPI library so you can communicate with the nRF24L01+
include <nrf24l01.h> //nRF2401 libarary
include <rf24.h> //nRF2401 libarary
include “I2Cdev.h” //I2C kütüphanesi
include “MPU6050.h” //Mpu6050 kütüphanesi
include “Wire.h”
MPU6050 accelgyro; // Mpu6050 sensör tanımlama
int16_t ax[3]; //ivme tanımlama
int16_t gx, gy, gz; //gyro tanımlama
const int pinCE = 9; //This pin is used to
const int pinCSN = 10; //This pin is used to
RF24 radio(pinCE, pinCSN);
define WHICH_NODE 2 // must be a number from 1 - 4 identifying the PTX node
const uint64_t wAddress = {0x7878787878LL, 0xB3B4B5B6F1LL, 0xB3B4B5B6CDLL, 0xB3B4B5B6A3LL, 0xB3B4B5B60FLL, 0xB3B4B5B605LL};
const uint64_t PTXpipe = wAddress[WHICH_NODE - 1]; // Pulls the address from the above array for this node’s pipe
byte counter = 1; //used to count the packets sent
bool done = false; //used to know when to stop sending packets
int32_t veri;
void setup()
{
Wire.begin();
Serial.println(“I2C cihazlar başlatılıyor…”);
accelgyro.initialize();
Serial.println(“Test cihazı bağlantıları…”);
Serial.println(accelgyro.testConnection() ? “MPU6050 bağlantı başarılı” : “MPU6050 bağlantısı başarısız”);
Serial.begin(115200); //start serial to communicate process
radio.begin(); //Start the nRF24 module
radio.setPALevel(RF24_PA_LOW); // “short range setting” - increase if you want more range AND have a good power supply
radio.setChannel(108); // the higher channels tend to be more “open”
radio.openReadingPipe(0, PTXpipe); //open reading or receive pipe
radio.stopListening(); //go into transmit mode
}
void loop()
{
if (!done) { //true once you guess the right number
radio.openWritingPipe(PTXpipe); //open writing or transmit pipe
sensor();
if (!radio.write( &ax, 6 )) { //if the write fails let the user know over serial monitor
Serial.println("Guess delivery failed");
}
else { //if the write was successful
Serial.print("Success sending guess: ");
radio.startListening(); //switch to receive mode to see if the guess was right
unsigned long startTimer = millis(); //start timer, we will wait 200ms
bool timeout = false;
while ( !radio.available() && !timeout ) { //run while no receive data and not timed out
if (millis() - startTimer > 200 ) timeout = true; //timed out
}
if (timeout) Serial.println("Last guess was wrong, try again"); //no data to receive guess must have been wrong
else { //we received something so guess must have been right
byte daNumber; //variable to store received value
radio.read( &daNumber, 1); //read value
if (daNumber == ax[0]) { //make sure it equals value we just sent, if so we are done
Serial.println("You guessed right so you are done");
done = true; //signal to loop that we are done guessing
}
else Serial.println("Something went wrong, keep guessing"); //this should never be true, but just in case
}
radio.stopListening(); //go back to transmit mode
}
}
delay(1000);
}
void sensor() {
accelgyro.getMotion6(&ax[0], &ax[1], &ax[2], &gx, &gy, &gz); // ivme ve gyro değerlerini okuma
}</rf24.h></nrf24l01.h></spi.h>