-
Notifications
You must be signed in to change notification settings - Fork 1
/
UWRC2.ino
215 lines (176 loc) · 5.01 KB
/
UWRC2.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
#include <Wire.h>
#include <Adafruit_PWMServoDriver.h>
Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver();
#define SERVOMIN 150
#define SERVOMAX 600
#define USMIN 600
#define USMAX 2400
#define SERVO_FREQ 60
#define DEADMAX 100
#define DEADMIN -100
int tempPin = 0;
struct JoystickConfig_s {
int xPin1Motor;
int xPin2Motor;
int xPinJoy;
int yPinJoy;
int xMax;
int xMin;
int yMax;
int yMin;
};
// Initialize default values
struct JoystickConfig_s JoystickConfigDefault = {0, 0, 0, 0, 1024, 1, 1024, 1003};
struct JoystickConfig_s joy1 = JoystickConfigDefault;
struct JoystickConfig_s joy2 = JoystickConfigDefault;
struct JoystickConfig_s joy3 = JoystickConfigDefault;
struct JoystickConfig_s joy4 = JoystickConfigDefault;
#define DEADMAX 100
#define DEADMIN -100
void setup() {
Serial.begin(9600);
pwm.begin();
pwm.setOscillatorFrequency(27000000);
pwm.setPWMFreq(50);
Wire.setClock(400000);
// define configuration for joystick 1:
joy1.xPin1Motor = 6;
joy1.xPin2Motor = 5;
joy1.xPinJoy = A0;
joy1.yPinJoy = A1;
// joystick 2:
joy2.xPin1Motor = 11; // 6
joy2.xPin2Motor = 10; // 3
joy2.xPinJoy = A2;
joy2.yPinJoy = A3;
// joystick 3 (Not ready):
joy3.xPin1Motor = 6; // 6
joy3.xPin2Motor = 7; // 3
joy3.xPinJoy = A4;
joy3.yPinJoy = A5;
// joystick 4 (not ready):
joy4.xPin1Motor = 8; // 6
joy4.xPin2Motor = 9; // 3
joy4.xPinJoy = A6;
joy4.yPinJoy = A7;
// comment goes here
pinMode(joy1.xPin1Motor, OUTPUT);
pinMode(joy1.xPin2Motor, OUTPUT);
pinMode(joy2.xPin1Motor, OUTPUT);
pinMode(joy2.xPin2Motor, OUTPUT);
pinMode(joy3.xPin1Motor, OUTPUT);
pinMode(joy3.xPin2Motor, OUTPUT);
pinMode(joy4.xPin1Motor, OUTPUT);
pinMode(joy4.xPin2Motor, OUTPUT);
}
void loop() {
int tempReading = analogRead(0);
double tempK = log(10000.0 * ((1024.0 / tempReading - 1)));
tempK = 1 / (0.001129148 + (0.000234125 + (0.0000000876741 * tempK * tempK )) * tempK ); // Temp Kelvin
float tempC = tempK - 273.15; // Convert Kelvin to Celcius
float tempF = (tempC * 9.0)/ 5.0 + 32.0; // Convert Celcius to Fahrenheit
Serial.println("=============== Thermometer ===============");
Serial.print("Temperature in Celcius: ");
Serial.print(tempC);
Serial.println();
Serial.print("Temperature in Fahrenheit: ");
Serial.print(tempF);
Serial.println();
Serial.println("============= End Thermometer =============");
// In the future, could use some loop shenanigans for this
// Joysitck 1
double xpower1 = map(analogRead(joy1.xPinJoy), joy1.xMax, joy1.xMin, 255, -255);
// NO THANK YOU double ypower1 = map(analogRead(YPJOY1), YMAX1, YMIN1, 255, -255);
// End Joystick 1
// Joysitck 2
double xpower2 = map(analogRead(joy2.xPinJoy), joy2.xMax, joy2.xMin, 255, -255);
// NO THANK YOU double ypower1 = map(analogRead(YPJOY1), YMAX1, YMIN1, 255, -255);
// End Joystick 1
// Joysitck 3
double ypower1 = map(analogRead(joy3.yPinJoy), joy3.yMax, joy3.yMin, 255, -255);
// NO THANK YOU double ypower1 = map(analogRead(YPJOY1), YMAX1, YMIN1, 255, -255);
// End Joystick 1
// Joysitck 4
double ypower2 = map(analogRead(joy4.yPinJoy), joy4.yMax, joy4.yMin, 255, -255);
// NO THANK YOU double ypower1 = map(analogRead(YPJOY1), YMAX1, YMIN1, 255, -255);
// End Joystick 1
// pwm.setPWM(servonum, 0, pulselen);
// x joystick 1
// i don't understand this
if (xpower1 > DEADMAX)
{
Serial.println("A");
analogWrite(joy1.xPin1Motor, xpower1);
analogWrite(joy1.xPin2Motor, LOW);
}
else if (xpower1 < DEADMIN)
{
Serial.println("B");
analogWrite(joy1.xPin2Motor, xpower1 * -1);
analogWrite(joy1.xPin1Motor, LOW);
}
else
{
Serial.println("N");
analogWrite(joy1.xPin1Motor , LOW);
analogWrite(joy1.xPin2Motor, LOW);
}
// x joystick 2
if (xpower2 > DEADMAX)
{
Serial.println("A");
analogWrite(joy2.xPin1Motor, xpower2);
analogWrite(joy2.xPin2Motor, LOW);
}
else if (xpower2 < DEADMIN)
{
Serial.println("B");
analogWrite(joy2.xPin2Motor, xpower2 * -1);
analogWrite(joy2.xPin1Motor, LOW);
}
else
{
Serial.println("N");
analogWrite(joy2.xPin1Motor, LOW);
analogWrite(joy2.xPin2Motor, LOW);
}
// The ys
// y joystick 1
if (ypower1 > DEADMAX)
{
Serial.println("A");
analogWrite(joy3.xPin1Motor, ypower1);
analogWrite(joy3.xPin2Motor, LOW);
}
else if (ypower1 < DEADMIN)
{
Serial.println("B");
analogWrite(joy3.xPin2Motor, ypower1 * -1);
analogWrite(joy3.xPin1Motor, LOW);
}
else
{
Serial.println("N");
analogWrite(joy3.xPin1Motor, LOW);
analogWrite(joy3.xPin2Motor, LOW);
}
// y joystick 2
if (ypower2 > DEADMAX)
{
Serial.println("A");
analogWrite(joy4.xPin1Motor, ypower2);
analogWrite(joy4.xPin2Motor, LOW);
}
else if (xpowery < DEADMIN)
{
Serial.println("B");
analogWrite(joy4.xPin2Motor, ypower2 * -1);
analogWrite(joy4.xPin1Motor, LOW);
}
else
{
Serial.println("N");
analogWrite(joy4.xPin1Motor , LOW);
analogWrite(joy4.xPin2Motor, LOW);
}
}