-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpotRollover.c
51 lines (44 loc) · 1.78 KB
/
potRollover.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
#pragma config(Hubs, S1, HTMotor, HTServo, HTMotor, none)
#pragma config(Sensor, S2, proto, sensorI2CCustom9V)
#pragma config(Sensor, S3, gyro, sensorI2CHiTechnicGyro)
#pragma config(Motor, mtr_S1_C1_1, pod2Drive, tmotorNormal, openLoop)
#pragma config(Motor, mtr_S1_C1_2, pod3Drive, tmotorNormal, openLoop)
#pragma config(Motor, mtr_S1_C3_1, pod1Drive, tmotorNormal, openLoop)
#pragma config(Motor, mtr_S1_C3_2, pod0Drive, tmotorNormal, openLoop)
#pragma config(Servo, srvo_S1_C2_1, pod0Steer, tServoStandard)
#pragma config(Servo, srvo_S1_C2_2, pod1Steer, tServoStandard)
#pragma config(Servo, srvo_S1_C2_3, pod2Steer, tServoStandard)
#pragma config(Servo, srvo_S1_C2_4, pod3Steer, tServoStandard)
#pragma config(Servo, srvo_S1_C2_5, servo5, tServoNone)
#pragma config(Servo, srvo_S1_C2_6, servo6, tServoNone)
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
#include "drivers/HTSPB-driver.h"
int counts = 0;
int lastPos = 0;
int currentPos = 0;
int getPotPosition(int pos, int rollovers)
{
if ( rollovers == -1 )
return (255-pos)*-1;
if ( rollovers <= -1 )
rollovers +=1;
return pos+(rollovers*255);
}
task main()
{
lastPos = currentPos = HTSPBreadADC(proto, 0, 8);
while ( true )
{
int reading = HTSPBreadADC(proto, 0, 8);
int dif = reading-lastPos;
if ( dif > 100 )
counts--;
else if ( dif < -100 )
counts++;
currentPos = getPotPosition(reading, counts);
nxtDisplayString(0, "Rolls: %i", counts);
nxtDisplayString(1, "Value: %i", currentPos);
wait1Msec(100);
lastPos = reading;
}
}