Samo Penic
2022-05-16 e0a3ca6fe6dcca8b7557063a1d99ff614d9547fa
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/* There was a help from these two pages:
https://forum.arduino.cc/t/connect-nrf24l01-to-esp32/678710/4
https://electropeak.com/learn/wireless-communication-w-arduino-and-nrf24l01/
*/
 
#include <RF24_config.h>
#include <nRF24L01.h>
#include <RF24.h>
#include <printf.h>
 
#include<WiFi.h>
 
#define IN_TRIGGER 17
#define OUT_TRIGGER 16
 
 
RF24 radio(22, 21); // CE, CSN
 
const byte address[6] = {'R','E','C','V', '1'};
char dataToSend[4] = "TRG";
 
void IRAM_ATTR isr() {
//    detachInterrupt(digitalPinToInterrupt(IN_TRIGGER));
    digitalWrite(OUT_TRIGGER, LOW);
    long time=micros();
    while(micros()-time<4000);
    digitalWrite(OUT_TRIGGER,HIGH);
//        radio.write( &dataToSend, sizeof(dataToSend) );
 
//    attachInterrupt(digitalPinToInterrupt(IN_TRIGGER), isr, RISING);
  
}
 
 
 
void setup() {
  // put your setup code here, to run once:
  
  WiFi.mode(WIFI_OFF);
  btStop();
 
 
  radio.begin();
  radio.openWritingPipe(address);
  radio.setPALevel(RF24_PA_MAX);
  radio.setDataRate( RF24_250KBPS );
 
  //pinMode(IN_TRIGGER, INPUT_PULLUP);
  pinMode(OUT_TRIGGER, OUTPUT);
  digitalWrite(OUT_TRIGGER,HIGH);
  attachInterrupt(digitalPinToInterrupt(IN_TRIGGER), isr, FALLING);
  Serial.begin(115200);
 
}
 
void loop() {
  // put your main code here, to run repeatedly:
Serial.print(micros());
Serial.println(": ---> TRG");
radio.write( &dataToSend, sizeof(dataToSend) );
Serial.print(micros());
Serial.println(": TRG--->");
    delay(5000);
 
}