This repository has been archived by the owner on May 17, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
a315-part2-ben_godfrey.c
76 lines (60 loc) · 2.67 KB
/
a315-part2-ben_godfrey.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
#pragma config(Sensor, in1, potentiometer, sensorPotentiometer)
#pragma config(Sensor, in2, light, sensorReflection)
#pragma config(Sensor, in3, lineFollower, sensorLineFollower)
#pragma config(Sensor, dgtl1, sonar, sensorSONAR_inch)
#pragma config(Sensor, dgtl3, encoder, sensorQuadEncoder)
#pragma config(Sensor, dgtl5, bump, sensorTouch)
#pragma config(Sensor, dgtl6, limit, sensorTouch)
#pragma config(Sensor, dgtl11, led, sensorLEDtoVCC)
#pragma config(Motor, port1, flashlight, tmotorVexFlashlight, openLoop, reversed)
#pragma config(Motor, port2, rMotor, tmotorVex393_MC29, openLoop)
#pragma config(Motor, port8, servo, tmotorServoStandard, openLoop)
#pragma config(Motor, port9, lMotor, tmotorVex269_MC29, openLoop)
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
/* Ben Godfrey *
* POE 8th Period *
* Activity 3.1.5 *
* 03/22/2017 */
typedef struct { // define object type "record" with 3 properties.
string label; // Label of the record
int min; // Minimum record value
int max; // Maximum record value
} record;
void resetRecord(record &inputRecord, int inputValue) { // clears records
inputRecord.min = inputValue; // set min on record to default
inputRecord.max = inputValue; // set max on record to default
}
void checkRecord(record &inputRecord, int inputValue) { //compares data to min/max
if (inputValue > inputRecord.max) { // if input greater than max on record,
inputRecord.max = inputValue; // set max on record
}
if (inputValue < inputRecord.min) { // if input less than min on record,
inputRecord.min = inputValue; // set min on record
}
}
void logRecord(record inputRecord) { // write record info to console on computer for monitoring
writeDebugStreamLine("%s: %d-%d", inputRecord.label, inputRecord.min, inputRecord.max);
}
task main() {
// declare records
record potentialRecord;
record sonarRecord;
// set record labels
potentialRecord.label = "Potentiometer";
sonarRecord.label = "Sonar";
// clear all records
resetRecord(potentialRecord, SensorValue[potentiometer]);
resetRecord(sonarRecord, SensorValue[sonar]);
while (true) {
// check all records against their sensors and make changes.
checkRecord(potentialRecord, SensorValue[potentiometer]);
checkRecord(sonarRecord, SensorValue[sonar]);
// clear console before writing data
clearDebugStream();
// log/output record data to console for viewing
logRecord(potentialRecord);
logRecord(sonarRecord);
// stop program if button pressed
if (SensorValue[bump] == 1) { break; }
}
}