Created
November 17, 2018 18:30
-
-
Save danjperron/d5577510110635ca2cacc699feac5794 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <SPI.h> | |
#include "nRF24L01.h" | |
#include "RF24.h" | |
#include "printf.h" | |
RF24 radio(8, 10); | |
const uint64_t pipe[2] = { 0xF0F0F0F0E1LL, 0xF0F0F0F0D2LL}; | |
int DataMsg[1]; | |
int Button1 = 2; | |
int Button3 = 4; | |
int Button4 = 6; | |
int Button5 = 7; | |
int Button2 = 3; | |
int Button10 = 3; | |
int Relay1 = 5; | |
void setup() | |
{ | |
pinMode(Button3, INPUT); | |
pinMode(Button2, INPUT); | |
pinMode(Button4, INPUT); | |
pinMode(Button1, INPUT); | |
pinMode(Button5, INPUT); | |
pinMode(Relay1, OUTPUT); | |
digitalWrite(Button1, HIGH); | |
digitalWrite(Button2, HIGH); | |
digitalWrite(Button3, HIGH); | |
digitalWrite(Button4, HIGH); | |
digitalWrite(Button5, HIGH); | |
Serial.begin(9600); | |
printf_begin(); | |
Serial.println("NRF24L01 Transmitter"); | |
radio.begin(); | |
radio.setChannel(76); // par 76 par defaux | |
radio.setRetries(15,15); | |
radio.setAutoAck(1); | |
radio.enableDynamicPayloads(); | |
radio.enableAckPayload(); | |
radio.openReadingPipe(1, pipe[0]); | |
radio.openWritingPipe(pipe[1]); | |
radio.startListening(); | |
radio.printDetails(); | |
} | |
void loop() { | |
radio.stopListening(); | |
if (digitalRead(Button1) == LOW)//recu de la telecomande pour arrete le tamis,feeder cone et feeder primaire | |
{ digitalWrite (Relay1, HIGH);// tamis stop | |
} | |
else digitalWrite (Relay1, LOW);// tamis fonctionne | |
if (digitalRead(Button1) == LOW) //envoie msg pour stop feeder du cone , du primaire et stop le tamis | |
{ | |
Serial.println("Button 1 pressed"); | |
DataMsg[0] = 1; | |
bool ok = radio.write(DataMsg, 1); | |
if (ok) | |
printf("ok..."); | |
else | |
printf("failed.\n\r"); | |
} | |
if (digitalRead(Button2) == LOW)//envois msg pour stop feeder primaire | |
{ | |
Serial.println("Button 2 pressed"); | |
DataMsg[0] = 2; | |
radio.write(DataMsg, 1); | |
} | |
if (digitalRead(Button3) == LOW)// envoie msg pour stop feeder cone | |
{ | |
Serial.println("Button 3 pressed"); | |
DataMsg[0] = 3; | |
radio.write(DataMsg, 1); | |
} | |
if (digitalRead(Button4) == LOW)//envoie msg start feeder primaire | |
{ | |
Serial.println("Button 4 pressed"); | |
DataMsg[0] = 4; | |
radio.write(DataMsg, 1); | |
} | |
if (digitalRead(Button5) == LOW) //envoie msg pour start feeder cone | |
{ | |
Serial.println("Button 5 pressed"); | |
DataMsg[0] = 5; | |
radio.write(DataMsg, 1); | |
} | |
radio.startListening(); | |
delay(100); | |
if (radio.available()) | |
{ | |
bool done = false; | |
while (!done) | |
{ | |
done = radio.read(DataMsg, 1); | |
Serial.print("NRF24L01 Receiver: "); | |
Serial.println(DataMsg[0]); | |
if (DataMsg[0] == 9)//msg recu du cone pour stop tamis et feeder primaire | |
{ | |
delay(10); | |
digitalWrite(Relay1, HIGH); | |
} | |
else digitalWrite (Relay1, LOW); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment