-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmindsensors-ps2ctrl-v4-test2.c
101 lines (85 loc) · 3.21 KB
/
mindsensors-ps2ctrl-v4-test2.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#pragma config(Sensor, S1, PSPNXV4, sensorI2CCustom)
#pragma config(Motor, motorA, ARMS, tmotorNormal, PIDControl, encoder)
#pragma config(Motor, motorB, RIGHT, tmotorNormal, PIDControl, encoder)
#pragma config(Motor, motorC, LEFT, tmotorNormal, PIDControl, encoder)
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
/*
* $Id: mindsensors-ps2ctrl-v4-test2.c 133 2013-03-10 15:15:38Z xander $
*/
/**
* mindsensors-ps2ctrl-v4.h provides an API for the Mindsensors PS2 controller sensor
* with referee signal receiver. This program demonstrates how to use that API
*
* Changelog:
* - 0.1: Initial release
*
* Credits:
* - Big thanks to Mindsensors for providing me with the hardware necessary to write and test this.
*
* License: You may use this code as you wish, provided you give credit where it's due.
*
* THIS CODE WILL ONLY WORK WITH ROBOTC VERSION 3.59 AND HIGHER.
* Xander Soldaat (xander_at_botbench.com)
* 02 August 2012
* version 0.1
*/
#include "drivers/mindsensors-ps2ctrl-v4.h"
task main ()
{
ubyte counter = 0;
ubyte oldCounter = 0;
ubyte refSignal = 0;
ubyte oldRefSignal = 0;
ubyte txType = 0;
long rawValue = 0;
nxtDisplayCenteredTextLine(0, "Mindsensors");
nxtDisplayCenteredBigTextLine(1, "PSP-Nx");
nxtDisplayCenteredTextLine(3, "Test 2");
wait1Msec(2000);
PlaySound(soundBeepBeep);
while(bSoundActive) EndTimeSlice();
eraseDisplay();
while (true)
{
// Get the current counter value, wraps at 255
counter = PSPV4readRefSignalCount(PSPNXV4);
if (oldCounter != counter)
{
// This is the command sent by the remote control, can be:
// PSPV4_SIGNAL_FAST_REWIND
// PSPV4_SIGNAL_FAST_FORWARD
// PSPV4_SIGNAL_PLAY
// PSPV4_SIGNAL_STOP
refSignal = PSPV4readRefSignal(PSPNXV4);
// Get the transmitted type. Not very useful in most cases unless
// you need to know what type of transmitter sent the command
txType = PSPV4readRefTXType(PSPNXV4);
// Raw value will also "see" commands from the remote
// that are not recognised as "play", "stop", "forward" or "rewind".
// You could use this to control additional aspects of your robot!
rawValue = PSPV4readRawRefTXValue(PSPNXV4);
if (oldRefSignal != refSignal)
{
PlaySound(soundShortBlip);
switch(refSignal)
{
case PSPV4_SIGNAL_FAST_REWIND: nxtDisplayCenteredBigTextLine(3,"REWIND"); break;
case PSPV4_SIGNAL_FAST_FORWARD: nxtDisplayCenteredBigTextLine(3,"FORWARD"); break;
case PSPV4_SIGNAL_PLAY: nxtDisplayCenteredBigTextLine(3,"PLAY"); break;
case PSPV4_SIGNAL_STOP: nxtDisplayCenteredBigTextLine(3,"STOP"); break;
}
}
// Always display the raw value, even if it's not one of the four
// referee signals. Handy if you want to add more commands to your robot!
nxtDisplayTextLine(6, "Type: 0x%02X", txType);
nxtDisplayTextLine(7, "Raw: 0x%03X", rawValue);
// Update the counters and signals
oldCounter = counter;
oldRefSignal = refSignal;
}
wait1Msec(50);
}
}
/*
* $Id: mindsensors-ps2ctrl-v4-test2.c 133 2013-03-10 15:15:38Z xander $
*/