-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathBatteryTester.c
83 lines (78 loc) · 2.07 KB
/
BatteryTester.c
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
#pragma config(Sensor, dgtl1, led1, sensorLEDtoVCC)
#pragma config(Sensor, dgtl2, led2, sensorLEDtoVCC)
#pragma config(Sensor, dgtl3, led3, sensorLEDtoVCC)
#pragma config(Sensor, dgtl4, led4, sensorLEDtoVCC)
#pragma config(Sensor, dgtl5, led5, sensorLEDtoVCC)
#pragma config(Sensor, dgtl6, led6, sensorLEDtoVCC)
#pragma config(Sensor, dgtl7, led7, sensorLEDtoVCC)
#pragma config(Sensor, dgtl8, led8, sensorLEDtoVCC)
#pragma config(Motor, port2, load, tmotorServoContinuousRotation, openLoop)
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
#pragma platform(VEX)
////////////////////
// PRE AUTONOMOUS //
////////////////////
const float BAT_FULL = 8.5;
const float BAT_DEAD = 7.5;
float batAvg = 6.5;
float percentage;
task main() {
clearTimer(T1);
clearTimer(T2);
//motor[load] = 127;
while (true) {
batAvg = ((float) nAvgBatteryLevel) * 0.001;
percentage = (batAvg - BAT_DEAD) / (BAT_FULL - BAT_DEAD);
if (percentage >= 1) {
// Overcharged.
if (time1[T1] >= 250) {
SensorValue[led1] = !SensorValue[led1];
clearTimer(T1);
}
} else if (percentage >= 0.875) {
SensorValue[led1] = 1;
} else {
SensorValue[led1] = 0;
}
if (percentage >= 0.75) {
SensorValue[led2] = 1;
} else {
SensorValue[led2] = 0;
}
if (percentage >= 0.625) {
SensorValue[led3] = 1;
} else {
SensorValue[led3] = 0;
}
if (percentage >= 0.5) {
SensorValue[led4] = 1;
} else {
SensorValue[led4] = 0;
}
if (percentage >= 0.375) {
SensorValue[led5] = 1;
} else {
SensorValue[led5] = 0;
}
if (percentage >= 0.25) {
SensorValue[led6] = 1;
} else {
SensorValue[led6] = 0;
}
if (percentage >= 0.125) {
SensorValue[led7] = 1;
} else {
SensorValue[led7] = 0;
}
if (percentage > 0) {
SensorValue[led8] = 1;
} else if (percentage <= 0) {
if (time1[T2] >= 250) {
SensorValue[led8] = !SensorValue[led8];
clearTimer(T2);
}
} else {
SensorValue[led8] = 0;
}
}
}