-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtransmit_rf24.ino
71 lines (56 loc) · 1.96 KB
/
transmit_rf24.ino
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
66
67
68
69
70
71
#include "nRF24L01.h"
#include "RF24_config.h"
#include <SPI.h> //the communication interface with the modem
#include "RF24.h" //the library which helps us to control the radio modem
int msg[1];
//define the flex sensor input pins
int flex_5 = A5;
int flex_4 = A4;
int flex_3 = A3;
int flex_2 = A2;
int flex_1 = A1;
//define variables for flex sensor values
int flex_5_val;
int flex_4_val;
int flex_3_val;
int flex_2_val;
int flex_1_val;
RF24 radio(5,10); //5 and 10 are a digital pin numbers to which signals CE and CSN are connected.
const uint64_t pipe = 0xE8E8F0F0E1LL; //the address of the modem, that will receive data from Arduino.
void setup(void){
Serial.begin(9600);
radio.begin(); //it activates the modem.
radio.openWritingPipe(pipe); //sets the address of the receiver to which the program will send data.
}
void loop(){
flex_5_val = analogRead(flex_5);
//175 - 0
flex_5_val = map(flex_5_val, 1023, 1000, 0, 10);
msg[0] = flex_5_val;
radio.write(msg, 1);
Serial.println("sensor:5 ");
flex_4_val = analogRead(flex_4);
//175 - 0
flex_4_val = map(flex_4_val, 1023, 1000, 11, 20);
msg[0] = flex_4_val;
radio.write(msg, 1);
Serial.println("sensor:4 ");
flex_3_val = analogRead(flex_3);
//175 - 0
flex_3_val = map(flex_3_val, 1023, 1000, 21, 30);
msg[0] = flex_3_val;
radio.write(msg, 1);
Serial.println("sensor:3 ");
flex_2_val = analogRead(flex_2);
//175 - 0
flex_2_val = map(flex_2_val, 1023, 1000, 31, 40);
msg[0] = flex_2_val;
radio.write(msg, 1);
Serial.println("sensor: 2");
flex_1_val = analogRead(flex_1);
//175 - 0
flex_1_val = map(flex_1_val, 1023, 1000, 41, 50);
msg[0] = flex_1_val;
radio.write(msg, 1);
Serial.println("sensor: 1");
}