-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhitechnic-superpro-exp6b.c
52 lines (37 loc) · 1.15 KB
/
hitechnic-superpro-exp6b.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
#pragma config(Sensor, S1, HTSPB, sensorI2CCustom9V)
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
/* HiTechnic Experimenter's Kit for the SuperPro
Experiment - 6 Variation - Complex Reaction Time Measurement
This program measures the time taken to press a button switch after an LED is turned on.
*/
#include "drivers/hitechnic-superpro.h"
task main() {
ubyte buttonmask = 0;
// The data to be written: 0x30 = 110000 binary,
// makes B4,B5 digital ports outputs.
HTSPBsetupIO(HTSPB, 0x03);
while(true) {
// Turn off all outputs
HTSPBwriteIO(HTSPB, 0x00);
eraseDisplay();
nxtDisplayTextLine(2, "running");
wait1Msec(random(5000) + 3000);
// Turn on a random LED
if(random(1) > 0) {
HTSPBwriteIO(HTSPB, 0x01);
buttonmask = 0x10;
} else {
HTSPBwriteIO(HTSPB, 0x02);
buttonmask = 0x20;
}
time1[T1] = 0;
while (HTSPBreadIO(HTSPB, 0x30) != buttonmask) {
wait1Msec(5);
}
eraseDisplay();
nxtDisplayTextLine(2, "Time: %d", time1[T1]);
while (HTSPBreadIO(HTSPB, 0x30) != 0x30) {
wait1Msec(5);
}
}
}