1#include "UnoJoy.h"
2
3
4int channel_1;
5int channel_2;
6int channel_3;
7int channel_4;
8
9int ch1;
10int ch2;
11int ch3;
12int ch4;
13
14
15void setup(){
16 setupPins();
17 setupUnoJoy();
18
19}
20
21void loop(){
22
23
24 dataForController_t controllerData = getControllerData();
25 setControllerData(controllerData);
26
27
28}
29
30void setupPins(void){
31
32 for (int i = 2; i <= 12; i++){
33 pinMode(i, INPUT);
34 digitalWrite(i, HIGH);
35 }
36}
37
38dataForController_t getControllerData(void){
39
40
41 dataForController_t controllerData = getBlankDataForController();
42
43
44 channel_1 = pulseIn (2, HIGH);
45 channel_2 = pulseIn (3, HIGH);
46 channel_3 = pulseIn (4, HIGH);
47 channel_4 = pulseIn (5, HIGH);
48
49
50 ch1 = map(constrain(channel_1, 1000, 2000), 1000, 2000, 0, 255);
51 ch2 = map(constrain(channel_2, 1000, 2000), 1000, 2000, 0, 255);
52 ch3 = map(constrain(channel_3, 1000, 2000), 1000, 2000, 0, 255);
53 ch4 = map(constrain(channel_4, 1000, 2000), 1000, 2000, 0, 255);
54
55
56 controllerData.leftStickX = ch1;
57 controllerData.leftStickY = ch2;
58 controllerData.rightStickX = ch3;
59 controllerData.rightStickY = ch4;
60
61 return controllerData;
62}