forked from MDL29/JacoBot
Start integrate NRF24 module
Author: Linux_Hat <adrien@d4x.fr>
This commit is contained in:
parent
c2213b3991
commit
0fdb58b6cc
|
@ -1,11 +1,13 @@
|
|||
//The sample code for driving one way motor encoder
|
||||
#include <PID_v1.h>
|
||||
#include <Arduino.h>
|
||||
#include "radio.h"
|
||||
#include "MotorEncoder.h"
|
||||
|
||||
MotorEncoder m1(2, 8, 5, 4); //Initialise motor with pins
|
||||
MotorEncoder m2(3, 9, 11, 10); //Initialise motor with pins
|
||||
|
||||
Radio radio(120, 6, 7);
|
||||
|
||||
void encoder_handler_m1() {
|
||||
m1.wheelSpeed(); // Call wheelSpeed() of the m1 MotorEncoder instance
|
||||
}
|
||||
|
|
27
jacobot/arduino/radio.cpp
Normal file
27
jacobot/arduino/radio.cpp
Normal file
|
@ -0,0 +1,27 @@
|
|||
#include <RF24.h>
|
||||
#include <SPI.h>
|
||||
#include <Arduino.h>
|
||||
#include "radio.h"
|
||||
|
||||
Radio::Radio(int canal, int pinCE, int pinCSN) {
|
||||
m_canal = canal;
|
||||
m_pinCE = pinCE;
|
||||
m_pinCSN = pinCSN;
|
||||
radio = new RF24(pinCE, pinCSN);
|
||||
if (!radio->begin()) {
|
||||
Serial.println("Error while initialise the NRF module");
|
||||
while (1);
|
||||
}
|
||||
Serial.println("Module initialised");
|
||||
radio->openReadingPipe(0, adresse);
|
||||
radio->setChannel(canal);
|
||||
radio->setPALevel(RF24_PA_MIN);
|
||||
radio->startListening();
|
||||
}
|
||||
|
||||
char Radio::read() {
|
||||
if (radio->available()) {
|
||||
radio->read(&message, sizeof(message));
|
||||
return *message;
|
||||
}
|
||||
}
|
18
jacobot/arduino/radio.h
Normal file
18
jacobot/arduino/radio.h
Normal file
|
@ -0,0 +1,18 @@
|
|||
#pragma once
|
||||
#include <RF24.h>
|
||||
#include <SPI.h>
|
||||
#include <Arduino.h>
|
||||
#define tunnel "PIPE1"
|
||||
|
||||
class Radio {
|
||||
public:
|
||||
Radio(int canal, int pinCE, int pinCSN);
|
||||
char read();
|
||||
char message[32];
|
||||
private:
|
||||
int m_canal;
|
||||
int m_pinCE;
|
||||
int m_pinCSN;
|
||||
RF24* radio;
|
||||
const byte adresse[6] = tunnel;
|
||||
};
|
Loading…
Reference in New Issue
Block a user