-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontroller.c
More file actions
74 lines (65 loc) · 1.6 KB
/
Copy pathcontroller.c
File metadata and controls
74 lines (65 loc) · 1.6 KB
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
72
73
74
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
// constants won't change. They're used here to set pin numbers:
const int buttonPinRight = 4;
const int buttonPinLeft = 2;
const int buttonPinUp = 10;
const int buttonPinDown = 5;
// the number of the pushbutton pin
RF24 radio(7, 8); // CE, CSN
const byte address[6] = "00001";
variables will change:
int buttonStateLeft = 0;
int buttonStateRight = 0;
int buttonStateUp = 0;
int buttonStateDown = 0;
// variable for reading the pushbutton status
//variable to hold data
int sup = 0;
void setup() {
// initialize the LED pin as an output:
// initialize the pushbutton pin as an input:
pinMode(buttonPinRight, INPUT);
pinMode(buttonPinLeft, INPUT);
pinMode(buttonPinUp, INPUT);
pinMode(buttonPinDown, INPUT);
radio.begin();
radio.openWritingPipe(address);
radio.setPALevel(RF24_PA_MIN);
radio.stopListening();
Serial.begin(9600);
}
void loop() {
// read the state of the pushbutton value:
buttonStateRight = digitalRead(buttonPinRight);
buttonStateLeft = digitalRead(buttonPinLeft);
buttonStateUp = digitalRead(buttonPinUp);
buttonStateDown = digitalRead(buttonPinDown);
// check if the pushbutton is pressed. If it is, the buttonState is HIGH:
if (buttonStateRight == 1)
{
sup = 4;
Serial.write("4");
}
else if(buttonStateLeft == 1)
{
sup = 3;
Serial.write("3");
}
else if (buttonStateUp == 1) {
sup = 1;
Serial.write("1");
}
else if (buttonStateDown == 1)
{
sup = 2;
Serial.write("2");
}
else
{
sup = 0;
Serial.write("0");
}
radio.write(&sup, sizeof(sup));
}