├── .gitignore
├── README.md
├── README.txt
├── doc
└── images
│ ├── LOGO_NXT.gif
│ └── logo.png
├── examples
├── benedetelli-nxt2wifi-config.c
├── benedettelli-nxt2wifi-setup.c
├── benedettelli-nxt2wifi-test2.c
├── benedettelli-nxt2wifi-test3.c
├── benedettelli-nxt2wifi-test4.c
├── codatech-rfid-test1.c
├── codatech-rfid-test2.c
├── dexterind-compass-test1.c
├── dexterind-compass-test2.c
├── dexterind-compass-test3.c
├── dexterind-dlight-test1.c
├── dexterind-flex-test1.c
├── dexterind-flex-test2.c
├── dexterind-gps-test1.c
├── dexterind-imu-test1.c
├── dexterind-imu-test2.c
├── dexterind-imu-test3.c
├── dexterind-nxtchuck-test1.c
├── dexterind-pressure-test1.c
├── dexterind-temp-test1.c
├── dexterind-thermalir-test1.c
├── dexterind-thermalir-test2.c
├── dexterind-wifi-config.c
├── dexterind-wifi.c
├── firgelli-linearact-test1.c
├── firgelli-linearact-test2.c
├── firgelli-linearact-test3.c
├── hitechnic-accelerometer-SMUX-test1.c
├── hitechnic-accelerometer-test1.c
├── hitechnic-angle-SMUX-test1.c
├── hitechnic-angle-test1.c
├── hitechnic-barometer-SMUX-test1.c
├── hitechnic-barometer-test1.c
├── hitechnic-colour-v2-SMUX-test1.c
├── hitechnic-colour-v2-configure.c
├── hitechnic-colour-v2-test1.c
├── hitechnic-compass-SMUX-test1.c
├── hitechnic-compass-test1.c
├── hitechnic-compass-test2.c
├── hitechnic-eopd-SMUX-test1.c
├── hitechnic-eopd-test1.c
├── hitechnic-force-SMUX-test1.c
├── hitechnic-force-test1.c
├── hitechnic-gyro-SMUX-test1.c
├── hitechnic-gyro-test1.c
├── hitechnic-irlink-rcx-test1.c
├── hitechnic-irlink-test1.c
├── hitechnic-irrecv-test1.c
├── hitechnic-irseeker-v2-SMUX-test1.c
├── hitechnic-irseeker-v2-test1.c
├── hitechnic-magfield-SMUX-test1.c
├── hitechnic-magfield-test1.c
├── hitechnic-pir-test1.c
├── hitechnic-protoboard-SMUX-test1.c
├── hitechnic-protoboard-SMUX-test2.c
├── hitechnic-protoboard-exp1.c
├── hitechnic-protoboard-exp2.c
├── hitechnic-protoboard-exp3.c
├── hitechnic-protoboard-exp4.c
├── hitechnic-protoboard-exp5.c
├── hitechnic-protoboard-exp6a.c
├── hitechnic-protoboard-exp6b.c
├── hitechnic-protoboard-exp7.c
├── hitechnic-protoboard-exp8.c
├── hitechnic-protoboard-test1.c
├── hitechnic-protoboard-test2.c
├── hitechnic-protoboard-test3.c
├── hitechnic-superpro-exp1.c
├── hitechnic-superpro-exp2.c
├── hitechnic-superpro-exp3.c
├── hitechnic-superpro-exp4.c
├── hitechnic-superpro-exp5.c
├── hitechnic-superpro-exp6a.c
├── hitechnic-superpro-exp6b.c
├── hitechnic-superpro-exp7.c
├── hitechnic-superpro-exp8.c
├── hitechnic-superpro-exp9.c
├── hitechnic-touchmux-test1.c
├── holitdata-motormux-test1.c
├── holitdata-motormux-test2.c
├── humarobotics-wifiblock-test1.c
├── lego-energymeter-test1.c
├── lego-light-SMUX-test1.c
├── lego-light-SMUX-test2.c
├── lego-light-test1.c
├── lego-light-test2.c
├── lego-sound-SMUX-test1.c
├── lego-temp-test1.c
├── lego-touch-SMUX-test1.c
├── lego-touch-test1.c
├── lego-ultrasound-SMUX-test1.c
├── mainpage.h
├── math-matrix-test1.c
├── microinfinity-cruizcore-test1.c
├── microinfinity-cruizcore-test2.c
├── mindensors-servo-test1.c
├── mindsensors-accelerometer-test1.c
├── mindsensors-accelerometer-test2.c
├── mindsensors-angle-test1.c
├── mindsensors-angle-test2.c
├── mindsensors-ev3-grove-test1.c
├── mindsensors-ev3-grove-test2.c
├── mindsensors-ev3smux-test1.c
├── mindsensors-hid-test1.c
├── mindsensors-imu-test1.c
├── mindsensors-imu-test2.c
├── mindsensors-imu-test3.c
├── mindsensors-irdist-test1.c
├── mindsensors-irthermometer-test1.c
├── mindsensors-ligthsensrarr-test1.c
├── mindsensors-ligthsensrarr-test2.c
├── mindsensors-ligthsensrarr-test3.c
├── mindsensors-lineleader-test2.c
├── mindsensors-lineleader-test3.c
├── mindsensors-lineleader-test4.c
├── mindsensors-lineleader-test5.c
├── mindsensors-magicwand-test1.c
├── mindsensors-motormux-test1.c
├── mindsensors-motormux-test2.c
├── mindsensors-numericpad-test1.c
├── mindsensors-nxtcam-test1.c
├── mindsensors-nxtcam-test2.c
├── mindsensors-pfmate-test1.c
├── mindsensors-powermeter-test1.c
├── mindsensors-pressure-test1.c
├── mindsensors-ps2ctrl-v4-test1.c
├── mindsensors-ps2ctrl-v4-test2.c
├── mindsensors-ps2ctrl-v4-test3.c
├── mindsensors-rcxmotormux-test1.c
├── mindsensors-rcxsensorsmux-test1.c
├── mindsensors-sensormux-test1.c
├── mindsensors-sensormux-test2.c
├── mindsensors-sumoeyes-test1.c
├── mindsensors-sumoeyes-test2.c
├── mindsensors-touchmux-SMUX-test1.c
├── mindsensors-touchmux-test1.c
├── mindsensors-touchpanel-test1.c
├── monkey01.ric
├── monkey02.ric
├── monkey03.ric
├── monkey04.ric
├── monkey05.ric
├── monkey06.ric
├── monkey07.ric
├── philips-pcf8574-test1.c
├── stats-test1.c
├── sumoLF.ric
├── sumoLL.ric
├── sumoLR.ric
├── sumoSF.ric
├── sumoSL.ric
├── sumoSR.ric
├── sumonone.ric
└── timer-test1.c
├── header.txt
├── include
├── benedettelli-nxt2wifi.h
├── codatech-rfid.h
├── common-light.h
├── common-mmux.h
├── common-rs485.h
├── common.h
├── dexterind-compass.h
├── dexterind-dlight.h
├── dexterind-flex.h
├── dexterind-gps.h
├── dexterind-imu.h
├── dexterind-nxtchuck.h
├── dexterind-pressure.h
├── dexterind-temp.h
├── dexterind-thermalir.h
├── dexterind-wifi.h
├── firgelli-linearact-ramping.h
├── firgelli-linearact.h
├── hitechnic-accelerometer.h
├── hitechnic-angle.h
├── hitechnic-barometer.h
├── hitechnic-colour-v2.h
├── hitechnic-compass.h
├── hitechnic-eopd.h
├── hitechnic-force.h
├── hitechnic-gyro.h
├── hitechnic-irlink-rcx.h
├── hitechnic-irlink.h
├── hitechnic-irrecv.h
├── hitechnic-irseeker-v2.h
├── hitechnic-magfield.h
├── hitechnic-pir.h
├── hitechnic-protoboard.h
├── hitechnic-sensormux.h
├── hitechnic-superpro.h
├── hitechnic-touchmux.h
├── holitdata-motormux.h
├── humarobotics-wifiblock.h
├── lego-energymeter.h
├── lego-light.h
├── lego-sound.h
├── lego-temp.h
├── lego-touch.h
├── lego-ultrasound.h
├── math-matrix.h
├── microinfinity-cruizcore.h
├── mindensors-servo.h
├── mindsensors-accelerometer.h
├── mindsensors-angle.h
├── mindsensors-ev3-grove.h
├── mindsensors-ev3smux.h
├── mindsensors-hid.h
├── mindsensors-imu.h
├── mindsensors-irdist.h
├── mindsensors-irthermometer.h
├── mindsensors-lightsensorarray.h
├── mindsensors-lineleader.h
├── mindsensors-magicwand.h
├── mindsensors-motormux.h
├── mindsensors-numericpad.h
├── mindsensors-nxtcam.h
├── mindsensors-pfmate.h
├── mindsensors-powermeter.h
├── mindsensors-pressure.h
├── mindsensors-ps2ctrl-v4.h
├── mindsensors-rcxmotormux.h
├── mindsensors-rcxsensorsmux.h
├── mindsensors-sensormux.h
├── mindsensors-sumoeyes.h
├── mindsensors-touchmux.h
├── mindsensors-touchpanel.h
├── philips-pcf8574.h
├── pid.h
├── stats.h
└── timer.h
├── robotc-drivers
├── scripts
├── batch-cleanup.pl
├── migrate-types.sh
└── run-batch-cleanup.sh
└── status_drivers.xlsx
/.gitignore:
--------------------------------------------------------------------------------
1 | ~*
2 |
--------------------------------------------------------------------------------
/README.txt:
--------------------------------------------------------------------------------
1 | /*
2 | * $Id: README.txt $
3 | */
4 |
5 | -= Note =-
6 | These drivers are for RobotC 3.59 beta and higher and are part of the
7 | version 3.3 of the 3rd Party RobotC Drivers suite.
8 |
9 | What's new in 3.3?
10 | * New driver + example for the Dexter Industries dLight
11 | * New driver + examples for the Mindsensors Sensor MUX (includes a disco party)
12 | * New matrix math functions, based on the Arduino Matrix library, worth for both floats and longs
13 | * Fixed silly bug in NXTCam driver. Thanks fxlj007 for reading through the code!
14 | * Complete rewrite of the dWIFI config program and driver, I hope it still works! :)
15 | * Fixed axes in the dIMU driver, I had flipped x and y
16 | * Added a simple strtok() function to common.h
17 | * Minor costmetic tweaks to test programs
18 | * Minor documentation tweaks here and there
19 | * For those who like to peruse code, check out dexterind-imu.h for a glimpse of what's to come
20 | * Fixed naming conflict between Hitechnic EOPD and Mindsensors SumoEyes driver (thanks Bill Fortney)
21 | * Fixed LEGO Light Sensor calibration data saving (thanks Jamie Diamond)
22 | * Minimum version of ROBOTC is now 3.59
23 |
24 | -= API Documentation =-
25 | The complete API documentation can be found in the html folder.
26 | Just point your browser at the index.html file.
27 |
28 | -= Downloads and support =-
29 | These drivers can also be downloaded from:
30 | http://sourceforge.net/projects/rdpartyrobotcdr/
31 |
32 | The documentation is hosted here:
33 | http://botbench.com/driversuite/
34 |
35 | For support questions, please use the RobotC 3rd party sensors forum:
36 | http://www.robotc.net/forums/viewforum.php?f=41
37 |
38 | Thanks,
39 | Xander Soldaat (xander@botbench.com)
40 |
41 | /*
42 | * $Id: README.txt $
43 | */
44 |
--------------------------------------------------------------------------------
/doc/images/LOGO_NXT.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/botbench/robotcdriversuite/e612f3efc1f960e7363fbd3609057ca134fc82b6/doc/images/LOGO_NXT.gif
--------------------------------------------------------------------------------
/doc/images/logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/botbench/robotcdriversuite/e612f3efc1f960e7363fbd3609057ca134fc82b6/doc/images/logo.png
--------------------------------------------------------------------------------
/examples/codatech-rfid-test1.c:
--------------------------------------------------------------------------------
1 | #pragma config(Sensor, S1, CTRFID, sensorI2CCustomFastSkipStates9V)
2 | //*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
3 |
4 | /**
5 | * codatech-rfid.h provides an API for the Codatex RFID sensor. This program
6 | * demonstrates how to use that API to use the sensor in single shotted mode.
7 | *
8 | * Changelog:
9 | * - 0.1: Initial release
10 | * - 0.2: Removed common.h include
11 | *
12 | * Credits:
13 | * - Big thanks to Sylvain Cacheux for writing the initial drivers.
14 | *
15 | * License: You may use this code as you wish, provided you give credit where it's due.
16 | *
17 | * THIS CODE WILL ONLY WORK WITH ROBOTC VERSION 4.10 AND HIGHER
18 |
19 | * Xander Soldaat (xander_at_botbench.com)
20 | * 20 february 2011
21 | * version 0.2
22 | */
23 |
24 | #include "codatech-rfid.h"
25 | string transponderID;
26 |
27 | task main()
28 | {
29 | nNxtButtonTask = -2;
30 | displayCenteredTextLine(0, "Codatex");
31 | displayCenteredBigTextLine(1, "RFID");
32 | displayCenteredTextLine(3, "Test 1");
33 | displayCenteredTextLine(5, "Connect sensor");
34 | displayCenteredTextLine(6, "to S1");
35 | sleep(2000);
36 |
37 | eraseDisplay();
38 | displayCenteredTextLine(3, "Start single");
39 | displayCenteredTextLine(4, "reading loop");
40 | sleep(2000);
41 | eraseDisplay();
42 |
43 | // loop for transponder readings in single read mode
44 | while(nNxtButtonPressed == kNoButton) {
45 | // read the transponder, if no mode (single/continuous) has been
46 | // set, it will default to single shotting the sensor.
47 | if (!CTRFIDreadTransponder(CTRFID, transponderID)) {
48 | eraseDisplay();
49 | displayTextLine(3, "Error reading");
50 | displayTextLine(4, "from sensor!");
51 | sleep(5000);
52 | stopAllTasks();
53 | }
54 | displayCenteredTextLine(3, "Transponder ID:");
55 | displayCenteredTextLine(4, "%s", transponderID);
56 |
57 | // Be sure to add about 200ms after each read
58 | // or you end up getting 0000000000 as a transponder address
59 | sleep(200);
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/examples/codatech-rfid-test2.c:
--------------------------------------------------------------------------------
1 | #pragma config(Sensor, S1, CTRFID, sensorI2CCustom9V)
2 | //*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
3 |
4 | /**
5 | * codatech-rfid.h provides an API for the Codatex RFID sensor. This program
6 | * demonstrates how to use that API to use the sensor in continuous mode.
7 | *
8 | * Changelog:
9 | * - 0.1: Initial release
10 | * - 0.2: Removed common.h include
11 | *
12 | * Credits:
13 | * - Big thanks to Sylvain Cacheux for writing the initial drivers.
14 | *
15 | * License: You may use this code as you wish, provided you give credit where it's due.
16 | *
17 | * THIS CODE WILL ONLY WORK WITH ROBOTC VERSION 4.10 AND HIGHER
18 |
19 | * Xander Soldaat (xander_at_botbench.com)
20 | * 20 february 2011
21 | * version 0.2
22 | */
23 |
24 | #include "codatech-rfid.h"
25 |
26 | string transponderID;
27 |
28 | task main()
29 | {
30 | nNxtButtonTask = -2;
31 | displayCenteredTextLine(0, "Codatex");
32 | displayCenteredBigTextLine(1, "RFID");
33 | displayCenteredTextLine(3, "Test 2");
34 | displayCenteredTextLine(5, "Connect sensor");
35 | displayCenteredTextLine(6, "to S1");
36 | sleep(2000);
37 |
38 | eraseDisplay();
39 | displayCenteredTextLine(3, "Start single");
40 | displayCenteredTextLine(4, "reading loop");
41 | sleep(2000);
42 | eraseDisplay();
43 |
44 | // Set up the sensor for continuous readings.
45 | CTRFIDsetContinuous(CTRFID);
46 |
47 | // loop for transponder readings with continuous read function
48 | while(nNxtButtonPressed == kNoButton) {
49 | // read the transponder
50 | if (!CTRFIDreadTransponder(CTRFID, transponderID)) {
51 | eraseDisplay();
52 | displayTextLine(3, "Error reading");
53 | displayTextLine(4, "from sensor!");
54 | sleep(5000);
55 | stopAllTasks();
56 | }
57 | displayCenteredTextLine(3, "Transponder ID:");
58 | displayCenteredTextLine(4, "%s", transponderID);
59 |
60 | // Be sure to add about 200ms after each read
61 | // or you end up getting 0000000000 as a transponder address
62 | sleep(200);
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/examples/dexterind-compass-test1.c:
--------------------------------------------------------------------------------
1 | /**
2 | * dexterind-compass.h provides an API for the Dexter Industries dCompass Sensor. This program
3 | * demonstrates how to use that API.
4 | *
5 | * Changelog:
6 | * - 0.1: Initial release
7 | *
8 | * Credits:
9 | * - Big thanks to Dexter Industries for providing me with the hardware necessary to write and test this.
10 | *
11 | * License: You may use this code as you wish, provided you give credit where it's due.
12 | *
13 | * THIS CODE WILL ONLY WORK WITH ROBOTC VERSION 4.10 AND HIGHER
14 |
15 | * Xander Soldaat (xander_at_botbench.com)
16 | * 07 August 2011
17 | * version 0.1
18 | */
19 |
20 | #include "dexterind-compass.h"
21 |
22 | task main(){
23 |
24 | // This struct holds all the sensor related data
25 | tDIMC compass;
26 | tSensors DIMC = S1;
27 |
28 | displayCenteredTextLine(0, "Dexter Ind.");
29 | displayCenteredBigTextLine(1, "dCompass");
30 | displayCenteredTextLine(3, "Test 1");
31 | displayCenteredTextLine(5, "Connect sensor");
32 | displayCenteredTextLine(6, "to S1");
33 | sleep(2000);
34 | eraseDisplay();
35 |
36 | // Fire up the compass and initialize it. Only needs to be done once.
37 | if (!initSensor(&compass, DIMC))
38 | playSound(soundException);
39 |
40 | sleep(100);
41 | while (true){
42 |
43 | // Read the Compass
44 | if (!readSensor(&compass))
45 | playSound(soundException);
46 |
47 | displayCenteredBigTextLine(2, "%3.2f", compass.heading);
48 | displayTextLine(5, "%d", compass.axes[0]);
49 | displayTextLine(6, "%d", compass.axes[1]);
50 | displayTextLine(7, "%d", compass.axes[2]);
51 | sleep(50);
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/examples/dexterind-compass-test2.c:
--------------------------------------------------------------------------------
1 | /**
2 | * dexterind-compass.h provides an API for the Dexter Industries dCompass Sensor. This program
3 | * demonstrates how to use that API.
4 | *
5 | * Changelog:
6 | * - 0.1: Initial release
7 | *
8 | * Credits:
9 | * - Big thanks to Dexter Industries for providing me with the hardware necessary to write and test this.
10 | *
11 | * License: You may use this code as you wish, provided you give credit where it's due.
12 | *
13 | * THIS CODE WILL ONLY WORK WITH ROBOTC VERSION 4.10 AND HIGHER
14 |
15 | * Xander Soldaat (xander_at_botbench.com)
16 | * 14 March 2012
17 | * version 0.1
18 | */
19 |
20 | #include "dexterind-compass.h"
21 |
22 | task main(){
23 |
24 | // This struct holds all the sensor related data
25 | tDIMC compass;
26 | tSensors DIMC = S1;
27 |
28 | displayCenteredTextLine(0, "Dexter Ind.");
29 | displayCenteredBigTextLine(1, "dCompass");
30 | displayCenteredTextLine(3, "Test 2");
31 | displayCenteredTextLine(5, "Connect sensor");
32 | displayCenteredTextLine(6, "to S1");
33 | sleep(2000);
34 | eraseDisplay();
35 |
36 | // Fire up the compass and initialize it. Only needs to be done once.
37 | if (!initSensor(&compass, DIMC))
38 | playSound(soundException);
39 |
40 | // This program uses an omniwheel platform to rotate the robot about
41 | // its axis a few times but you can use another robot to do this.
42 | // Just make sure the robot rotates around 2-3 times about is axis
43 | startCal(&compass);
44 |
45 | displayCenteredTextLine(1, "Calibrating...");
46 | displayCenteredTextLine(2, "Turn the sensor");
47 | displayCenteredTextLine(3, "slowly");
48 |
49 | time1[T1] = 0;
50 | while(time1[T1] < 15000)
51 | {
52 | // Read the Compass
53 | if (!readSensor(&compass))
54 | playSound(soundException);
55 |
56 | if (time1[T1] % 1000 < 10)
57 | displayCenteredBigTextLine(5, "%d", 15 - (time1[T1]/1000));
58 |
59 | }
60 |
61 | // Stop the calibration and store the data
62 | stopCal(&compass);
63 |
64 | eraseDisplay();
65 | sleep(100);
66 | while (true){
67 |
68 | // Read the Compass
69 | if (!readSensor(&compass))
70 | playSound(soundException);
71 |
72 | displayCenteredBigTextLine(1, "Heading");
73 | displayCenteredBigTextLine(3, "%3.2f", compass.heading);
74 | displayTextLine(5, "%d", compass.axes[0]);
75 | displayTextLine(6, "%d", compass.axes[1]);
76 | displayTextLine(7, "%d", compass.axes[2]);
77 | sleep(50);
78 | }
79 | }
80 |
--------------------------------------------------------------------------------
/examples/dexterind-compass-test3.c:
--------------------------------------------------------------------------------
1 | /**
2 | * dexterind-compass.h provides an API for the Dexter Industries dCompass Sensor. This program
3 | * demonstrates how to use that API.
4 | *
5 | * Changelog:
6 | * - 0.1: Initial release
7 | *
8 | * Credits:
9 | * - Big thanks to Dexter Industries for providing me with the hardware necessary to write and test this.
10 | *
11 | * License: You may use this code as you wish, provided you give credit where it's due.
12 | *
13 | * THIS CODE WILL ONLY WORK WITH ROBOTC VERSION 4.10 AND HIGHER
14 |
15 | * Xander Soldaat (xander_at_botbench.com)
16 | * 05 April 2012
17 | * version 0.1
18 | */
19 |
20 | #include "dexterind-compass.h"
21 |
22 | task main ()
23 | {
24 | // This struct holds all the sensor related data
25 | tDIMC compass;
26 | tSensors DIMC = S1;
27 |
28 | // Our local variables
29 | short strength = 0;
30 |
31 | // Fire up the compass and initialize it. Only needs to be done once.
32 | if (!initSensor(&compass, DIMC))
33 | playSound(soundException);
34 |
35 | // Loop forever, reading the sensor and calulating total
36 | // field strength
37 | while (true)
38 | {
39 | // Read the Compass
40 | if (!readSensor(&compass))
41 | playSound(soundException);
42 |
43 | // calculate the field strength
44 | strength = sqrt(pow(compass.axes[0], 2) + pow(compass.axes[1], 2) + pow(compass.axes[2], 2));
45 |
46 | // Play a tone of the frequency of the field strength
47 | // Great for annoying the cat/dog/wife/parent
48 | playImmediateTone(strength, 8);
49 |
50 | // display on the screen
51 | displayCenteredBigTextLine(3, "%d", strength);
52 | sleep(50);
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/examples/dexterind-flex-test1.c:
--------------------------------------------------------------------------------
1 | #pragma config(Sensor, S1, DFLEX, sensorLightInactive)
2 | //*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
3 |
4 | /**
5 | * dexterind-flex.h provides an API for the Dexter Industries dFlex Sensor. This program
6 | * demonstrates how to use that API to calibrate the sensor.
7 | *
8 | * Changelog:
9 | * - 0.1: Initial release
10 | *
11 | * Credits:
12 | * - Big thanks to Dexter Industries for providing me with the hardware necessary to write and test this.
13 | *
14 | * License: You may use this code as you wish, provided you give credit where it's due.
15 | *
16 | * THIS CODE WILL ONLY WORK WITH ROBOTC VERSION 4.10 AND HIGHER
17 |
18 | * Xander Soldaat (xander_at_botbench.com)
19 | * 23 June 2010
20 | * version 0.1
21 | */
22 |
23 | #include "dexterind-flex.h"
24 |
25 | task main() {
26 | short raw = 0;
27 | short nrm = 0;
28 |
29 | nNxtButtonTask = -2;
30 |
31 | eraseDisplay();
32 | displayTextLine(0, "Dexter Industries");
33 | displayCenteredBigTextLine(1, "dFlex");
34 | displayCenteredTextLine(3, "Test 1");
35 | displayCenteredTextLine(5, "Connect sensor");
36 | displayCenteredTextLine(6, "to S1");
37 | sleep(2000);
38 |
39 | eraseDisplay();
40 | displayTextLine(0, "dFlex Sensor");
41 |
42 | while (true) {
43 | displayClearTextLine(5);
44 | displayClearTextLine(6);
45 |
46 | // Get the raw value from the sensor
47 | raw = DFLEXvalRaw(DFLEX);
48 |
49 | // Get the normalised value from the sensor
50 | nrm = DFLEXvalNorm(DFLEX);
51 |
52 | displayTextLine(2, "Raw: %4d", raw);
53 | displayTextLine(4, "Norm: %4d", nrm);
54 | sleep(50);
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/examples/dexterind-flex-test2.c:
--------------------------------------------------------------------------------
1 | #pragma config(Sensor, S1, DFLEX, sensorAnalogInactive)
2 | //*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
3 |
4 | /**
5 | * dexterind-flex.h provides an API for the Dexter Industries dFlex Sensor. This program
6 | * demonstrates how to use that API to calibrate the sensor.
7 | *
8 | * Changelog:
9 | * - 0.1: Initial release
10 | *
11 | * Credits:
12 | * - Big thanks to Dexter Industries for providing me with the hardware necessary to write and test this.
13 | *
14 | * License: You may use this code as you wish, provided you give credit where it's due.
15 | *
16 | * THIS CODE WILL ONLY WORK WITH ROBOTC VERSION 4.10 AND HIGHER
17 |
18 | * Xander Soldaat (xander_at_botbench.com)
19 | * 23 June 2010
20 | * version 0.1
21 | */
22 |
23 | #include "dexterind-flex.h"
24 |
25 | task main () {
26 | short raw = 0;
27 | short nrm = 0;
28 | // Get control over the buttons
29 | nNxtButtonTask = -2;
30 |
31 | eraseDisplay();
32 | displayTextLine(0, "Dexter Industries");
33 | displayCenteredBigTextLine(1, "dFlex");
34 | displayCenteredTextLine(3, "Test 2");
35 | displayCenteredTextLine(5, "Connect sensor");
36 | displayCenteredTextLine(6, "to S1");
37 | sleep(2000);
38 |
39 | eraseDisplay();
40 | displayTextLine(0, "dFlex Calibration");
41 | displayTextLine(2, "Left: set min");
42 | displayTextLine(3, "Right: set max");
43 | displayTextLine(7, "Grey: exit");
44 |
45 | while (true) {
46 | switch(nNxtButtonPressed) {
47 | // if the left button is pressed calibrate the black value for the sensor
48 | case kLeftButton:
49 | DFLEXcalLow(DFLEX);
50 | playSound(soundBeepBeep);
51 | while(bSoundActive) sleep(1);
52 | break;
53 |
54 | // if the left button is pressed calibrate the white value for the sensor
55 | case kRightButton:
56 | DFLEXcalHigh(DFLEX);
57 | playSound(soundBeepBeep);
58 | while(bSoundActive) sleep(1);
59 | break;
60 | }
61 |
62 | displayClearTextLine(5);
63 | displayClearTextLine(6);
64 |
65 | // Read the raw value of the sensor
66 | raw = DFLEXvalRaw(DFLEX);
67 |
68 | // Read the normalised value of the sensor
69 | nrm = DFLEXvalNorm(DFLEX);
70 |
71 | // Display the raw and normalised values
72 | displayTextLine(5, "R: %4d N: %4d", raw, nrm);
73 |
74 | // Display the values for black and white
75 | displayTextLine(6, "B: %4d W: %4d", dflexlow, dflexhigh);
76 | sleep(50);
77 | }
78 | }
79 |
--------------------------------------------------------------------------------
/examples/dexterind-gps-test1.c:
--------------------------------------------------------------------------------
1 | #pragma config(Sensor, S1, DGPS, sensorI2CCustom)
2 | //*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
3 |
4 | /**
5 | * dexterind-gps.h provides an API for the Dexter Industries GPS Sensor. This program
6 | * demonstrates how to use that API.
7 | *
8 | * Changelog:
9 | * - 0.1: Initial release
10 | * - 0.2: Removed common.h from includes
11 | *
12 | * Credits:
13 | * - Big thanks to Dexter Industries for providing me with the hardware necessary to write and test this.
14 | *
15 | * License: You may use this code as you wish, provided you give credit where it's due.
16 | *
17 | * THIS CODE WILL ONLY WORK WITH ROBOTC VERSION 4.10 AND HIGHER
18 |
19 | * Xander Soldaat (xander_at_botbench.com)
20 | * 20 February 2011
21 | * version 0.2
22 | */
23 |
24 | #include "dexterind-gps.h"
25 |
26 | task main () {
27 |
28 | long longitude = 0;
29 | long latitude = 0;
30 | long utc = 0;
31 | bool linkstatus = false;
32 |
33 | displayCenteredTextLine(0, "Dexter Ind.");
34 | displayCenteredBigTextLine(1, "GPS");
35 | displayCenteredTextLine(3, "Test 1");
36 | displayCenteredTextLine(5, "Connect sensor");
37 | displayCenteredTextLine(6, "to S1");
38 | sleep(2000);
39 | eraseDisplay();
40 |
41 | while (true) {
42 | // Read the sensor's data
43 | utc = DGPSreadUTC(DGPS);
44 | longitude = DGPSreadLongitude(DGPS);
45 | latitude = DGPSreadLatitude(DGPS);
46 | linkstatus = DGPSreadStatus(DGPS);
47 |
48 | displayCenteredTextLine(0, "DGPS Test 1");
49 | drawLine(0, 52, 99, 52);
50 | displayTextLine(2, "UTC: %d", utc);
51 | displayTextLine(3, "Lon: %d", longitude);
52 | displayTextLine(4, "Lat: %d", latitude);
53 | if (linkstatus)
54 | displayTextLine(7, "Link Stat: [UP]");
55 | else
56 | displayTextLine(7, "Link Stat: [DOWN]");
57 | drawLine(0, 20, 99, 20);
58 | sleep(500);
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/examples/dexterind-imu-test2.c:
--------------------------------------------------------------------------------
1 | #pragma config(Sensor, S1, DIMU, sensorI2CCustom)
2 | //*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
3 |
4 | /**
5 | * dexterind-imu.h provides an API for the Dexter Industries IMU Sensor. This program
6 | * demonstrates how to use that API.
7 | *
8 | * Changelog:
9 | * - 0.1: Initial release
10 | *
11 | * Credits:
12 | * - Big thanks to Dexter Industries for providing me with the hardware necessary to write and test this.
13 | *
14 | * License: You may use this code as you wish, provided you give credit where it's due.
15 | *
16 | * THIS CODE WILL ONLY WORK WITH ROBOTC VERSION 4.10 AND HIGHER
17 |
18 | * Xander Soldaat (xander_at_botbench.com)
19 | * 07 August 2011
20 | * version 0.1
21 | */
22 |
23 | #include "dexterind-imu.h"
24 |
25 | float xvals[500];
26 | float yvals[500];
27 | float zvals[500];
28 |
29 | task main(){
30 |
31 | displayCenteredTextLine(0, "Dexter Ind.");
32 | displayCenteredBigTextLine(1, "IMU");
33 | displayCenteredTextLine(3, "Test 2");
34 | displayCenteredTextLine(5, "Connect sensor");
35 | displayCenteredTextLine(6, "to S1");
36 | sleep(2000);
37 | eraseDisplay();
38 |
39 | // Fire up the gyro and initialize it. Only needs to be done once.
40 | if(!DIMUconfigGyro(DIMU, DIMU_GYRO_RANGE_250, true))
41 | playSound(soundException);
42 |
43 | for (short i = 0; i < 500; i++){
44 |
45 | // Read the GYROSCOPE
46 | // There are 3 ways to do this:
47 |
48 | // All at once, very convenient if you need all 3
49 | DIMUreadGyroAxes(DIMU, xvals[i], yvals[i], zvals[i]);
50 | sleep(5);
51 | }
52 |
53 | for (short i = 0; i< 500; i++) {
54 | writeDebugStreamLine("%4.4f, %4.4f, %4.4f", xvals[i], yvals[i], zvals[i]);
55 | sleep(2);
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/examples/dexterind-nxtchuck-test1.c:
--------------------------------------------------------------------------------
1 | #pragma config(Sensor, S1, CHUCKNORRIS, sensorI2CCustom)
2 | //*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
3 |
4 | /**
5 | * dexterind-nxtchuck.h provides an API for the Dexter Industries NXTChuck sensor.
6 | * This program demonstrates how to use that API.
7 | *
8 | * Changelog:
9 | * - 0.1: Initial release
10 | *
11 | * Credits:
12 | * - Big thanks to Matthew Richardson and Dexter Industries for providing me with the
13 | * hardware necessary to write and test this.
14 | *
15 | * License: You may use this code as you wish, provided you give credit where it's due.
16 | *
17 | * THIS CODE WILL ONLY WORK WITH ROBOTC VERSION 4.10 AND HIGHER
18 |
19 | * Xander Soldaat (xander_at_botbench.com)
20 | * 31 October 2012
21 | * version 0.1
22 | */
23 |
24 | #include "dexterind-nxtchuck.h"
25 |
26 | task main()
27 | {
28 |
29 | tNunchuck chucky;
30 |
31 | byte Device = 0;
32 | NXTChuckreadIdent(CHUCKNORRIS, chucky);
33 | writeDebugStreamLine("dev: %d", Device);
34 |
35 | while (true)
36 | {
37 | //if(Device == NXTCHUCK_DEVICE_NUNCHUK){ // If it identified the extension as a Nunchuk
38 | if (NXTChuckreadSensor(S1, chucky)) { // Read the Nunchuk
39 |
40 | displayTextLine(0, "Stick X %d", chucky.stickX);
41 | displayTextLine(1, "Stick Y %d", chucky.stickY);
42 | displayTextLine(2, "Accel X %d", chucky.accelX);
43 | displayTextLine(3, "Accel Y %d", chucky.accelY);
44 | displayTextLine(4, "Accel Z %d", chucky.accelZ);
45 | displayTextLine(5, "Button C %d", chucky.buttonC);
46 | displayTextLine(6, "Button Z %d", chucky.buttonZ);
47 | displayTextLine(7, "Buttons %d", chucky.buttons);
48 | }
49 | else {
50 | sleep(100);
51 | eraseDisplay();
52 | displayTextLine(0, "Failed");
53 | }
54 | //}
55 | sleep(10);
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/examples/dexterind-pressure-test1.c:
--------------------------------------------------------------------------------
1 | #pragma config(Sensor, S1, DPRESS, sensorAnalogInactive)
2 | //*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
3 |
4 | /**
5 | * dexterind-pressure.h provides an API for the Dexter Industries dPressure sensor. This program
6 | * demonstrates how to use that API.
7 | *
8 | * Changelog:
9 | * - 0.1: Initial release
10 | *
11 | * Credits:
12 | * - Big thanks to Dexter Industries for providing me with the hardware necessary to write and test this.
13 | *
14 | * License: You may use this code as you wish, provided you give credit where it's due.
15 | *
16 | * THIS CODE WILL ONLY WORK WITH ROBOTC VERSION 4.10 AND HIGHER
17 |
18 | * Xander Soldaat (xander_at_botbench.com)
19 | * 13 June 2010
20 | * version 0.1
21 | */
22 |
23 | #include "dexterind-pressure.h"
24 |
25 | task main() {
26 | float pressure;
27 | byte state = 0;
28 |
29 | displayTextLine(0, "Dexter Industries");
30 | displayCenteredTextLine(1, "dPressure 250");
31 | displayCenteredTextLine(3, "Test 1");
32 | displayCenteredTextLine(5, "Connect sensor");
33 | displayCenteredTextLine(6, "to S1");
34 | sleep(2000);
35 | eraseDisplay();
36 |
37 | displayTextLine(0, "Dexter Industries");
38 | displayCenteredTextLine(7, "< switch scale >");
39 | //loop to read temp
40 | while (true) {
41 | switch(nNxtButtonPressed) {
42 | // If the right button is pressed, cycle through the scales
43 | case kRightButton:
44 | if (++state > 1)
45 | state = 0;
46 | while (nNxtButtonPressed != kNoButton) sleep(1);
47 | break;
48 |
49 | // If the left button is pressed, cycle through the scales in reverse
50 | case kLeftButton:
51 | if (--state < 0)
52 | state = 1;
53 | // debounce the button
54 | while (nNxtButtonPressed != kNoButton) sleep(1);
55 | break;
56 | }
57 |
58 | displayCenteredBigTextLine(1, "Pressure:");
59 | switch(state) {
60 | // if state: 0, display temp in degrees celcius
61 | case 0: DPRESSreadPress250kPa(DPRESS, pressure);
62 | displayCenteredBigTextLine(3, "%4.2f", pressure);
63 | displayCenteredBigTextLine(5, "kPa");
64 | break;
65 |
66 | // if state: 1, display temp in Fahrenheit
67 | case 1: DPRESSreadPress250PSI(DPRESS, pressure);
68 | displayCenteredBigTextLine(3, "%4.2f", pressure);
69 | displayCenteredBigTextLine(5, "PSI.");
70 | break;
71 | }
72 | sleep(10);
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/examples/dexterind-temp-test1.c:
--------------------------------------------------------------------------------
1 | #pragma config(Sensor, S1, DTMP, sensorAnalogInactive)
2 | //*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
3 |
4 | /**
5 | * dexterind-temp.h provides an API for the Dexter Industries Temperature Probe. This program
6 | * demonstrates how to use that API.
7 | *
8 | * Changelog:
9 | * - 0.1: Initial release
10 | *
11 | * Credits:
12 | * - Big thanks to Dexter Industries for providing me with the hardware necessary to write and test this.
13 | *
14 | * License: You may use this code as you wish, provided you give credit where it's due.
15 | *
16 | * THIS CODE WILL ONLY WORK WITH ROBOTC VERSION 4.10 AND HIGHER
17 |
18 | * Xander Soldaat (xander_at_botbench.com)
19 | * 13 June 2010
20 | * version 0.1
21 | */
22 |
23 | #include "dexterind-temp.h"
24 |
25 | task main() {
26 | float temp;
27 | byte state = 0;
28 |
29 | displayTextLine(0, "Dexter Industries");
30 | displayCenteredBigTextLine(1, "T Probe");
31 | displayCenteredTextLine(3, "Test 1");
32 | displayCenteredTextLine(5, "Connect sensor");
33 | displayCenteredTextLine(6, "to S1");
34 | sleep(2000);
35 | eraseDisplay();
36 |
37 | displayTextLine(0, "Dexter Industries");
38 | displayCenteredTextLine(7, "< switch scale >");
39 | //loop to read temp
40 | while (true) {
41 | switch(nNxtButtonPressed) {
42 | // If the right button is pressed, cycle through the scales
43 | case kRightButton:
44 | if (++state > 2)
45 | state = 0;
46 | while (nNxtButtonPressed != kNoButton) sleep(1);
47 | break;
48 |
49 | // If the left button is pressed, cycle through the scales in reverse
50 | case kLeftButton:
51 | if (--state < 0)
52 | state = 2;
53 | // debounce the button
54 | while (nNxtButtonPressed != kNoButton) sleep(1);
55 | break;
56 | }
57 |
58 | displayCenteredBigTextLine(1, "Temp:");
59 | switch(state) {
60 | // if state: 0, display temp in degrees celcius
61 | case 0: DTMPreadTemp(DTMP, temp);
62 | displayCenteredBigTextLine(3, "%4.2f", temp);
63 | displayCenteredBigTextLine(5, "Celcius");
64 | break;
65 |
66 | // if state: 1, display temp in Fahrenheit
67 | case 1: DTMPreadTempF(DTMP, temp);
68 | displayCenteredBigTextLine(3, "%4.2f", temp);
69 | displayCenteredBigTextLine(5, "Fahrenh.");
70 | break;
71 |
72 | // if state: 2, display temp in Kelvin
73 | case 2: DTMPreadTempK(DTMP, temp);
74 | displayCenteredBigTextLine(3, "%4.2f", temp);
75 | displayCenteredBigTextLine(5, "Kelvin");
76 | break;
77 | }
78 | sleep(10);
79 | }
80 | }
81 |
--------------------------------------------------------------------------------
/examples/dexterind-thermalir-test1.c:
--------------------------------------------------------------------------------
1 | #pragma config(Sensor, S1, TIR, sensorI2CCustomFastSkipStates)
2 | //*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
3 |
4 | /**
5 | * dexterind-thermalir.h provides an API for the Dexter Industries Thermal Infrared Sensor. This program
6 | * demonstrates how to use that API.
7 | *
8 | * Changelog:
9 | * - 0.1: Initial release
10 | *
11 | * Credits:
12 | * - Big thanks to Dexter Industries for providing me with the hardware necessary to write and test this.
13 | *
14 | * License: You may use this code as you wish, provided you give credit where it's due.
15 | *
16 | * THIS CODE WILL ONLY WORK WITH ROBOTC VERSION 4.10 AND HIGHER
17 |
18 | * Xander Soldaat (xander_at_botbench.com)
19 | * 30 march 2013
20 | * version 0.1
21 | */
22 |
23 | #include "dexterind-thermalir.h"
24 |
25 | task main () {
26 |
27 | // declare and initialise the sensor
28 | tTIR tir;
29 | initSensor(&tir, S1);
30 |
31 | displayCenteredTextLine(0, "Dexter Industries");
32 | displayCenteredTextLine(1, "Thermal Infrared");
33 | displayCenteredTextLine(3, "Test 1");
34 | displayCenteredTextLine(5, "Connect sensor");
35 | displayCenteredTextLine(6, "to S1");
36 | sleep(2000);
37 |
38 | eraseDisplay();
39 |
40 | // set emissivity for light skin
41 | setEmissivity(&tir, TIR_EM_SKIN_LIGHT);
42 |
43 | sleep(200);
44 |
45 | displayCenteredTextLine(0, "Dexter Industries");
46 | displayCenteredTextLine(1, "Thermal Infrared");
47 | while (true) {
48 | // Read the currently detected ambient and object temp from the sensor
49 | readSensor(&tir);
50 |
51 | displayTextLine(3, "A: %3.2f", tir.ambientTemp);
52 | displayTextLine(4, "O: %3.2f", tir.objectTemp);
53 | sleep(100);
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/examples/dexterind-wifi-config.c:
--------------------------------------------------------------------------------
1 | #pragma config(Sensor, S1, COLOUR, sensorColorNxtNONE)
2 | #pragma config(Sensor, S3, DTMP, sensorAnalogInactive)
3 | #pragma config(Motor, motorA, M1, tmotorNormal, openLoop, encoder)
4 | //*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
5 | #define __RS485_DEBUG__ 1
6 |
7 | #include "common.h"
8 | #include "dexterind-wifi.h"
9 |
10 | void configureWiFi(char *_ssid, char *_key)
11 | {
12 | short len;
13 | RS485clearRead(); // Clear out the buffer and test TX/RX.
14 | sleep(1000); // Must be run first!
15 | DWIFIsetEcho(false); // Must be run first!
16 | sleep(1000); // Must be run first!
17 | RS485clearRead();
18 | eraseDisplay();
19 | DWIFIsetSWControl(); // Must be run first!
20 | RS485clearRead();
21 | DWIFIsetVerbose(false);
22 | sleep(100);
23 | RS485clearRead();
24 | RS485read(RS485rxbuffer, len);
25 | DWIFIsetSSID(_ssid);
26 | DWIFIsetDHCP(true);
27 | DWIFIsetWPAPSK(_ssid, _key);
28 | sleep(20000);
29 | DWIFIsaveConfig();
30 | }
31 |
32 | task main()
33 | {
34 | char *ssid = "YOURSSID";
35 | char *wpa_psk = "YOURPASSWORD";
36 |
37 | writeDebugStreamLine("ssid: %s", ssid);
38 | writeDebugStreamLine("psk: %s", wpa_psk);
39 | short len;
40 | eraseDisplay();
41 | bNxtLCDStatusDisplay = true; // Enable top status line display
42 | writeDebugStream("Scanning for wifi sensor: ");
43 |
44 | // You can play with these to see if they work for you.
45 | // I tend to use the 460800 rate as it's the fastest speed
46 | // that I can use reliably.
47 | //DWIFIsetBAUDRate(9600);
48 | DWIFIsetBAUDRate(230400);
49 | DWIFIresetConfig();
50 | playSound(soundBlip);
51 | while(nNxtButtonPressed != kEnterButton) sleep(1);
52 | DWIFIsetBAUDRate(230400);
53 |
54 | configureWiFi((char *)ssid, (char *)wpa_psk);
55 | // set_verbose(false);
56 | // Receive();
57 | sleep(100);
58 | while(true)
59 | {
60 | RS485read(RS485rxbuffer, len, 100);
61 | }
62 | playSound(soundBeepBeep);
63 | }
64 |
--------------------------------------------------------------------------------
/examples/firgelli-linearact-test1.c:
--------------------------------------------------------------------------------
1 |
2 |
3 | /**
4 | * firgelli-linearact.h provides an API for the Firgelli Linear Actuator. This program
5 | * demonstrates how to use that API.
6 | *
7 | * Changelog:
8 | * - 0.1: Initial release
9 | *
10 | * TODO:
11 | * - Add ramping support (being worked on, has a few bugs)
12 | *
13 | * Credits:
14 | * - Big thanks to Firgelli for providing me with a Linear Actuator to play with!
15 | *
16 | * License: You may use this code as you wish, provided you give credit where it's due.
17 | *
18 | * THIS CODE WILL ONLY WORK WITH ROBOTC VERSION 4.10 AND HIGHER
19 |
20 | * Xander Soldaat (xander_at_botbench.com)
21 | * 15 february 2010
22 | * version 0.1
23 | */
24 |
25 | #include "firgelli-linearact.h"
26 |
27 | task main () {
28 | tMotor testMotor = motorA;
29 |
30 | playSound(soundBeepBeep);
31 | displayBigTextLine(3, "Retract");
32 | FLACretractLA(testMotor, 100);
33 | while(!isDone(testMotor)) sleep(50);
34 | sleep(200);
35 | nMotorEncoder[testMotor] = 0;
36 | sleep(1000);
37 |
38 | playSound(soundBeepBeep);
39 | eraseDisplay();
40 | displayBigTextLine(1, "Extend");
41 | displayTextLine(3, "ticks: 40");
42 | displayTextLine(4, "speed: 50");
43 | FLACextendLA(testMotor, 50, 40);
44 | while(!isDone(testMotor)) sleep(50);
45 | if (isStalled(testMotor))
46 | displayTextLine(7, "STALLED");
47 | sleep(1000);
48 |
49 | playSound(soundBeepBeep);
50 | eraseDisplay();
51 | displayBigTextLine(1, "Extend");
52 | displayTextLine(3, "ticks: 100");
53 | displayTextLine(4, "speed: 80");
54 | FLACextendLA(testMotor, 80, 100);
55 | while(!isDone(testMotor)) sleep(50);
56 | if (isStalled(testMotor))
57 | displayTextLine(7, "STALLED");
58 | sleep(1000);
59 | eraseDisplay();
60 |
61 | playSound(soundBeepBeep);
62 | displayBigTextLine(1, "Retract");
63 | displayTextLine(3, "ticks: 120");
64 | displayTextLine(4, "speed: 100");
65 | FLACtretractLA(testMotor, 100, 120);
66 | while(!isDone(testMotor)) sleep(50);
67 | if (isStalled(testMotor))
68 | displayTextLine(7, "STALLED");
69 | sleep(1000);
70 |
71 | playSound(soundBeepBeep);
72 | displayBigTextLine(1, "Retract");
73 | displayTextLine(3, "ticks: 20");
74 | displayTextLine(4, "speed: 100");
75 | FLACtretractLA(testMotor, 100, 20);
76 | while(!isDone(testMotor)) sleep(50);
77 | if (isStalled(testMotor))
78 | displayTextLine(7, "STALLED");
79 | sleep(1000);
80 |
81 | playSound(soundBeepBeep);
82 | eraseDisplay();
83 | displayBigTextLine(1, "Done");
84 | sleep(2000);
85 | }
86 |
--------------------------------------------------------------------------------
/examples/firgelli-linearact-test2.c:
--------------------------------------------------------------------------------
1 |
2 |
3 | /**
4 | * firgelli-linearact.h provides an API for the Firgelli Linear Actuator. This program
5 | * demonstrates how to use that API.
6 | *
7 | * Changelog:
8 | * - 0.1: Initial release
9 | *
10 | * TODO:
11 | * - Add ramping support (being worked on, has a few bugs)
12 | *
13 | * Credits:
14 | * - Big thanks to Firgelli for providing me with a Linear Actuator to play with!
15 | *
16 | * License: You may use this code as you wish, provided you give credit where it's due.
17 | *
18 | * THIS CODE WILL ONLY WORK WITH ROBOTC VERSION 4.10 AND HIGHER
19 |
20 | * Xander Soldaat (xander_at_botbench.com)
21 | * 15 february 2010
22 | * version 0.1
23 | */
24 |
25 | #include "firgelli-linearact.h"
26 |
27 | task main () {
28 | tMotor testMotor = motorC;
29 |
30 | // playSound(soundBeepBeep);
31 | // displayBigTextLine(3, "Retract");
32 | // FLACtretractLA(testMotor, 100);
33 | // while(!isDone(testMotor)) sleep(50);
34 | // sleep(200);
35 | // nMotorEncoder[testMotor] = 0;
36 | // sleep(1000);
37 |
38 | playSound(soundBeepBeep);
39 | eraseDisplay();
40 | displayBigTextLine(1, "Extend");
41 | displayTextLine(3, "ticks: 1");
42 | displayTextLine(4, "speed: 50");
43 | FLACextendLA(testMotor, 50, 1);
44 | while(!isDone(testMotor)) sleep(50);
45 | if (isStalled(testMotor))
46 | displayTextLine(7, "STALLED");
47 | sleep(1000);
48 |
49 | // playSound(soundBeepBeep);
50 | // eraseDisplay();
51 | // displayBigTextLine(1, "Extend");
52 | // displayTextLine(3, "ticks: 100");
53 | // displayTextLine(4, "speed: 80");
54 | // FLACextendLA(testMotor, 80, 100);
55 | // while(!isDone(testMotor)) sleep(50);
56 | // if (isStalled(testMotor))
57 | // displayTextLine(7, "STALLED");
58 | // sleep(1000);
59 | // eraseDisplay();
60 |
61 | // playSound(soundBeepBeep);
62 | // displayBigTextLine(1, "Retract");
63 | // displayTextLine(3, "ticks: 120");
64 | // displayTextLine(4, "speed: 100");
65 | // FLACtretractLA(testMotor, 100, 120);
66 | // while(!isDone(testMotor)) sleep(50);
67 | // if (isStalled(testMotor))
68 | // displayTextLine(7, "STALLED");
69 | // sleep(1000);
70 |
71 | playSound(soundBeepBeep);
72 | displayBigTextLine(1, "Retract");
73 | displayTextLine(3, "ticks: 1");
74 | displayTextLine(4, "speed: 100");
75 | FLACtretractLA(testMotor, 100, 1);
76 | while(!isDone(testMotor)) sleep(50);
77 | if (isStalled(testMotor))
78 | displayTextLine(7, "STALLED");
79 | sleep(1000);
80 |
81 | playSound(soundBeepBeep);
82 | eraseDisplay();
83 | displayBigTextLine(1, "Done");
84 | sleep(2000);
85 | }
86 |
--------------------------------------------------------------------------------
/examples/firgelli-linearact-test3.c:
--------------------------------------------------------------------------------
1 |
2 |
3 | /**
4 | * firgelli-linearact.h provides an API for the Firgelli Linear Actuator. This program
5 | * demonstrates how to use that API.
6 | *
7 | * Changelog:
8 | * - 0.1: Initial release
9 | *
10 | * TODO:
11 | * - Add ramping support (being worked on, has a few bugs)
12 | *
13 | * Credits:
14 | * - Big thanks to Firgelli for providing me with a Linear Actuator to play with!
15 | *
16 | * License: You may use this code as you wish, provided you give credit where it's due.
17 | *
18 | * THIS CODE WILL ONLY WORK WITH ROBOTC VERSION 4.10 AND HIGHER
19 |
20 | * Xander Soldaat (xander_at_botbench.com)
21 | * 15 february 2010
22 | * version 0.1
23 | */
24 |
25 | #include "firgelli-linearact.h"
26 |
27 | task main () {
28 | tMotor testMotor = motorA;
29 |
30 | playSound(soundBeepBeep);
31 | displayBigTextLine(3, "Retract");
32 | FLACretractLA(testMotor, 100);
33 | sleep(500);
34 |
35 | // This stops the motor, handy in case of emergencies
36 | FLACstopLA(motorA);
37 | while(!isDone(testMotor)) sleep(50);
38 | sleep(200);
39 | nMotorEncoder[testMotor] = 0;
40 | sleep(1000);
41 |
42 | playSound(soundBeepBeep);
43 | eraseDisplay();
44 | displayBigTextLine(1, "Extend");
45 | displayTextLine(3, "ticks: 40");
46 | displayTextLine(4, "speed: 50");
47 | FLACextendLA(testMotor, 50, 40);
48 | while(!isDone(testMotor)) sleep(50);
49 | if (isStalled(testMotor))
50 | displayTextLine(7, "STALLED");
51 | sleep(1000);
52 |
53 | playSound(soundBeepBeep);
54 | eraseDisplay();
55 | displayBigTextLine(1, "Done");
56 | sleep(2000);
57 | }
58 |
--------------------------------------------------------------------------------
/examples/hitechnic-accelerometer-SMUX-test1.c:
--------------------------------------------------------------------------------
1 | #pragma config(Sensor, S1, HTSMUX, sensorI2CCustom)
2 | //*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
3 |
4 | /**
5 | * hitechnic-accelerometer.h provides an API for the HiTechnic Acceleration Sensor. This program
6 | * demonstrates how to use that API.
7 | *
8 | * Changelog:
9 | * - 0.1: Initial release
10 | * - 0.2: Make use of new API calls
11 | * - 0.3: Better comments
12 | * - 0.4: Fixed line number in display functionality
13 | * - 0.5: Now uses HTSMUX driver which has been split from common.h\n
14 | * HTSMUX initialisation and scanning functions have been removed\n
15 | * Removed single axis functions, they're no longer in the driver
16 | *
17 | * Credits:
18 | * - Big thanks to HiTechnic for providing me with the hardware necessary to write and test this.
19 | * - Chris Shepherd for pointing a silly bug in the display functionality
20 | *
21 | * License: You may use this code as you wish, provided you give credit where it's due.
22 | *
23 | * THIS CODE WILL ONLY WORK WITH ROBOTC VERSION 4.10 AND HIGHER
24 |
25 | * Xander Soldaat (xander_at_botbench.com)
26 | * 20 February 2011
27 | * version 0.5
28 | */
29 |
30 | #include "hitechnic-accelerometer.h"
31 |
32 | task main () {
33 | displayCenteredTextLine(0, "HiTechnic");
34 | displayCenteredBigTextLine(1, "Accel");
35 | displayCenteredTextLine(3, "Test 1");
36 | displayCenteredTextLine(5, "Connect sensor");
37 | displayCenteredTextLine(6, "to S1");
38 | sleep(2000);
39 |
40 | playSound(soundBeepBeep);
41 | while(bSoundActive) sleep(1);
42 |
43 | // Create struct to hold sensor data
44 | tHTAC accelerometer;
45 |
46 | // The sensor is connected to the first port
47 | // of the SMUX which is connected to the NXT port S1.
48 | // To access that sensor, we must use msensor_S1_1. If the sensor
49 | // were connected to 3rd port of the SMUX connected to the NXT port S4,
50 | // we would use msensor_S4_3
51 |
52 | // Initialise and configure struct and port
53 | initSensor(&accelerometer, msensor_S1_1);
54 |
55 | while (true) {
56 | eraseDisplay();
57 |
58 | // Read all of the axes at once
59 | if (!readSensor(&accelerometer)) {
60 | displayTextLine(4, "ERROR!!");
61 | sleep(2000);
62 | stopAllTasks();
63 | }
64 |
65 | displayTextLine(0,"HTAC Test 1");
66 | displayTextLine(2, " X Y Z");
67 |
68 | displayTextLine(3, "%4d %4d %4d", accelerometer.x, accelerometer.y, accelerometer.z);
69 | // Alternatively, you can read them like this:
70 | displayTextLine(4, "%4d %4d %4d", accelerometer.axes[0], accelerometer.axes[1], accelerometer.axes[2]);
71 | sleep(100);
72 | }
73 | }
74 |
--------------------------------------------------------------------------------
/examples/hitechnic-accelerometer-test1.c:
--------------------------------------------------------------------------------
1 | #pragma config(Sensor, S1, HTAC, sensorI2CCustom)
2 | //*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
3 |
4 | /**
5 | * hitechnic-accelerometer.h provides an API for the HiTechnic Acceleration Sensor. This program
6 | * demonstrates how to use that API.
7 | *
8 | * Changelog:
9 | * - 0.1: Initial release
10 | * - 0.2: Make use of new API calls
11 | * - 0.3: Better comments
12 | * - 0.4: Fixed display line (thanks Dave)
13 | * - 0.5: Removed single axis functions, they're no longer in the driver\n
14 | * Removed common.h from includes
15 | *
16 | * Credits:
17 | * - Big thanks to HiTechnic for providing me with the hardware necessary to write and test this.
18 | *
19 | * License: You may use this code as you wish, provided you give credit where it's due.
20 | *
21 | * THIS CODE WILL ONLY WORK WITH ROBOTC VERSION 4.10 AND HIGHER
22 |
23 | * Xander Soldaat (xander_at_botbench.com)
24 | * 20 February 2011
25 | * version 0.5
26 | */
27 |
28 | #include "hitechnic-accelerometer.h"
29 |
30 | task main () {
31 | displayCenteredTextLine(0, "HiTechnic");
32 | displayCenteredBigTextLine(1, "Accel");
33 | displayCenteredTextLine(3, "Test 1");
34 | displayCenteredTextLine(5, "Connect sensor");
35 | displayCenteredTextLine(6, "to S1");
36 | sleep(2000);
37 |
38 | playSound(soundBeepBeep);
39 | while(bSoundActive) sleep(1);
40 |
41 | // Create struct to hold sensor data
42 | tHTAC accelerometer;
43 |
44 | // Initialise and configure struct and port
45 | initSensor(&accelerometer, S1);
46 |
47 | while (true) {
48 | eraseDisplay();
49 |
50 | // Read all of the axes at once
51 | if (!readSensor(&accelerometer)) {
52 | displayTextLine(4, "ERROR!!");
53 | sleep(2000);
54 | stopAllTasks();
55 | }
56 |
57 | displayTextLine(0,"HTAC Test 1");
58 | displayTextLine(2, " X Y Z");
59 |
60 | displayTextLine(3, "%4d %4d %4d", accelerometer.x, accelerometer.y, accelerometer.z);
61 | // Alternatively, you can read them like this:
62 | displayTextLine(4, "%4d %4d %4d", accelerometer.axes[0], accelerometer.axes[1], accelerometer.axes[2]);
63 | sleep(100);
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/examples/hitechnic-angle-test1.c:
--------------------------------------------------------------------------------
1 | #pragma config(Sensor, S1, , sensorEV3_GenericI2C)
2 | //*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
3 |
4 | /**
5 | * hitechnic-angle.h provides an API for the HiTechnic Angle Sensor. This program
6 | * demonstrates how to use that API.
7 | *
8 | * Changelog:
9 | * - 0.1: Initial release
10 | * - 0.2: Removed common.h from includes
11 | *
12 | * Credits:
13 | * - Big thanks to HiTechnic for providing me with the hardware necessary to write and test this.
14 | *
15 | * License: You may use this code as you wish, provided you give credit where it's due.
16 | *
17 | * THIS CODE WILL ONLY WORK WITH ROBOTC VERSION 4.10 AND HIGHER
18 |
19 | * Xander Soldaat (xander_at_botbench.com)
20 | * date 20 February 2011
21 | * version 0.2
22 | */
23 |
24 | #include "hitechnic-angle.h"
25 |
26 | task main () {
27 |
28 | #ifdef NXT
29 | nNxtButtonTask = -2;
30 | #endif
31 |
32 | displayCenteredTextLine(0, "HiTechnic");
33 | displayCenteredBigTextLine(1, "Angle");
34 | displayCenteredTextLine(3, "Test 1");
35 | displayCenteredTextLine(5, "Connect sensor");
36 | displayCenteredTextLine(6, "to S1");
37 | sleep(2000);
38 |
39 | eraseDisplay();
40 | displayCenteredTextLine(0, "HiTechnic Angle");
41 | displayTextLine(1, "-------------------");
42 | displayTextLine(5, "-------------------");
43 |
44 | // Create struct to hold sensor data
45 | tHTANG angleSensor;
46 |
47 | // Initialise and configure struct and port
48 | initSensor(&angleSensor, S1);
49 |
50 | while (true) {
51 |
52 | // Reset all the values in the sensor
53 | if (getXbuttonValue(xButtonEnter)) {
54 | resetSensor(&angleSensor);
55 | while (!getXbuttonValue(xButtonAny)) sleep(1);
56 | }
57 |
58 | // If the left button is pressed, set the 0 point to the current angle
59 | else if (getXbuttonValue(xButtonLeft)) {
60 | resetAngle(&angleSensor);
61 | while (!getXbuttonValue(xButtonAny)) sleep(1);
62 |
63 | // Reset the total accumulated angle to 0
64 | } else if (getXbuttonValue(xButtonRight)) {
65 | resetAccmulatedAngle(&angleSensor);
66 | while (!getXbuttonValue(xButtonAny)) sleep(1);
67 | }
68 |
69 | // Read the data from the sensor
70 | readSensor(&angleSensor);
71 | displayTextLine(2, "Ang: %7d deg", angleSensor.angle);
72 | displayTextLine(3, "Tot: %7d deg", angleSensor.accumlatedAngle);
73 | displayTextLine(4, "RPM: %7d", angleSensor.rpm);
74 | displayTextLine(6, " < Set angle");
75 | displayTextLine(7, " Reset total >");
76 | sleep(50);
77 | }
78 | }
79 |
--------------------------------------------------------------------------------
/examples/hitechnic-barometer-SMUX-test1.c:
--------------------------------------------------------------------------------
1 | #pragma config(Sensor, S1, HTBM, sensorI2CCustom)
2 | //*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
3 |
4 | /**
5 | * hitechnic-barometer.h provides an API for the HiTechnic Barometric Sensor. This program
6 | * demonstrates how to use that API.
7 | *
8 | * Changelog:
9 | * - 0.1: Initial release
10 | * - 0.2: Removed common.h from includes
11 | *
12 | * Credits:
13 | * - Big thanks to HiTechnic for providing me with the hardware necessary to write and test this.
14 | *
15 | * License: You may use this code as you wish, provided you give credit where it's due.
16 | *
17 | * THIS CODE WILL ONLY WORK WITH ROBOTC VERSION 4.10 AND HIGHER
18 |
19 | * Xander Soldaat (xander_at_botbench.com)
20 | * 30 October 2010
21 | * version 0.1
22 | */
23 |
24 | #include "hitechnic-barometer.h"
25 |
26 | task main () {
27 |
28 | displayCenteredTextLine(0, "HiTechnic");
29 | displayCenteredBigTextLine(1, "BaroTemp");
30 | displayCenteredTextLine(3, "Test 1");
31 | displayCenteredTextLine(5, "Connect sensor");
32 | displayCenteredTextLine(6, "to the SMUX");
33 | sleep(2000);
34 |
35 | // Create struct to hold sensor data
36 | tHTBM pressureSensor;
37 |
38 | // Initialise and configure struct and port
39 | // The sensor is connected to the first port
40 | // of the SMUX which is connected to the NXT port S1.
41 | // To access that sensor, we must use msensor_S1_1. If the sensor
42 | // were connected to 3rd port of the SMUX connected to the NXT port S4,
43 | // we would use msensor_S4_3
44 | initSensor(&pressureSensor, msensor_S1_1);
45 |
46 | while (true) {
47 | eraseDisplay();
48 |
49 | // Read the sensor's data
50 | readSensor(&pressureSensor);
51 |
52 | displayCenteredTextLine(0, "HTBM Test 1");
53 | displayTextLine(2, "%5d mInHg", pressureSensor.mInHg);
54 | displayTextLine(3, "%5.1f hPa", pressureSensor.hPa);
55 | displayTextLine(4, "%5.1f PSI", pressureSensor.Psi);
56 | displayTextLine(6, "%3.1f C / %3.1f F", pressureSensor.Celcius, pressureSensor.Fahrenheit);
57 | drawLine(0, 52, 99, 52);
58 | drawLine(0, 20, 99, 20);
59 | sleep(100);
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/examples/hitechnic-barometer-test1.c:
--------------------------------------------------------------------------------
1 | #pragma config(Sensor, S1, HTBM, sensorI2CCustom)
2 | //*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
3 |
4 | /**
5 | * hitechnic-barometer.h provides an API for the HiTechnic Barometric Sensor. This program
6 | * demonstrates how to use that API.
7 | *
8 | * Changelog:
9 | * - 0.1: Initial release
10 | * - 0.2: Removed common.h from includes
11 | *
12 | * Credits:
13 | * - Big thanks to HiTechnic for providing me with the hardware necessary to write and test this.
14 | *
15 | * License: You may use this code as you wish, provided you give credit where it's due.
16 | *
17 | * THIS CODE WILL ONLY WORK WITH ROBOTC VERSION 4.10 AND HIGHER
18 |
19 | * Xander Soldaat (xander_at_botbench.com)
20 | * 30 October 2010
21 | * version 0.1
22 | */
23 |
24 | #include "hitechnic-barometer.h"
25 |
26 | task main () {
27 |
28 | displayCenteredTextLine(0, "HiTechnic");
29 | displayCenteredBigTextLine(1, "BaroTemp");
30 | displayCenteredTextLine(3, "Test 1");
31 | displayCenteredTextLine(5, "Connect sensor");
32 | displayCenteredTextLine(6, "to S1");
33 | sleep(2000);
34 |
35 | // Create struct to hold sensor data
36 | tHTBM pressureSensor;
37 |
38 | // Initialise and configure struct and port
39 | initSensor(&pressureSensor, S1);
40 |
41 | while (true) {
42 | eraseDisplay();
43 |
44 | // Read the sensor's data
45 | readSensor(&pressureSensor);
46 |
47 | displayCenteredTextLine(0, "HTBM Test 1");
48 | displayTextLine(2, "%5d mInHg", pressureSensor.mInHg);
49 | displayTextLine(3, "%5.1f hPa", pressureSensor.hPa);
50 | displayTextLine(4, "%5.1f PSI", pressureSensor.Psi);
51 | displayTextLine(6, "%3.1f C / %3.1f F", pressureSensor.Celcius, pressureSensor.Fahrenheit);
52 | drawLine(0, 52, 99, 52);
53 | drawLine(0, 20, 99, 20);
54 | sleep(100);
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/examples/hitechnic-colour-v2-SMUX-test1.c:
--------------------------------------------------------------------------------
1 |
2 |
3 | /**
4 | * hitechnic-colour-v2.h provides an API for the HiTechnic Color V2 Sensor. This program
5 | * demonstrates how to use that API.
6 |
7 | * Changelog:
8 | * - 0.1: Initial release
9 | * - 0.2: More comments
10 | * - 0.3: Now uses HTSMUX driver which has been split from common.h\n
11 | * HTSMUX initialisation and scanning functions have been removed\n
12 | *
13 | * Credits:
14 | * - Big thanks to HiTechnic for providing me with the hardware necessary to write and test this.
15 | *
16 | * License: You may use this code as you wish, provided you give credit where it's due.
17 | *
18 | * THIS CODE WILL ONLY WORK WITH ROBOTC VERSION 4.10 AND HIGHER
19 |
20 | * Xander Soldaat (xander_at_botbench.com)
21 | * 20 February 2011
22 | * version 0.3
23 | */
24 |
25 | #include "hitechnic-colour-v2.h"
26 |
27 | task main () {
28 | string _tmp;
29 |
30 | displayCenteredTextLine(0, "HiTechnic");
31 | displayCenteredBigTextLine(1, "COLOR V2");
32 | displayCenteredTextLine(3, "SMUX Test");
33 | displayCenteredTextLine(5, "Connect SMUX to");
34 | displayCenteredTextLine(6, "S1 and CS to");
35 | displayCenteredTextLine(7, "SMUX Port 1");
36 | sleep(2000);
37 |
38 | // Create struct to hold sensor data
39 | tHTCS2 colorSensor;
40 |
41 | // Initialise and configure struct and port
42 | // The sensor is connected to the first port
43 | // of the SMUX which is connected to the NXT port S1.
44 | // To access that sensor, we must use msensor_S1_1. If the sensor
45 | // were connected to 3rd port of the SMUX connected to the NXT port S4,
46 | // we would use msensor_S4_3
47 | initSensor(&colorSensor, msensor_S1_1);
48 |
49 | eraseDisplay();
50 | while (true)
51 | {
52 | // Read the currently detected colour and RGB/HSV data from the sensor
53 | if (!readSensor(&colorSensor)) {
54 | displayTextLine(4, "ERROR!!");
55 | sleep(2000);
56 | stopAllTasks();
57 | }
58 |
59 | displayCenteredTextLine(0, "Color: %d", colorSensor.color);
60 | displayCenteredBigTextLine(1, "R G B");
61 |
62 | eraseRect(0,10, 99, 41);
63 | fillRect( 0, 10, 30, 10 + (colorSensor.red+1)/8);
64 | fillRect(35, 10, 65, 10 + (colorSensor.green+1)/8);
65 | fillRect(70, 10, 99, 10 + (colorSensor.blue+1)/8);
66 | stringFormat(_tmp, " %3d %3d", colorSensor.red, colorSensor.green);
67 | displayTextLine(7, "%s %3d", _tmp, colorSensor.blue);
68 |
69 | sleep(100);
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/examples/hitechnic-colour-v2-test1.c:
--------------------------------------------------------------------------------
1 |
2 |
3 | /**
4 | * hitechnic-colour-v2.h provides an API for the HiTechnic Color V2 Sensor. This program
5 | * demonstrates how to use that API.
6 | *
7 | * Changelog:
8 | * - 0.1: Initial release
9 | * - 0.2: More comments
10 | * - 0.3: Removed common.h from includes
11 | *
12 | * Credits:
13 | * - Big thanks to HiTechnic for providing me with the hardware necessary to write and test this.
14 | *
15 | * License: You may use this code as you wish, provided you give credit where it's due.
16 | *
17 | * THIS CODE WILL ONLY WORK WITH ROBOTC VERSION 4.10 AND HIGHER
18 |
19 | * Xander Soldaat (xander_at_botbench.com)
20 | * 20 February 2011
21 | * version 0.3
22 | */
23 |
24 | #include "hitechnic-colour-v2.h"
25 |
26 | task main ()
27 | {
28 | displayCenteredTextLine(0, "HiTechnic");
29 | displayCenteredBigTextLine(1, "Color V2");
30 | displayCenteredTextLine(3, "Test 1");
31 | displayCenteredTextLine(5, "Connect sensor");
32 | displayCenteredTextLine(6, "to S1");
33 | sleep(2000);
34 |
35 | // Create struct to hold sensor data
36 | tHTCS2 colorSensor;
37 |
38 | // Initialise and configure struct and port
39 | initSensor(&colorSensor, S1);
40 |
41 | eraseDisplay();
42 | while (true)
43 | {
44 | // Read the currently detected colour and RGB/HSV data from the sensor
45 | if (!readSensor(&colorSensor)) {
46 | displayTextLine(4, "ERROR!!");
47 | sleep(2000);
48 | stopAllTasks();
49 | }
50 |
51 | displayCenteredTextLine(0, "Color: %d", colorSensor.color);
52 | displayCenteredBigTextLine(1, "R G B");
53 |
54 | eraseRect(0,10, 99, 41);
55 | fillRect( 0, 10, 30, 10 + (colorSensor.red+1)/8);
56 | fillRect(35, 10, 65, 10 + (colorSensor.green+1)/8);
57 | fillRect(70, 10, 99, 10 + (colorSensor.blue+1)/8);
58 | displayTextLine(7, " %3d %3d %3d", colorSensor.red, colorSensor.green, colorSensor.blue);
59 | writeDebugStreamLine("R: %d, G: %d, B: %d", colorSensor.red, colorSensor.green, colorSensor.blue);
60 | sleep(100);
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/examples/hitechnic-compass-test1.c:
--------------------------------------------------------------------------------
1 |
2 |
3 | /**
4 | * hitechnic-compass.h provides an API for the HiTechnic Compass Sensor. This program
5 | * demonstrates how to use that API.
6 | *
7 | * Changelog:
8 | * - 0.1: Initial release
9 | * - 0.2: More comments
10 | *
11 | * License: You may use this code as you wish, provided you give credit where it's due.
12 | *
13 | * THIS CODE WILL ONLY WORK WITH ROBOTC VERSION 4.10 AND HIGHER
14 |
15 | * Xander Soldaat (xander_at_botbench.com)
16 | * 25 November 2009
17 | * version 0.2
18 | */
19 |
20 | #include "hitechnic-compass.h"
21 |
22 | task main () {
23 | displayCenteredTextLine(0, "HiTechnic");
24 | displayCenteredBigTextLine(1, "Compass");
25 | displayCenteredTextLine(3, "Test 1");
26 | displayTextLine(5, "Press enter");
27 | displayTextLine(6, "to set target");
28 |
29 | sleep(2000);
30 | eraseDisplay();
31 |
32 | // Create struct to hold sensor data
33 | tHTMC compass;
34 |
35 | // Initialise and configure struct and port
36 | initSensor(&compass, S1);
37 |
38 | time1[T1] = 0;
39 | while(true) {
40 | // Reset the target no more than once a second
41 | // This also helps with debouncing the [enter] button.
42 | if (time1[T1] > 1000) {
43 | eraseDisplay();
44 | displayTextLine(1, "Changing");
45 | displayTextLine(2, "target");
46 | sleep(500);
47 |
48 | // Read the data from the sensor
49 | readSensor(&compass);
50 |
51 | // Set the current heading as the value for the offset to be used as the
52 | // new zero-point for the relative heading returned by
53 | // compass.relativeHeading
54 | compass.offset = compass.heading;
55 |
56 | playSound(soundBlip);
57 | while(bSoundActive) sleep(1);
58 | time1[T1] = 0;
59 | }
60 |
61 | // Get the true heading and relative heading from the sensor and
62 | // display them on the screen.
63 | while(!getXbuttonValue(xButtonEnter)) {
64 | // Read the data from the sensor
65 | readSensor(&compass);
66 | eraseDisplay();
67 | displayTextLine(1, "Reading");
68 | displayTextLine(2, "Target: %4d", compass.offset);
69 | displayTextLine(4, "Abs: %4d", compass.heading);
70 | displayTextLine(5, "Rel: %4d", compass.relativeHeading);
71 | displayTextLine(6, "Press enter");
72 | displayTextLine(7, "to set target");
73 | sleep(100);
74 | }
75 | }
76 | }
77 |
--------------------------------------------------------------------------------
/examples/hitechnic-force-SMUX-test1.c:
--------------------------------------------------------------------------------
1 | #pragma config(Sensor, S1, HTSMUX, sensorI2CCustom)
2 | //*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
3 |
4 | /**
5 | * HTCS-driver.h provides an API for the HiTechnic Force Sensor. This program
6 | * demonstrates how to use that API.
7 | *
8 | * Changelog:
9 | * - 0.1: Initial release
10 | *
11 | * Credits:
12 | * - Big thanks to HiTechnic for providing me with the hardware necessary to write and test this.
13 | *
14 | * License: You may use this code as you wish, provided you give credit where it's due.
15 | *
16 | * THIS CODE WILL ONLY WORK WITH ROBOTC VERSION 4.10 AND HIGHER
17 |
18 | * Xander Soldaat (xander_at_botbench.com)
19 | * 30 September 2012
20 | * version 0.1
21 | */
22 |
23 | #include "hitechnic-force.h"
24 |
25 | task main() {
26 | eraseDisplay();
27 | displayCenteredTextLine(0, "HiTechnic");
28 | displayCenteredBigTextLine(1, "Force");
29 | displayCenteredTextLine(3, "SMUX Test");
30 | displayCenteredTextLine(5, "Connect SMUX to");
31 | displayCenteredTextLine(6, "S1 and sensor to");
32 | displayCenteredTextLine(7, "SMUX Port 1");
33 | sleep(2000);
34 |
35 | // Create struct to hold sensor data
36 | tHTF forceSensor;
37 |
38 | // Initialise and configure struct and port
39 | // The sensor is connected to the first port
40 | // of the SMUX which is connected to the NXT port S1.
41 | // To access that sensor, we must use msensor_S1_1. If the sensor
42 | // were connected to 3rd port of the SMUX connected to the NXT port S4,
43 | // we would use msensor_S4_3
44 | initSensor(&forceSensor, msensor_S1_1);
45 |
46 | while(true) {
47 | // Read the sensor value
48 | readSensor(&forceSensor);
49 |
50 | displayClearTextLine(3);
51 | displayClearTextLine(4);
52 | displayTextLine(3, "Force: %4d", forceSensor.force);
53 | sleep(50);
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/examples/hitechnic-force-test1.c:
--------------------------------------------------------------------------------
1 | /**
2 | * HTCS-driver.h provides an API for the HiTechnic Force Sensor. This program
3 | * demonstrates how to use that API.
4 | *
5 | * Changelog:
6 | * - 0.1: Initial release
7 | *
8 | * Credits:
9 | * - Big thanks to HiTechnic for providing me with the hardware necessary to write and test this.
10 | *
11 | * License: You may use this code as you wish, provided you give credit where it's due.
12 | *
13 | * THIS CODE WILL ONLY WORK WITH ROBOTC VERSION 4.10 AND HIGHER
14 |
15 | * Xander Soldaat (xander_at_botbench.com)
16 | * 30 September 2012
17 | * version 0.1
18 | */
19 |
20 | #include "hitechnic-force.h"
21 |
22 | task main() {
23 | eraseDisplay();
24 |
25 | displayCenteredTextLine(0, "HiTechnic");
26 | displayCenteredBigTextLine(1, "Force");
27 | displayCenteredTextLine(3, "Test 1");
28 | sleep(2000);
29 | eraseDisplay();
30 |
31 | // Create struct to hold sensor data
32 | tHTF forceSensor;
33 |
34 | // Initialise and configure struct and port
35 | initSensor(&forceSensor, S1);
36 |
37 | while(true) {
38 | // Read the sensor value
39 | readSensor(&forceSensor);
40 |
41 | displayClearTextLine(3);
42 | displayClearTextLine(4);
43 | displayTextLine(3, "Force: %4d", forceSensor.force);
44 | sleep(50);
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/examples/hitechnic-gyro-test1.c:
--------------------------------------------------------------------------------
1 | /**
2 | * hitechnic-gyro.h provides an API for the HiTechnic Gyroscopic Sensor. This program
3 | * demonstrates how to use that API.
4 | *
5 | * Changelog:
6 | * - 0.1: Initial release
7 | * - 0.2: More comments
8 | * - 0.3: Removed common.h from includes
9 | *
10 | * Credits:
11 | * - Big thanks to HiTechnic for providing me with the hardware necessary to write and test this.
12 | *
13 | * License: You may use this code as you wish, provided you give credit where it's due.
14 | *
15 | * THIS CODE WILL ONLY WORK WITH ROBOTC VERSION 4.10 AND HIGHER
16 |
17 | * Xander Soldaat (xander_at_botbench.com)
18 | * 20 February 2011
19 | * version 0.3
20 | */
21 |
22 | #include "hitechnic-gyro.h"
23 |
24 | task main () {
25 | displayTextLine(0, "HT Gyro");
26 | displayTextLine(1, "Test 1");
27 | displayTextLine(5, "Press enter");
28 | displayTextLine(6, "to set relative");
29 | displayTextLine(7, "heading");
30 |
31 | sleep(2000);
32 | eraseDisplay();
33 |
34 | // Create struct to hold sensor data
35 | tHTGYRO gyroSensor;
36 |
37 | // Initialise and configure struct and port
38 | initSensor(&gyroSensor, S1);
39 |
40 | time1[T1] = 0;
41 | while(true) {
42 | if (time1[T1] > 1000) {
43 | eraseDisplay();
44 | displayTextLine(1, "Resetting");
45 | displayTextLine(1, "offset");
46 | sleep(500);
47 |
48 | // Start the calibration and display the offset
49 | sensorCalibrate(&gyroSensor);
50 |
51 | displayTextLine(2, "Offset: %f", gyroSensor.offset);
52 | playSound(soundBlip);
53 | while(bSoundActive) sleep(1);
54 | time1[T1] = 0;
55 | }
56 |
57 | while(!getXbuttonValue(xButtonEnter)) {
58 | eraseDisplay();
59 |
60 | displayTextLine(1, "Reading");
61 |
62 | // Read the current rotational speed
63 | readSensor(&gyroSensor);
64 |
65 | // Read the current calibration offset and display it
66 | displayTextLine(2, "Offset: %4f", gyroSensor.offset);
67 |
68 | displayClearTextLine(4);
69 | // Read the current rotational speed and display it
70 | displayTextLine(4, "Gyro: %4f", gyroSensor.rotation);
71 | displayTextLine(6, "Press enter");
72 | displayTextLine(7, "to recalibrate");
73 | sleep(100);
74 | }
75 | }
76 | }
77 |
--------------------------------------------------------------------------------
/examples/hitechnic-irlink-rcx-test1.c:
--------------------------------------------------------------------------------
1 | #pragma config(Sensor, S1, HTRCX, sensorI2CCustom)
2 | //*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
3 |
4 | /**
5 | * hitechnic-irlink-rcx.h provides an API for the HiTechnic IR Link Sensor to allow
6 | * communication between the NXT and RCX.
7 | *
8 | * Changelog:
9 | * - 0.1: Initial release
10 | *
11 | * Credits:
12 | * - Big thanks to HiTechnic for providing me with the hardware necessary to write and test this.
13 | * - Big thanks to Thorsten Benter for giving me one of his RCXs to work with!
14 | *
15 | * License: You may use this code as you wish, provided you give credit where it's due.
16 | *
17 | * THIS CODE WILL ONLY WORK WITH ROBOTC VERSION 4.10 AND HIGHER
18 |
19 | * Xander Soldaat (xander_at_botbench.com)
20 | * 16 September 2010
21 | * version 0.1
22 | */
23 |
24 | #include "hitechnic-irlink-rcx.h"
25 |
26 | task main () {
27 | short msg = 0x00FD;
28 | eraseDisplay();
29 | displayTextLine(6, "Press [enter]");
30 | displayTextLine(7, "to send msg");
31 | while(true) {
32 | // Increment the msg
33 | msg++;
34 | while(nNxtButtonPressed != kEnterButton) sleep(1);
35 | while(nNxtButtonPressed != kNoButton) sleep(1);
36 | // Send the message to the RCX and display
37 | playSound(soundBlip);
38 | displayCenteredBigTextLine(2, "0x%04X", msg);
39 | HTRCXsendWord(HTRCX, msg);
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/examples/hitechnic-irrecv-test1.c:
--------------------------------------------------------------------------------
1 | #pragma config(Sensor, S1, HTIRR, sensorI2CCustom)
2 | //*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
3 |
4 | /**
5 | * HTIRL-driver.h provides an API for the HiTechnic IR Receiver Sensor. This program
6 | * demonstrates how to use the IR Receiver API to display the currently transmitted
7 | * motor powers.
8 | *
9 | * Changelog:
10 | * - 0.1: Initial release
11 | * - 0.2: More comments
12 | *
13 | * Credits:
14 | * - Big thanks to HiTechnic for providing me with the hardware necessary to write and test this.
15 | *
16 | * License: You may use this code as you wish, provided you give credit where it's due.
17 | *
18 | * THIS CODE WILL ONLY WORK WITH ROBOTC VERSION 4.10 AND HIGHER
19 |
20 | * Xander Soldaat (xander_at_botbench.com)
21 | * 25 November 2009
22 | * version 0.2
23 | */
24 |
25 | #include "hitechnic-irrecv.h"
26 |
27 | /*
28 | =============================================================================
29 | main task with some testing code
30 |
31 | */
32 | task main {
33 | displayCenteredTextLine(0, "HiTechnic");
34 | displayCenteredBigTextLine(1, "IR Recv");
35 | displayCenteredTextLine(3, "Test 1");
36 | displayCenteredTextLine(5, "Connect sensor");
37 | displayCenteredTextLine(6, "to S1");
38 | sleep(2000);
39 | eraseDisplay();
40 |
41 | // Create struct to hold sensor data
42 | tHTIRR irReceiver;
43 |
44 | // Initialise and configure struct and port
45 | initSensor(&irReceiver, S1);
46 |
47 | while (true) {
48 | // Read the data from the sensor
49 | if (!readSensor(&irReceiver)) {
50 | displayTextLine(4, "ERROR!!");
51 | sleep(2000);
52 | stopAllTasks();
53 | }
54 |
55 | for (short i = 0; i < 4; i++) {
56 | // Read the motor powers sent by the remote on the specified channel
57 | // and display them.
58 | displayTextLine(i, "%4d, %4d", irReceiver.motA[i], irReceiver.motB[i]);
59 | sleep(10);
60 | }
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/examples/hitechnic-irseeker-v2-SMUX-test1.c:
--------------------------------------------------------------------------------
1 | /**
2 | * hitechnic-irseeker-v2.h provides an API for the HiTechnic IR Seeker V2. This program
3 | * demonstrates how to use that API.
4 | *
5 | * Changelog:
6 | * - 0.1: Initial release
7 | *
8 | * Credits:
9 | * - Big thanks to HiTechnic for providing me with the hardware necessary to write and test this.
10 | *
11 | * License: You may use this code as you wish, provided you give credit where it's due.
12 | *
13 | * THIS CODE WILL ONLY WORK WITH ROBOTC VERSION 4.10 AND HIGHER
14 |
15 | * Xander Soldaat (xander_at_botbench.com)
16 | * Dick Swan
17 | * Gus Jansson
18 | * 04 October 2012
19 | * version 0.1
20 | */
21 |
22 | #include "hitechnic-irseeker-v2.h"
23 |
24 | // main task
25 | task main ()
26 | {
27 | displayCenteredTextLine(0, "HiTechnic");
28 | displayCenteredBigTextLine(1, "IRSeekr2");
29 | displayCenteredTextLine(3, "SMUX Test");
30 | displayCenteredTextLine(5, "Connect SMUX to");
31 | displayCenteredTextLine(6, "S1 and sensor to");
32 | displayCenteredTextLine(7, "SMUX Port 1");
33 | sleep(2000);
34 |
35 | // Create struct to hold sensor data
36 | tHTIRS2 irSeeker;
37 |
38 | // The sensor is connected to the first port
39 | // of the SMUX which is connected to the NXT port S1.
40 | // To access that sensor, we must use msensor_S1_1. If the sensor
41 | // were connected to 3rd port of the SMUX connected to the NXT port S4,
42 | // we would use msensor_S4_3
43 |
44 | // Initialise and configure struct and port
45 | initSensor(&irSeeker, msensor_S1_1);
46 |
47 | while(true)
48 | {
49 | // You can switch between the two different DSP modes by pressing the
50 | // orange enter button
51 |
52 | playSound(soundBeepBeep);
53 | while(bSoundActive)
54 | {}
55 | eraseDisplay();
56 |
57 | displayTextLine(0, " DC 1200");
58 |
59 | while (true)
60 | {
61 | // Read the sensor data.
62 | readSensor(&irSeeker);
63 | displayTextLine(1, "D:%4d %4d %3d", irSeeker.dcDirection, irSeeker.acDirection, irSeeker.enhDirection);
64 | displayTextLine(2, "0:%4d %4d", irSeeker.dcValues[0], irSeeker.acValues[0]);
65 | displayTextLine(3, "0:%4d %4d", irSeeker.dcValues[1], irSeeker.acValues[1]);
66 | displayTextLine(4, "0:%4d %4d %3d", irSeeker.dcValues[2], irSeeker.acValues[2], irSeeker.enhStrength);
67 | displayTextLine(5, "0:%4d %4d", irSeeker.dcValues[3], irSeeker.acValues[3]);
68 | displayTextLine(6, "0:%4d %4d", irSeeker.dcValues[4], irSeeker.acValues[4]);
69 | displayTextLine(7, "Enter to switch");
70 | }
71 | }
72 | }
73 |
--------------------------------------------------------------------------------
/examples/hitechnic-magfield-test1.c:
--------------------------------------------------------------------------------
1 | #pragma config(Sensor, S1, HTMAG, sensorAnalogInactive)
2 | //*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
3 |
4 | /**
5 | * hitechnic-magfield.h provides an API for the HiTechnic Magnetic Field Sensor. This program
6 | * demonstrates how to use that API.
7 | *
8 | * Changelog:
9 | * - 0.1: Initial release
10 | *
11 | * Credits:
12 | * - Big thanks to HiTechnic for providing me with the hardware necessary to write and test this.
13 | *
14 | * License: You may use this code as you wish, provided you give credit where it's due.
15 | *
16 | * THIS CODE WILL ONLY WORK WITH ROBOTC VERSION 4.10 AND HIGHER
17 |
18 | * Xander Soldaat (xander_at_botbench.com)
19 | * 27 July 2010
20 | * version 0.1
21 | */
22 |
23 | #include "hitechnic-magfield.h"
24 |
25 | task main () {
26 | displayCenteredTextLine(0, "HiTechnic");
27 | displayCenteredBigTextLine(1, "MAGNETIC");
28 | displayCenteredTextLine(3, "Field Sensor");
29 | displayCenteredTextLine(4, "Test 1");
30 | displayCenteredTextLine(5, "Connect Sensor");
31 | displayCenteredTextLine(6, "to S1");
32 |
33 | sleep(2000);
34 |
35 | displayCenteredTextLine(5, "Press enter");
36 | displayCenteredTextLine(6, "to set bias");
37 |
38 | sleep(2000);
39 | eraseDisplay();
40 |
41 | // Create struct to hold sensor data
42 | tHTMAG magneticSensor;
43 |
44 | // Initialise and configure struct and port
45 | initSensor(&magneticSensor, S1);
46 |
47 | while(true) {
48 | eraseDisplay();
49 | displayTextLine(1, "Resetting");
50 | displayTextLine(2, "bias");
51 | sleep(500);
52 |
53 | // Start the calibration and display the offset
54 | sensorCalibrate(&magneticSensor);
55 |
56 | displayTextLine(2, "Bias: %4d", magneticSensor.bias);
57 | playSound(soundBlip);
58 | while(bSoundActive) sleep(1);
59 | while(getXbuttonValue(xButtonAny)) sleep(1);
60 |
61 | while(!getXbuttonValue(xButtonEnter)) {
62 | eraseDisplay();
63 |
64 | // Read the sensor data
65 | readSensor(&magneticSensor);
66 |
67 | displayTextLine(1, "Reading");
68 | // Display the current calibration value
69 | displayTextLine(2, "Bias: %4d", magneticSensor.bias);
70 |
71 | displayClearTextLine(4);
72 | // Display the current magnetic field strength
73 | displayTextLine(4, "Mag: %4d", magneticSensor.strength);
74 | displayTextLine(6, "Press enter");
75 | displayTextLine(7, "to recalibrate");
76 | sleep(100);
77 | }
78 | }
79 | }
80 |
--------------------------------------------------------------------------------
/examples/hitechnic-pir-test1.c:
--------------------------------------------------------------------------------
1 | /**
2 | * hitechnic-pir.h provides an API for the HiTechnic PIR Sensor. This program
3 | * demonstrates how to use that API.
4 | *
5 | * Changelog:
6 | * - 0.1: Initial release
7 | *
8 | * License: You may use this code as you wish, provided you give credit where it's due.
9 | *
10 | * THIS CODE WILL ONLY WORK WITH ROBOTC VERSION 4.10 AND HIGHER
11 |
12 | * Xander Soldaat (xander_at_botbench.com)
13 | * 26 August 2012
14 | * version 0.1
15 | */
16 |
17 | #include "hitechnic-pir.h"
18 |
19 | // Draw a little stick figure
20 | void drawStickFigure(short offset)
21 | {
22 | eraseRect(0, 0, 99, 50);
23 | drawCircle(offset + 43, 40, 15);
24 | drawLine(offset + 50,25,offset + 50,10);
25 | drawLine(offset + 43, 22, offset + 58, 22);
26 | drawLine(offset + 43, 0, offset + 50, 10);
27 | drawLine(offset + 50, 10, offset + 58, 0);
28 | }
29 |
30 | task main () {
31 | long x = 0;
32 |
33 | displayCenteredTextLine(0, "HiTechnic");
34 | displayCenteredBigTextLine(1, "PIR");
35 | displayCenteredTextLine(3, "Test 1");
36 | displayCenteredTextLine(6, "L/ENTER/R");
37 | displayCenteredTextLine(7, "change deadband");
38 |
39 | sleep(2000);
40 | eraseDisplay();
41 |
42 | // Create struct to hold sensor data
43 | tHTPIR pirSensor;
44 |
45 | // Initialise and configure struct and port
46 | initSensor(&pirSensor, S1);
47 |
48 | while(true) {
49 | if (getXbuttonValue(xButtonAny))
50 | {
51 | if (getXbuttonValue(xButtonRight))
52 | pirSensor.deadband++;
53 | else if (getXbuttonValue(xButtonRight))
54 | pirSensor.deadband--;
55 | else if (getXbuttonValue(xButtonRight))
56 | pirSensor.deadband = HTPIR_DEFAULT_DEADBAND;
57 |
58 | // Make sure the value stays between 0 and 47
59 | pirSensor.deadband = clip(pirSensor.deadband, 0, 47);
60 |
61 |
62 | // Set the new dead band value.
63 | sensorCalibrate(&pirSensor);
64 |
65 | // Debounce
66 | while (getXbuttonValue(xButtonAny)) sleep(1);
67 | }
68 |
69 | // Get the IR levels from the PIR sensor
70 | readSensor(&pirSensor);
71 |
72 | displayTextLine(0, "HT PIR %d / %d", pirSensor.deadband, pirSensor.value);
73 |
74 | // Draw a cool little stick figure
75 | x = (40 * pirSensor.value) / 100;
76 | drawStickFigure(x);
77 | sleep(50);
78 |
79 | }
80 | }
81 |
--------------------------------------------------------------------------------
/examples/hitechnic-protoboard-SMUX-test1.c:
--------------------------------------------------------------------------------
1 | #pragma config(Sensor, S1, HTSMUX, sensorI2CCustom)
2 | //*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
3 |
4 | /**
5 | * hitechnic-protoboard.h provides an API for the HiTechnic Protoboard. This program
6 | * demonstrates how to use that API.
7 | *
8 | * Changelog:
9 | * - 0.1: Initial release
10 | * - 0.2: More comments
11 | *
12 | * Credits:
13 | * - Big thanks to HiTechnic for providing me with the hardware necessary to write and test this.
14 | *
15 | * License: You may use this code as you wish, provided you give credit where it's due.
16 | *
17 | * THIS CODE WILL ONLY WORK WITH ROBOTC VERSION 4.10 AND HIGHER
18 |
19 | * Xander Soldaat (xander_at_botbench.com)
20 | * 25 November 2009
21 | * version 0.2
22 | */
23 |
24 | #include "hitechnic-sensormux.h"
25 | #include "hitechnic-protoboard.h"
26 |
27 | // The sensor is connected to the first port
28 | // of the SMUX which is connected to the NXT port S1.
29 | // To access that sensor, we must use msensor_S1_1. If the sensor
30 | // were connected to 3rd port of the SMUX connected to the NXT port S4,
31 | // we would use msensor_S4_3
32 |
33 | // Give the sensor a nice easy to use name
34 | const tMUXSensor HTPB = msensor_S1_1;
35 |
36 | task main() {
37 | byte inputs = 0;
38 |
39 | displayCenteredTextLine(0, "HiTechnic");
40 | displayCenteredBigTextLine(1, "Proto");
41 | displayCenteredTextLine(3, "Test 1");
42 | displayCenteredTextLine(5, "Connect SMUX to");
43 | displayCenteredTextLine(6, "S1 and HTPB to");
44 | displayCenteredTextLine(7, "SMUX Port 1");
45 | sleep(2000);
46 |
47 | playSound(soundBeepBeep);
48 | while(bSoundActive) sleep(1);
49 |
50 | eraseDisplay();
51 |
52 | while(true) {
53 | // Fetch the state of the digital IO pins. When not explicitly
54 | // configured as input or output, they will default to input.
55 | inputs = HTPBreadIO(HTPB, 0x3F);
56 | displayTextLine(4, "D: 0x%x", (short)inputs);
57 | sleep(10);
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/examples/hitechnic-protoboard-SMUX-test2.c:
--------------------------------------------------------------------------------
1 | #pragma config(Sensor, S1, HTSMUX, sensorI2CCustom)
2 | //*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
3 |
4 | /**
5 | * hitechnic-protoboard.h provides an API for the HiTechnic Protoboard. This program
6 | * demonstrates how to use that API.
7 | *
8 | * Changelog:
9 | * - 0.1: Initial release
10 | * - 0.2: More comments
11 | *
12 | * Credits:
13 | * - Big thanks to HiTechnic for providing me with the hardware necessary to write and test this.
14 | *
15 | * License: You may use this code as you wish, provided you give credit where it's due.
16 | *
17 | * THIS CODE WILL ONLY WORK WITH ROBOTC VERSION 4.10 AND HIGHER
18 |
19 | * Xander Soldaat (xander_at_botbench.com)
20 | * 25 November 2009
21 | * version 0.2
22 | */
23 |
24 | #include "hitechnic-sensormux.h"
25 | #include "hitechnic-protoboard.h"
26 |
27 | // The sensor is connected to the first port
28 | // of the SMUX which is connected to the NXT port S1.
29 | // To access that sensor, we must use msensor_S1_1. If the sensor
30 | // were connected to 3rd port of the SMUX connected to the NXT port S4,
31 | // we would use msensor_S4_3
32 |
33 | // Give the sensor a nice easy to use name
34 | const tMUXSensor HTPB = msensor_S1_1;
35 |
36 | task main() {
37 | short _chVal = 0;
38 |
39 | displayCenteredTextLine(0, "HiTechnic");
40 | displayCenteredBigTextLine(1, "Proto");
41 | displayCenteredTextLine(3, "Test 1");
42 | displayCenteredTextLine(5, "Connect SMUX to");
43 | displayCenteredTextLine(6, "S1 and HTPB to");
44 | displayCenteredTextLine(7, "SMUX Port 1");
45 | sleep(2000);
46 |
47 | playSound(soundBeepBeep);
48 | while(bSoundActive) sleep(1);
49 |
50 | eraseDisplay();
51 |
52 | while(true) {
53 | eraseDisplay();
54 | // get the value for ADC channel 0, we want a 10 bit answer
55 | _chVal = HTPBreadADC(HTPB, 0, 10);
56 | displayTextLine(4, "A0: %d", _chVal);
57 |
58 | sleep(10);
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/examples/hitechnic-protoboard-exp1.c:
--------------------------------------------------------------------------------
1 | #pragma config(Sensor, S1, HTPB, sensorI2CCustom9V)
2 | //*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
3 |
4 | /**
5 | * hitechnic-protoboard.h provides an API for the HiTechnic Protoboard. This is program 1
6 | * for the HTPB experimenter's kit.
7 | *
8 | * Changelog:
9 | * - 0.1: Initial release
10 | * - 0.2: Removed common.h from includes
11 | *
12 | * Credits:
13 | * - Big thanks to HiTechnic for providing me with the hardware necessary to write and test this.
14 | *
15 | * License: You may use this code as you wish, provided you give credit where it's due.
16 | *
17 | * THIS CODE WILL ONLY WORK WITH ROBOTC VERSION 4.10 AND HIGHER
18 |
19 | * Xander Soldaat (xander_at_botbench.com)
20 | * 14 February 2011
21 | * version 0.2
22 | */
23 |
24 | #include "hitechnic-protoboard.h"
25 |
26 | task main() {
27 | // Local variables
28 | short inputdata;
29 |
30 | // The data to be written: 0x3F = 111111 binary,
31 | // makes all digital ports outputs.
32 | HTPBsetupIO(HTPB, 0x3F);
33 |
34 | while(true) {
35 | // Read a 10bit wide analogue value from A0
36 | inputdata = HTPBreadADC(HTPB, 0, 10);
37 | eraseDisplay();
38 | displayTextLine(1, "%d", inputdata);
39 |
40 | // If A0 is less than 50% of the max value
41 | // turn off the LED, otherwise switch it on
42 | if(inputdata < 512)
43 | HTPBwriteIO(HTPB, 0x00);
44 | else
45 | HTPBwriteIO(HTPB, 0x01);
46 |
47 | sleep(50);
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/examples/hitechnic-protoboard-exp2.c:
--------------------------------------------------------------------------------
1 | #pragma config(Sensor, S1, HTPB, sensorI2CCustom9V)
2 | //*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
3 |
4 | /**
5 | * hitechnic-protoboard.h provides an API for the HiTechnic Protoboard. This is program 2
6 | * for the HTPB experimenter's kit.
7 | *
8 | * Changelog:
9 | * - 0.1: Initial release
10 | *
11 | * Credits:
12 | * - Big thanks to HiTechnic for providing me with the hardware necessary to write and test this.
13 | *
14 | * License: You may use this code as you wish, provided you give credit where it's due.
15 | *
16 | * THIS CODE WILL ONLY WORK WITH ROBOTC VERSION 4.10 AND HIGHER
17 |
18 | * Xander Soldaat (xander_at_botbench.com)
19 | * 07 May 2010
20 | * version 0.1
21 | */
22 |
23 | #include "hitechnic-protoboard.h"
24 |
25 | task main() {
26 | // Local variables
27 | short inputdata;
28 | ubyte outputdata;
29 |
30 | // The data to be written: 0x3F = 111111 binary,
31 | // makes all digital ports outputs.
32 | HTPBsetupIO(HTPB, 0x3F);
33 |
34 | while(true) {
35 | // Read a 10bit wide analogue value from A0
36 | inputdata = HTPBreadADC(HTPB, 0, 10);
37 |
38 | eraseDisplay();
39 | displayTextLine(1, "%d", inputdata);
40 |
41 | // Depending on the input voltage on A0,
42 | // turn on the corresponding LED.
43 | outputdata = 0x01;
44 | if (inputdata > 31) outputdata = 0x02;
45 | if (inputdata > 63) outputdata = 0x04;
46 | if (inputdata > 127) outputdata = 0x08;
47 | if (inputdata > 255) outputdata = 0x10;
48 | if (inputdata > 511) outputdata = 0x20;
49 |
50 | HTPBwriteIO(HTPB, outputdata);
51 | sleep(50);
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/examples/hitechnic-protoboard-exp3.c:
--------------------------------------------------------------------------------
1 | #pragma config(Sensor, S1, HTPB, sensorI2CCustom9V)
2 | #pragma config(Sensor, S2, SOUND_PORT, sensorAnalogInactive)
3 | //*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
4 |
5 | /**
6 | * hitechnic-protoboard.h provides an API for the HiTechnic Protoboard. This is program 3
7 | * for the HTPB experimenter's kit.
8 | *
9 | * Changelog:
10 | * - 0.1: Initial release
11 | *
12 | * Credits:
13 | * - Big thanks to HiTechnic for providing me with the hardware necessary to write and test this.
14 | *
15 | * License: You may use this code as you wish, provided you give credit where it's due.
16 | *
17 | * THIS CODE WILL ONLY WORK WITH ROBOTC VERSION 4.10 AND HIGHER
18 |
19 | * Xander Soldaat (xander_at_botbench.com)
20 | * 07 May 2010
21 | * version 0.1
22 | */
23 |
24 | #include "hitechnic-protoboard.h"
25 |
26 | task main() {
27 | // Local variables
28 | short soundlevel;
29 | ubyte outputdata;
30 |
31 | // The data to be written: 0x3F = 111111 binary,
32 | // makes all digital ports outputs.
33 | HTPBsetupIO(HTPB, 0x3F);
34 |
35 | while(true) {
36 | // Get the value from the LEGO sound sensor.
37 | soundlevel = 1023 - SensorValue[SOUND_PORT];
38 |
39 | eraseDisplay();
40 | displayTextLine(1, "%d", soundlevel);
41 |
42 | // Depending on the input voltage on A0,
43 | // turn on the corresponding LED.
44 | outputdata = 0x01;
45 | outputdata = 0x01;
46 | if (soundlevel > 65) outputdata = 0x02;
47 | if (soundlevel > 108) outputdata = 0x04;
48 | if (soundlevel > 180) outputdata = 0x08;
49 | if (soundlevel > 300) outputdata = 0x10;
50 | if (soundlevel > 500) outputdata = 0x20;
51 |
52 | HTPBwriteIO(HTPB, outputdata);
53 | sleep(50);
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/examples/hitechnic-protoboard-exp4.c:
--------------------------------------------------------------------------------
1 | #pragma config(Sensor, S1, HTPB, sensorI2CCustom9V)
2 | //*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
3 |
4 | /**
5 | * hitechnic-protoboard.h provides an API for the HiTechnic Protoboard. This is program 4
6 | * for the HTPB experimenter's kit.
7 | *
8 | * Changelog:
9 | * - 0.1: Initial release
10 | *
11 | * Credits:
12 | * - Big thanks to HiTechnic for providing me with the hardware necessary to write and test this.
13 | *
14 | * License: You may use this code as you wish, provided you give credit where it's due.
15 | *
16 | * THIS CODE WILL ONLY WORK WITH ROBOTC VERSION 4.10 AND HIGHER
17 |
18 | * Xander Soldaat (xander_at_botbench.com)
19 | * 07 May 2010
20 | * version 0.1
21 | */
22 |
23 | #include "hitechnic-protoboard.h"
24 |
25 | task main() {
26 | // Local variables
27 | short inputdata;
28 |
29 | while(true) {
30 | // Read a 10bit wide analogue value from A0
31 | inputdata = HTPBreadADC(HTPB, 0, 10);
32 |
33 | eraseDisplay();
34 | displayTextLine(1, "%d", inputdata);
35 |
36 | sleep(50);
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/examples/hitechnic-protoboard-exp5.c:
--------------------------------------------------------------------------------
1 | #pragma config(Sensor, S1, HTPB, sensorI2CCustom9V)
2 | //*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
3 |
4 | /**
5 | * hitechnic-protoboard.h provides an API for the HiTechnic Protoboard. This is program 5
6 | * for the HTPB experimenter's kit.
7 | *
8 | * Changelog:
9 | * - 0.1: Initial release
10 | *
11 | * Credits:
12 | * - Big thanks to HiTechnic for providing me with the hardware necessary to write and test this.
13 | *
14 | * License: You may use this code as you wish, provided you give credit where it's due.
15 | *
16 | * THIS CODE WILL ONLY WORK WITH ROBOTC VERSION 4.10 AND HIGHER
17 |
18 | * Xander Soldaat (xander_at_botbench.com)
19 | * 07 May 2010
20 | * version 0.1
21 | */
22 |
23 | #include "hitechnic-protoboard.h"
24 |
25 | short wlight;
26 | short wolight;
27 | short lightdelta;
28 |
29 | task main() {
30 | // The data to be written: 0x3F = 111111 binary,
31 | // makes all digital ports outputs.
32 | HTPBsetupIO(HTPB, 0x3F);
33 |
34 | while(true) {
35 | // Switch off LED on port B0
36 | HTPBwriteIO(HTPB, 0x00);
37 | sleep(30);
38 | wolight = HTPBreadADC(HTPB, 0, 10);
39 |
40 | // Switch on LED on port B0
41 | HTPBwriteIO(HTPB, 0x01);
42 | sleep(30);
43 | wlight = HTPBreadADC(HTPB, 0, 10);
44 |
45 | // Calculate the difference
46 | lightdelta = wlight - wolight;
47 |
48 | eraseDisplay();
49 | displayTextLine(1, "%4d", wlight);
50 | displayTextLine(2, "%4d", wolight);
51 | displayTextLine(3, "%4d", lightdelta);
52 | sleep(30);
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/examples/hitechnic-protoboard-exp6a.c:
--------------------------------------------------------------------------------
1 | #pragma config(Sensor, S1, HTPB, sensorI2CCustom9V)
2 | //*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
3 |
4 | /**
5 | * hitechnic-protoboard.h provides an API for the HiTechnic Protoboard. This is program 6a
6 | * for the HTPB experimenter's kit.
7 | *
8 | * Changelog:
9 | * - 0.1: Initial release
10 | *
11 | * Credits:
12 | * - Big thanks to HiTechnic for providing me with the hardware necessary to write and test this.
13 | *
14 | * License: You may use this code as you wish, provided you give credit where it's due.
15 | *
16 | * THIS CODE WILL ONLY WORK WITH ROBOTC VERSION 4.10 AND HIGHER
17 |
18 | * Xander Soldaat (xander_at_botbench.com)
19 | * 07 May 2010
20 | * version 0.1
21 | */
22 |
23 | #include "hitechnic-protoboard.h"
24 |
25 | task main() {
26 | // The data to be written: 0x30 = 110000 binary,
27 | // makes B4,B5 digital ports outputs.
28 | HTPBsetupIO(HTPB, 0x30);
29 |
30 | while(true) {
31 |
32 | // Turn off the LED
33 | HTPBwriteIO(HTPB, 0x00);
34 |
35 | eraseDisplay();
36 | displayTextLine(2, "running");
37 |
38 | // Wait a random time between 5 and 10 seconds.
39 | sleep(random(5000) + 5000);
40 |
41 | // Switch on the LED and reset the timer
42 | HTPBwriteIO(HTPB, 0x10);
43 | time1[T1] = 0;
44 |
45 | // Wait for user to press the stop button
46 | while (HTPBreadIO(HTPB, 0xF3) != 0x01) {
47 | sleep(5);
48 | }
49 |
50 | eraseDisplay();
51 | displayTextLine(2, "%d", time1[T1]);
52 |
53 | // Wait for user to reset
54 | while (HTPBreadIO(HTPB, 0xF3) != 0x03) {
55 | sleep(5);
56 | }
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/examples/hitechnic-protoboard-exp6b.c:
--------------------------------------------------------------------------------
1 | #pragma config(Sensor, S1, HTPB, sensorI2CCustom9V)
2 | //*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
3 |
4 | /**
5 | * hitechnic-protoboard.h provides an API for the HiTechnic Protoboard. This is program 6b
6 | * for the HTPB experimenter's kit.
7 | *
8 | * Changelog:
9 | * - 0.1: Initial release
10 | *
11 | * Credits:
12 | * - Big thanks to HiTechnic for providing me with the hardware necessary to write and test this.
13 | *
14 | * License: You may use this code as you wish, provided you give credit where it's due.
15 | *
16 | * THIS CODE WILL ONLY WORK WITH ROBOTC VERSION 4.10 AND HIGHER
17 |
18 | * Xander Soldaat (xander_at_botbench.com)
19 | * 07 May 2010
20 | * version 0.1
21 | */
22 |
23 | #include "hitechnic-protoboard.h"
24 |
25 | ubyte buttonmask = 0;
26 |
27 | task main() {
28 | // The data to be written: 0x30 = 110000 binary,
29 | // makes B4,B5 digital ports outputs.
30 | HTPBsetupIO(HTPB, 0x30);
31 |
32 | while(true) {
33 | // Turn off all outputs
34 | HTPBwriteIO(HTPB, 0x00);
35 |
36 | eraseDisplay();
37 | displayTextLine(2, "running");
38 |
39 | sleep(random(5000) + 5000);
40 |
41 | // Turn on a random LED
42 | if(random(1) > 0) {
43 | HTPBwriteIO(HTPB, 0x10);
44 | buttonmask = 0x01;
45 | } else {
46 | HTPBwriteIO(HTPB, 0x20);
47 | buttonmask = 0x02;
48 | }
49 |
50 | time1[T1] = 0;
51 |
52 | while ((ubyte)HTPBreadIO(HTPB, 0xF3) != buttonmask) {
53 | sleep(5);
54 | }
55 |
56 | eraseDisplay();
57 | displayTextLine(2, "%d", time1[T1]);
58 |
59 | while (HTPBreadIO(HTPB, 0xF3) != 0x03) {
60 | sleep(5);
61 | }
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/examples/hitechnic-protoboard-exp7.c:
--------------------------------------------------------------------------------
1 | #pragma config(Sensor, S1, HTPB, sensorI2CCustom9V)
2 | //*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
3 |
4 | /**
5 | * hitechnic-protoboard.h provides an API for the HiTechnic Protoboard. This is program 7
6 | * for the HTPB experimenter's kit.
7 | *
8 | * Changelog:
9 | * - 0.1: Initial release
10 | *
11 | * Credits:
12 | * - Big thanks to HiTechnic for providing me with the hardware necessary to write and test this.
13 | *
14 | * License: You may use this code as you wish, provided you give credit where it's due.
15 | *
16 | * THIS CODE WILL ONLY WORK WITH ROBOTC VERSION 4.10 AND HIGHER
17 |
18 | * Xander Soldaat (xander_at_botbench.com)
19 | * 07 May 2010
20 | * version 0.1
21 | */
22 |
23 | #include "hitechnic-protoboard.h"
24 |
25 | task main() {
26 | // The data to be written: 0x10 = 010000 binary,
27 | // makes B4 digital port an output.
28 | HTPBsetupIO(HTPB, 0x10);
29 |
30 | while(true) {
31 | if(HTPBreadIO(HTPB, 0xF3) == 0) {
32 | eraseDisplay();
33 | displayTextLine(1, "Magnet present");
34 | HTPBwriteIO(HTPB, 0x10);
35 | } else {
36 | eraseDisplay();
37 | displayTextLine(1, "Magnet absent");
38 | HTPBwriteIO(HTPB, 0x00);
39 | }
40 | sleep(50);
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/examples/hitechnic-protoboard-exp8.c:
--------------------------------------------------------------------------------
1 | #pragma config(Sensor, S1, HTPB, sensorI2CCustom9V)
2 | //*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
3 |
4 | /**
5 | * hitechnic-protoboard.h provides an API for the HiTechnic Protoboard. This is program 7
6 | * for the HTPB experimenter's kit.
7 | *
8 | * Changelog:
9 | * - 0.1: Initial release
10 | *
11 | * Credits:
12 | * - Big thanks to HiTechnic for providing me with the hardware necessary to write and test this.
13 | *
14 | * License: You may use this code as you wish, provided you give credit where it's due.
15 | *
16 | * THIS CODE WILL ONLY WORK WITH ROBOTC VERSION 4.10 AND HIGHER
17 |
18 | * Xander Soldaat (xander_at_botbench.com)
19 | * 07 May 2010
20 | * version 0.1
21 | */
22 |
23 | #include "hitechnic-protoboard.h"
24 |
25 | // This is the temperature at which we switch on the LED
26 | #define THRESHOLD 28
27 |
28 | long temperature;
29 | long inputdata;
30 |
31 | task main() {
32 | // The data to be written: 0x3F = 111111 binary,
33 | // makes B4 digital port an output.
34 | HTPBsetupIO(HTPB, 0x3F);
35 |
36 | while(true) {
37 | // Read the value from the temp sensor
38 | inputdata = HTPBreadADC(HTPB, 0, 10);
39 |
40 | // Convert to an actual temperature
41 | temperature = ((inputdata - 186) * 32 / 99);
42 | eraseDisplay();
43 | displayTextLine(1, "%d", temperature);
44 |
45 | // If we're above 28 degrees, switch on the LED
46 | if(temperature > THRESHOLD) {
47 | HTPBwriteIO(HTPB, 0x10);
48 | } else {
49 | HTPBwriteIO(HTPB, 0x00);
50 | }
51 | sleep(50);
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/examples/hitechnic-protoboard-test1.c:
--------------------------------------------------------------------------------
1 | #pragma config(Sensor, S1, HTPB, sensorI2CCustom9V)
2 | //*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
3 |
4 | /**
5 | * hitechnic-protoboard.h provides an API for the HiTechnic Protoboard. This program
6 | * demonstrates how to use that API.
7 | *
8 | * Changelog:
9 | * - 0.1: Initial release
10 | * - 0.2: More comments
11 | *
12 | * Credits:
13 | * - Big thanks to HiTechnic for providing me with the hardware necessary to write and test this.
14 | *
15 | * License: You may use this code as you wish, provided you give credit where it's due.
16 | *
17 | * THIS CODE WILL ONLY WORK WITH ROBOTC VERSION 4.10 AND HIGHER
18 |
19 | * Xander Soldaat (xander_at_botbench.com)
20 | * 25 November 2009
21 | * version 0.2
22 | */
23 |
24 | #include "hitechnic-protoboard.h"
25 |
26 | task main() {
27 | short _chVal = 0;
28 |
29 | displayCenteredTextLine(0, "HiTechnic");
30 | displayCenteredBigTextLine(1, "Proto");
31 | displayCenteredTextLine(3, "Test 1");
32 | displayCenteredTextLine(5, "Connect HTPB");
33 | displayCenteredTextLine(6, "to S1");
34 |
35 | sleep(2000);
36 | // Setup all the digital IO ports as outputs (0xFF)
37 | if (!HTPBsetupIO(HTPB, 0xFF)) {
38 | displayTextLine(4, "ERROR!!");
39 | sleep(2000);
40 | stopAllTasks();
41 | }
42 |
43 | while(true) {
44 | eraseDisplay();
45 | // get the value for ADC channel 0, we want a 10 bit answer
46 | _chVal = HTPBreadADC(HTPB, 0, 10);
47 | displayTextLine(4, "A0: %d", _chVal);
48 |
49 | // if _chVal is more than 512, turn on the LED, otherwise turn it off.
50 | if (_chVal > 512) {
51 | if (!HTPBwriteIO(HTPB, 0xFF)) displayTextLine(5, "ERR WRITE");
52 | } else {
53 | if (!HTPBwriteIO(HTPB, 0x00)) displayTextLine(5, "ERR WRITE");
54 | }
55 | sleep(100);
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/examples/hitechnic-protoboard-test2.c:
--------------------------------------------------------------------------------
1 | #pragma config(Sensor, S1, HTPB, sensorI2CCustom9V)
2 | //*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
3 |
4 | /**
5 | * hitechnic-protoboard.h provides an API for the HiTechnic Protoboard. This program
6 | * demonstrates how to use that API.
7 | *
8 | * Changelog:
9 | * - 0.1: Initial release
10 | * - 0.2: More comments
11 | *
12 | * Credits:
13 | * - Big thanks to HiTechnic for providing me with the hardware necessary to write and test this.
14 | *
15 | * License: You may use this code as you wish, provided you give credit where it's due.
16 | *
17 | * THIS CODE WILL ONLY WORK WITH ROBOTC VERSION 4.10 AND HIGHER
18 |
19 | * Xander Soldaat (xander_at_botbench.com)
20 | * 25 November 2009
21 | * version 0.2
22 | */
23 |
24 | #include "hitechnic-protoboard.h"
25 |
26 | task main() {
27 | byte inputs = 0;
28 |
29 | displayCenteredTextLine(0, "HiTechnic");
30 | displayCenteredBigTextLine(1, "Proto");
31 | displayCenteredTextLine(3, "Test 2");
32 | displayCenteredTextLine(5, "Connect HTPB");
33 | displayCenteredTextLine(6, "to S1");
34 | sleep(2000);
35 |
36 | while(true) {
37 | eraseDisplay();
38 | // Fetch the state of the digital IO pins. When not explicitly
39 | // configured as input or output, they will default to input.
40 | inputs = HTPBreadIO(HTPB, 0x3F);
41 | displayTextLine(4, "D: 0x%x", inputs);
42 | sleep(100);
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/examples/hitechnic-protoboard-test3.c:
--------------------------------------------------------------------------------
1 | #pragma config(Sensor, S1, HTPB, sensorI2CCustom9V)
2 | //*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
3 |
4 | /**
5 | * hitechnic-protoboard.h provides an API for the HiTechnic Protoboard. This program
6 | * demonstrates how to use that API.
7 | *
8 | * Credits:
9 | * - Big thanks to HiTechnic for providing me with the hardware necessary to write and test this.
10 | *
11 | * License: You may use this code as you wish, provided you give credit where it's due.
12 | *
13 | * THIS CODE WILL ONLY WORK WITH ROBOTC VERSION 4.10 AND HIGHER
14 |
15 | * Xander Soldaat (xander_at_botbench.com)
16 | * 16 July 2009
17 | * version 0.1
18 | */
19 |
20 | #include "hitechnic-protoboard.h"
21 |
22 | task main() {
23 | short adch0, adch1, adch2, adch3, adch4 = 0;
24 |
25 | displayCenteredTextLine(0, "HiTechnic");
26 | displayCenteredBigTextLine(1, "Proto");
27 | displayCenteredTextLine(3, "Test 3");
28 | displayCenteredTextLine(5, "Connect HTPB");
29 | displayCenteredTextLine(6, "to S1");
30 | sleep(2000);
31 |
32 | while(true) {
33 | // get the value for ADC channels, we want a 10 bit answer
34 | if (!HTPBreadAllADC(HTPB, adch0, adch1, adch2, adch3, adch4, 10)) {
35 | eraseDisplay();
36 | playSound(soundException);
37 | displayTextLine(5, "ERR READING ADC");
38 | sleep(2000);
39 | stopAllTasks();
40 | }
41 | displayBigTextLine(1, "ADC VALS");
42 | displayTextLine(3, "CH0: %4d", adch0);
43 | displayTextLine(4, "CH1: %4d", adch1);
44 | displayTextLine(5, "CH2: %4d", adch2);
45 | displayTextLine(6, "CH3: %4d", adch3);
46 | displayTextLine(7, "CH4: %4d", adch4);
47 | sleep(100);
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/examples/hitechnic-superpro-exp1.c:
--------------------------------------------------------------------------------
1 | #pragma config(Sensor, S1, HTSPB, sensorI2CCustom9V)
2 | //*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
3 |
4 | /* HiTechnic Experimenter's Kit for the SuperPro
5 |
6 | Experiment - 1 Introduction
7 | Read the status of a switch and display the status on an LED
8 |
9 | */
10 |
11 | #include "hitechnic-superpro.h"
12 |
13 | task main() {
14 | short inputdata;
15 |
16 | // Set B0 for output
17 | HTSPBsetupIO(HTSPB, 0x1);
18 |
19 | while(true) {
20 | // Read a 10bit wide analogue value from A0
21 | inputdata = HTSPBreadADC(HTSPB, 0, 10);
22 | displayTextLine(1, "A0: %d", inputdata);
23 |
24 | // If A0 is less than 50% of the max value
25 | // turn off the LED, otherwise switch it on
26 | if(inputdata < 512)
27 | HTSPBwriteIO(HTSPB, 0x00);
28 | else
29 | HTSPBwriteIO(HTSPB, 0x01);
30 |
31 | sleep(50);
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/examples/hitechnic-superpro-exp2.c:
--------------------------------------------------------------------------------
1 | #pragma config(Sensor, S1, HTSPB, sensorI2CCustom9V)
2 | //*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
3 |
4 | /* HiTechnic Experimenter's Kit for the SuperPro
5 |
6 | Experiment - 2 Six LEDs and a Potentiometer
7 |
8 | This program reads the analog value of a potentiometer and outputs a
9 | digital value to one of six LEDs.
10 |
11 | */
12 |
13 | #include "hitechnic-superpro.h"
14 |
15 | task main() {
16 | short inputdata;
17 | ubyte outputdata;
18 | short bit;
19 |
20 | // Set all digital IOs as outputs as output
21 | HTSPBsetupIO(HTSPB, 0xFF);
22 |
23 | while(true) {
24 | // Read a 10bit wide analogue value from A0
25 | inputdata = HTSPBreadADC(HTSPB, 0, 10);
26 |
27 | displayTextLine(1, "A0: %d", inputdata);
28 |
29 | // Set the output bit based on the analogue input value
30 | bit = (inputdata/128);
31 | if (bit > 5) bit = 5;
32 | displayTextLine(2, "Bit: %d", bit);
33 | outputdata = 1 << bit;
34 | HTSPBwriteIO(HTSPB, outputdata);
35 | sleep(50);
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/examples/hitechnic-superpro-exp3.c:
--------------------------------------------------------------------------------
1 | #pragma config(Sensor, S1, HTSPB, sensorI2CCustom9V)
2 | #pragma config(Sensor, S4, US_PORT, sensorSONAR)
3 | //*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
4 |
5 | /* HiTechnic Experimenter's Kit for the SuperPro
6 |
7 | Experiment - 3 Six LEDs and the Ultrasonic sensor
8 |
9 | This program reads the raw value of the sound sensor and outputs a
10 | digital value to one of six LEDs.
11 |
12 | Port 1 - HiTechnic Prototype Board
13 | Port 4 - Ultrasonic sensor
14 |
15 | */
16 |
17 | #include "hitechnic-superpro.h"
18 |
19 | task main() {
20 | short sonarvalue;
21 | ubyte outputdata;
22 | short bit;
23 |
24 | // The data to be written: 0x3F = 111111 binary,
25 | // makes all digital ports outputs.
26 | HTSPBsetupIO(HTSPB, 0x3F);
27 |
28 | while(true) {
29 | // Get the value from the LEGO sound sensor.
30 | sonarvalue = SensorValue[US_PORT];
31 |
32 | // Set the output bit based on the analogue input value
33 | bit = sonarvalue / 10;
34 | if (bit > 5) bit = 5;
35 | outputdata = 1 << bit;
36 |
37 | eraseDisplay();
38 | displayTextLine(1, "%d", sonarvalue);
39 |
40 | HTSPBwriteIO(HTSPB, outputdata);
41 | sleep(50);
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/examples/hitechnic-superpro-exp4.c:
--------------------------------------------------------------------------------
1 | #pragma config(Sensor, S1, HTSPB, sensorI2CCustom9V)
2 | //*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
3 |
4 | /* HiTechnic Experimenter's Kit for the SuperPro
5 |
6 | Experiment - 4 Light Level sensor
7 |
8 | This program reads the analog value from a photo cell and displays the light level.
9 |
10 | */
11 |
12 | #include "hitechnic-superpro.h"
13 |
14 | task main() {
15 | short inputdata;
16 |
17 | while(true) {
18 | // Read a 10bit wide analogue value from A0
19 | inputdata = HTSPBreadADC(HTSPB, 0, 10);
20 |
21 | eraseDisplay();
22 | displayTextLine(1, "Light: %d", inputdata);
23 |
24 | sleep(50);
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/examples/hitechnic-superpro-exp5.c:
--------------------------------------------------------------------------------
1 | #pragma config(Sensor, S1, HTSPB, sensorI2CCustom9V)
2 | //*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
3 |
4 | /* HiTechnic Experimenter's Kit for the SuperPro
5 |
6 | Experiment 5 - Ambient Canceling Light Sensor
7 |
8 | This program reads the light level with a reference light source on and also off,
9 | calculates the background light level to create an ambient (background) canceling light sensor.
10 |
11 | */
12 |
13 | #include "hitechnic-superpro.h"
14 |
15 | task main() {
16 | short wlight;
17 | short wolight;
18 | short lightdelta;
19 |
20 | // The data to be written: 0x3F = 111111 binary,
21 | // makes all digital ports outputs.
22 | HTSPBsetupIO(HTSPB, 0x3F);
23 |
24 | while(true) {
25 | // Switch off LED on port B0
26 | HTSPBwriteIO(HTSPB, 0x00);
27 | sleep(30);
28 | wolight = HTSPBreadADC(HTSPB, 0, 10);
29 |
30 | // Switch on LED on port B0
31 | HTSPBwriteIO(HTSPB, 0x01);
32 | sleep(30);
33 | wlight = HTSPBreadADC(HTSPB, 0, 10);
34 |
35 | // Calculate the difference
36 | lightdelta = wlight - wolight;
37 |
38 | eraseDisplay();
39 | displayTextLine(1, "L_On : %4d", wlight);
40 | displayTextLine(2, "L_Off: %4d", wolight);
41 | displayTextLine(4, "L_Delta: %4d", lightdelta);
42 | sleep(30);
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/examples/hitechnic-superpro-exp6a.c:
--------------------------------------------------------------------------------
1 | #pragma config(Sensor, S1, HTSPB, sensorI2CCustom9V)
2 | //*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
3 |
4 | /* HiTechnic Experimenter's Kit for the SuperPro
5 |
6 | Experiment - 6 Reaction Time Measurement
7 |
8 | This program measures the time taken to press a button switch after an LED is turned on.
9 |
10 | */
11 |
12 | #include "hitechnic-superpro.h"
13 |
14 | task main() {
15 | // The data to be written: 0x30 = 110000 binary,
16 | // makes B4,B5 digital ports outputs.
17 | HTSPBsetupIO(HTSPB, 0x03);
18 |
19 | while(true) {
20 |
21 | // Turn off the LED
22 | HTSPBwriteIO(HTSPB, 0x00);
23 |
24 | eraseDisplay();
25 | displayTextLine(2, "running");
26 |
27 | // Wait a random time between 3 and 8 seconds.
28 | sleep(random(5000) + 3000);
29 |
30 | // Switch on the LED and reset the timer
31 | HTSPBwriteIO(HTSPB, 0x01);
32 | time1[T1] = 0;
33 |
34 | // Wait for user to press the stop button
35 | while (HTSPBreadIO(HTSPB, 0x30) != 0x10) {
36 | sleep(5);
37 | }
38 |
39 | eraseDisplay();
40 | displayTextLine(2, "Time: %d", time1[T1]);
41 |
42 | // Wait for user to reset
43 | while (HTSPBreadIO(HTSPB, 0x30) != 0x30) {
44 | sleep(5);
45 | }
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/examples/hitechnic-superpro-exp6b.c:
--------------------------------------------------------------------------------
1 | #pragma config(Sensor, S1, HTSPB, sensorI2CCustom9V)
2 | //*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
3 |
4 | /* HiTechnic Experimenter's Kit for the SuperPro
5 |
6 | Experiment - 6 Variation - Complex Reaction Time Measurement
7 |
8 | This program measures the time taken to press a button switch after an LED is turned on.
9 |
10 | */
11 |
12 | #include "hitechnic-superpro.h"
13 |
14 | task main() {
15 | ubyte buttonmask = 0;
16 |
17 | // The data to be written: 0x30 = 110000 binary,
18 | // makes B4,B5 digital ports outputs.
19 | HTSPBsetupIO(HTSPB, 0x03);
20 |
21 | while(true) {
22 | // Turn off all outputs
23 | HTSPBwriteIO(HTSPB, 0x00);
24 |
25 | eraseDisplay();
26 | displayTextLine(2, "running");
27 |
28 | sleep(random(5000) + 3000);
29 |
30 | // Turn on a random LED
31 | if(random(1) > 0) {
32 | HTSPBwriteIO(HTSPB, 0x01);
33 | buttonmask = 0x10;
34 | } else {
35 | HTSPBwriteIO(HTSPB, 0x02);
36 | buttonmask = 0x20;
37 | }
38 |
39 | time1[T1] = 0;
40 |
41 | while (HTSPBreadIO(HTSPB, 0x30) != buttonmask) {
42 | sleep(5);
43 | }
44 |
45 | eraseDisplay();
46 | displayTextLine(2, "Time: %d", time1[T1]);
47 |
48 | while (HTSPBreadIO(HTSPB, 0x30) != 0x30) {
49 | sleep(5);
50 | }
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/examples/hitechnic-superpro-exp7.c:
--------------------------------------------------------------------------------
1 | #pragma config(Sensor, S1, HTSPB, sensorI2CCustom9V)
2 | //*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
3 |
4 | /* HiTechnic Experimenter's Kit for the SuperPro
5 |
6 | Experiment - 7 Magnetic Switch Sensor
7 |
8 | This program measures reads the status of the magnetic sensor and outputs the status.
9 |
10 | */
11 |
12 | #include "hitechnic-superpro.h"
13 |
14 | task main() {
15 | // The data to be written: 0x10 = 010000 binary,
16 | // makes B4 digital port an output.
17 | HTSPBsetupIO(HTSPB, 0x10);
18 |
19 | while(true) {
20 | if(HTSPBreadIO(HTSPB, 0x01) == 0) {
21 | eraseDisplay();
22 | displayTextLine(1, "Magnet present");
23 | HTSPBwriteIO(HTSPB, 0x10);
24 | } else {
25 | eraseDisplay();
26 | displayTextLine(1, "Magnet absent");
27 | HTSPBwriteIO(HTSPB, 0x00);
28 | }
29 | sleep(50);
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/examples/hitechnic-superpro-exp8.c:
--------------------------------------------------------------------------------
1 | #pragma config(Sensor, S1, HTSPB, sensorI2CCustom9V)
2 | //*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
3 |
4 | /* HiTechnic Experimenter's Kit Program
5 |
6 | Experiment - 8 Temperature Sensor
7 |
8 | This program reads the temperature sensor and displays the value.
9 |
10 | */
11 |
12 | #include "hitechnic-superpro.h"
13 |
14 | // This is the temperature at which we switch on the LED
15 | #define THRESHOLD 23
16 |
17 | long temperatureC;
18 | long inputdata;
19 |
20 | task main() {
21 | HTSPBsetupIO(HTSPB, 0x10);
22 |
23 | while(true) {
24 | // Read the value from the temp sensor
25 | inputdata = HTSPBreadADC(HTSPB, 0, 10);
26 |
27 | // Convert to an actual temperature
28 | temperatureC = ((inputdata*3300)/1023-600)/10.0;
29 |
30 | displayTextLine(1, "Temp: %d C", temperatureC);
31 |
32 | // If we're above 28 degrees, switch on the LED
33 | if(temperatureC > THRESHOLD) {
34 | HTSPBwriteIO(HTSPB, 0x10);
35 | } else {
36 | HTSPBwriteIO(HTSPB, 0x00);
37 | }
38 | sleep(50);
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/examples/hitechnic-superpro-exp9.c:
--------------------------------------------------------------------------------
1 | #pragma config(Sensor, S1, HTSPB, sensorI2CCustom9V)
2 | //*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
3 |
4 | /* HiTechnic Experimenter's Kit for the SuperPro
5 |
6 | Experiment - 9 Speaker
7 |
8 | This program first plays a sequence of three ascending
9 | notes using just O0 and then three pairs of descending
10 | notes using both O0 and O1.
11 |
12 | */
13 |
14 | // One octive of note frequencies
15 | #define TONE_C4 262
16 | #define TONE_CS4 277
17 | #define TONE_D4 294
18 | #define TONE_DS4 311
19 | #define TONE_E4 330
20 | #define TONE_F4 349
21 | #define TONE_FS4 370
22 | #define TONE_G4 392
23 | #define TONE_GS4 415
24 | #define TONE_A4 440
25 | #define TONE_AS4 466
26 | #define TONE_B4 494
27 | #define TONE_C5 523
28 |
29 | #include "hitechnic-superpro.h"
30 |
31 | task main() {
32 | HTSPBsetupIO(HTSPB, 0x10);
33 |
34 | HTSPBwriteAnalog(HTSPB, HTSPB_DACO0, DAC_MODE_SQUAREWAVE, TONE_C4, 1023);
35 | sleep(200);
36 | HTSPBwriteAnalog(HTSPB, HTSPB_DACO0, DAC_MODE_SQUAREWAVE, TONE_DS4, 1023);
37 | sleep(400);
38 | HTSPBwriteAnalog(HTSPB, HTSPB_DACO0, DAC_MODE_SQUAREWAVE, TONE_E4, 1023);
39 | sleep(200);
40 | HTSPBwriteAnalog(HTSPB, HTSPB_DACO0, DAC_MODE_SQUAREWAVE, 1, 0);
41 | sleep(200);
42 |
43 | HTSPBwriteAnalog(HTSPB, HTSPB_DACO0, DAC_MODE_SQUAREWAVE, TONE_F4, 1023);
44 | HTSPBwriteAnalog(HTSPB, HTSPB_DACO1, DAC_MODE_SQUAREWAVE, TONE_A4, 1023);
45 | sleep(200);
46 | HTSPBwriteAnalog(HTSPB, HTSPB_DACO0, DAC_MODE_SQUAREWAVE, TONE_E4, 1023);
47 | HTSPBwriteAnalog(HTSPB, HTSPB_DACO1, DAC_MODE_SQUAREWAVE, TONE_G4, 1023);
48 | sleep(200);
49 | HTSPBwriteAnalog(HTSPB, HTSPB_DACO0, DAC_MODE_SQUAREWAVE, TONE_C4, 1023);
50 | HTSPBwriteAnalog(HTSPB, HTSPB_DACO1, DAC_MODE_SQUAREWAVE, TONE_E4, 1023);
51 | sleep(400);
52 | HTSPBwriteAnalog(HTSPB, HTSPB_DACO0, DAC_MODE_SQUAREWAVE, 1, 0);
53 | HTSPBwriteAnalog(HTSPB, HTSPB_DACO1, DAC_MODE_SQUAREWAVE, 1, 0);
54 |
55 | }
56 |
--------------------------------------------------------------------------------
/examples/hitechnic-touchmux-test1.c:
--------------------------------------------------------------------------------
1 | #pragma config(Sensor, S1, HTTMUX, sensorAnalogInactive)
2 | //*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
3 |
4 | /**
5 | * hitechnic-touchmux.h provides an API for the HiTechnic Touch Sensor MUX. This program
6 | * demonstrates how to use that API.
7 | *
8 | * Changelog:
9 | * - 0.1: Initial release
10 | * - 0.2: More comments
11 | *
12 | * Credits:
13 | * - Big thanks to HiTechnic for providing me with the hardware necessary to write and test this.
14 | *
15 | * License: You may use this code as you wish, provided you give credit where it's due.
16 | *
17 | * THIS CODE WILL ONLY WORK WITH ROBOTC VERSION 4.10 AND HIGHER
18 |
19 | * Xander Soldaat (xander_at_botbench.com)
20 | * 25 November 2009
21 | * version 0.2
22 | */
23 |
24 | #include "hitechnic-touchmux.h"
25 |
26 | task main () {
27 | displayCenteredTextLine(0, "HiTechnic");
28 | displayCenteredBigTextLine(1, "TMUX");
29 | displayCenteredTextLine(3, "Test 1");
30 | displayCenteredTextLine(5, "This is for the");
31 | displayCenteredTextLine(6, "Touch MUX");
32 | sleep(2000);
33 |
34 | // Create struct to hold sensor data
35 | tHTTMUX touchMUX;
36 |
37 | // Initialise and configure struct and port
38 | initSensor(&touchMUX, S1);
39 |
40 | while (true) {
41 | eraseDisplay();
42 | displayTextLine(0, "HT Touch MUX");
43 |
44 | // Read the data from the sensor
45 | readSensor(&touchMUX);
46 |
47 | // Go through each possible touch switch attached to the TMUX
48 | // and display whether or not is active (pressed)
49 | for (short i = 0; i < 4; i++) {
50 | if (touchMUX.status[i])
51 | displayTextLine(i+2, "Touch %d: on", i+1);
52 | else
53 | displayTextLine(i+2, "Touch %d: off", i+1);
54 | }
55 |
56 | // Display the binary value of the active touch switches
57 | // 0 = no touch, 1 = touch 1 active, 2 = touch 2 active, etc.
58 | // touch 1 + touch 2 active = 1 + 2 = 3.
59 | displayTextLine(7, "Mask: %d", touchMUX.statusMask);
60 | sleep(50);
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/examples/holitdata-motormux-test2.c:
--------------------------------------------------------------------------------
1 | #pragma config(Sensor, S1, HDMMUX, sensorI2CCustomFastSkipStates)
2 | //*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
3 |
4 | /**
5 | * holitdata-motormux.h provides an API for the Holit Data Systems Motor MUX. This program
6 | * demonstrates how to use that API to control the motors attached to the MUX.
7 | *
8 | * Changelog:
9 | * - 0.1: Initial release
10 | * - 0.2: Removed common.h from list of includes
11 | *
12 | * Credits:
13 | * - Big thanks to Holit Data Systems for providing me with the hardware necessary to write and test this.
14 | *
15 | * License: You may use this code as you wish, provided you give credit where it's due.
16 | *
17 | * THIS CODE WILL ONLY WORK WITH ROBOTC VERSION 4.10 AND HIGHER
18 |
19 | * Xander Soldaat (xander_at_botbench.com)
20 | * 14 February 2011
21 | * version 0.2
22 | */
23 |
24 | #include "holitdata-motormux.h"
25 |
26 | task main () {
27 | long encA = 0;
28 | long encB = 0;
29 | long encC = 0;
30 |
31 | long timer = 0;
32 |
33 | ubyte motorStatus = 0;
34 | string motorAstatus;
35 | bool done = false;
36 |
37 | eraseDisplay();
38 |
39 | // Initialise all the internal variables
40 | HDMMUXinit();
41 |
42 | // Reset the encoders. This can be done individually or all at once.
43 | // You should do this at the start of your program.
44 | HDMMotorEncoderResetAll(HDMMUX);
45 |
46 | // You can specify the type of braking that should be used when the motors
47 | // are sent the stop command. The default is to use brake.
48 | HDMMotorSetBrake(mmotor_S1_1);
49 |
50 | // Specify a motor 1 to run for 2.5 seconds.
51 | HDMMotorSetTimeTarget(mmotor_S1_1, 2.50);
52 |
53 | // Tell the motors to start moving.
54 | HDMMotor(mmotor_S1_1, 50);
55 |
56 | // Reset the timer
57 | time1[T1] = 0;
58 | // Give the motor time to get started
59 | sleep(50);
60 | while (!done) {
61 | // Retrieve the motor-MUX's status info and encoder counts
62 | HDMMUXreadStatus(HDMMUX, motorStatus, encA, encB, encC);
63 |
64 | // Use the HDMMotorBusy() function to see if a motor is busy or idle.
65 | motorAstatus = HDMMotorBusy(mmotor_S1_1) ? "busy" : "idle";
66 | if (!HDMMotorBusy(mmotor_S1_1) && timer == 0) {
67 | timer = time1[T1];
68 | displayTextLine(0,"Time: %dms", timer);
69 | done = true;
70 | }
71 |
72 | // Display the info.
73 | displayTextLine(6, "B: %5d (%s)", encB, motorAstatus);
74 | sleep(1);
75 | }
76 | sleep(5000);
77 | }
78 |
--------------------------------------------------------------------------------
/examples/lego-energymeter-test1.c:
--------------------------------------------------------------------------------
1 | #pragma config(Sensor, S1, LEGOEM, sensorI2CCustom)
2 | //*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
3 |
4 | /**
5 | * lego-energymeter.h provides an API for the Lego Energy Meter. This program
6 | * demonstrates how to use that API to use the sensor in continuous mode.
7 | *
8 | * Changelog:
9 | * - 0.1: Initial release
10 | *
11 | * Credits :
12 | * - Cosimano for sending me one of these.
13 | * - John Hansen for providing me with the specs.
14 | *
15 | * License: You may use this code as you wish, provided you give credit where it's due.
16 | *
17 | * THIS CODE WILL ONLY WORK WITH ROBOTC VERSION 4.10 AND HIGHER
18 |
19 | * Xander Soldaat (xander_at_botbench.com)
20 | * 22 August 2010
21 | * version 0.1
22 | */
23 |
24 | #include "lego-energymeter.h"
25 |
26 | task main() {
27 |
28 | short _joule;
29 | float _voltageIn;
30 | float _currentIn;
31 | float _voltageOut;
32 | float _currentOut;
33 | float _wattIn;
34 | float _wattOut;
35 |
36 | displayCenteredTextLine(0, "LEGO");
37 | displayCenteredBigTextLine(1, "Energy");
38 | displayCenteredTextLine(3, "Test 1");
39 | displayCenteredTextLine(5, "Connect sensor");
40 | displayCenteredTextLine(6, "to S1");
41 | sleep(2000);
42 | eraseDisplay();
43 |
44 | drawLine(0, 27, 99, 27);
45 | drawLine(0, 52, 99, 52);
46 |
47 | while (true) {
48 | //eraseDisplay();
49 | LEGOEMreadData(LEGOEM, _voltageIn, _currentIn, _voltageOut, _currentOut, _joule, _wattIn, _wattOut);
50 | displayCenteredTextLine(0, "Energy Meter");
51 | displayTextLine(2, "In: %2.1fV|%2.3fA", _voltageIn, _currentIn);
52 | displayTextLine(3, "Out: %2.1fV|%2.3fA", _voltageOut, _currentOut);
53 | displayTextLine(5, "Pwr in: %2.3fW", _wattIn);
54 | displayTextLine(6, "Pwr out: %2.3fW", _wattOut);
55 | displayTextLine(7, "Energy: %3dJ", _joule);
56 | sleep(100);
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/examples/lego-light-SMUX-test1.c:
--------------------------------------------------------------------------------
1 | #pragma config(Sensor, S1, HTSMUX, sensorI2CCustom)
2 | //*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
3 |
4 | /**
5 | * lego-light.h provides an API for the Lego Light Sensor. This program
6 | * demonstrates how to use that API through a SMUX.
7 | *
8 | * Changelog:
9 | * - 0.1: Initial release
10 | * - 0.2: More comments
11 | *
12 | * License: You may use this code as you wish, provided you give credit where it's due.
13 | *
14 | * THIS CODE WILL ONLY WORK WITH ROBOTC VERSION 4.10 AND HIGHER
15 |
16 | * Xander Soldaat (xander_at_botbench.com)
17 | * 25 November 2009
18 | * version 0.2
19 | */
20 |
21 | #include "hitechnic-sensormux.h"
22 | #include "lego-light.h"
23 |
24 | // The sensor is connected to the first port
25 | // of the SMUX which is connected to the NXT port S1.
26 | // To access that sensor, we must use msensor_S1_1. If the sensor
27 | // were connected to 3rd port of the SMUX connected to the NXT port S4,
28 | // we would use msensor_S4_3
29 |
30 | // Give the sensor a nice easy to use name
31 | const tMUXSensor LEGOLS = msensor_S1_1;
32 |
33 | task main() {
34 | short raw = 0;
35 | short nrm = 0;
36 | bool active = true;
37 |
38 | // Turn the light on
39 | LSsetActive(LEGOLS);
40 |
41 | displayCenteredTextLine(0, "Lego");
42 | displayCenteredBigTextLine(1, "LIGHT");
43 | displayCenteredTextLine(3, "SMUX Test");
44 | displayCenteredTextLine(5, "Connect SMUX to");
45 | displayCenteredTextLine(6, "S1 and sensor to");
46 | displayCenteredTextLine(7, "SMUX Port 1");
47 | sleep(2000);
48 |
49 | displayClearTextLine(7);
50 | displayTextLine(5, "Press [enter]");
51 | displayTextLine(6, "to toggle light");
52 | sleep(2000);
53 |
54 | while (true) {
55 | // The enter button has been pressed, switch
56 | // to the other mode
57 | if (getXbuttonValue(xButtonEnter))
58 | {
59 | active = !active;
60 | if (!active)
61 | LSsetInactive(LEGOLS);
62 | else
63 | LSsetActive(LEGOLS);
64 |
65 | // wait 500ms to debounce the switch
66 | sleep(500);
67 | }
68 |
69 | displayClearTextLine(5);
70 | displayClearTextLine(6);
71 | raw = LSvalRaw(LEGOLS);
72 | nrm = LSvalNorm(LEGOLS);
73 | displayTextLine(5, "Raw: %4d", raw);
74 | displayTextLine(6, "Norm: %4d", nrm);
75 | sleep(50);
76 | }
77 | }
78 |
--------------------------------------------------------------------------------
/examples/lego-light-test1.c:
--------------------------------------------------------------------------------
1 | #pragma config(Sensor, S1, LEGOLS, sensorLightInactive)
2 | //*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
3 |
4 | /**
5 | * lego-light.h provides an API for the Lego Light Sensor. This program
6 | * demonstrates how to use that API.
7 | *
8 | * Changelog:
9 | * - 0.1: Initial release
10 | * - 0.2: More comments
11 | *
12 | * License: You may use this code as you wish, provided you give credit where it's due.
13 | *
14 | * THIS CODE WILL ONLY WORK WITH ROBOTC VERSION 4.10 AND HIGHER
15 |
16 | * Xander Soldaat (xander_at_botbench.com)
17 | * 25 November 2009
18 | * version 0.2
19 | */
20 | #include "lego-light.h"
21 |
22 | task main() {
23 | short raw = 0;
24 | short nrm = 0;
25 | bool active = true;
26 | LSsetActive(LEGOLS);
27 |
28 | nNxtButtonTask = -2;
29 |
30 | eraseDisplay();
31 | displayTextLine(0, "Light Sensor");
32 | displayTextLine(2, "Press orange");
33 | displayTextLine(3, "button to switch");
34 |
35 | while (true) {
36 | // The enter button has been pressed, switch
37 | // to the other mode
38 | if (nNxtButtonPressed == kEnterButton) {
39 | active = !active;
40 | if (!active)
41 | // Turn the light off
42 | LSsetInactive(LEGOLS);
43 | else
44 | // Turn the light on
45 | LSsetActive(LEGOLS);
46 |
47 | // wait 500ms to debounce the switch
48 | sleep(500);
49 | }
50 |
51 | displayClearTextLine(5);
52 | displayClearTextLine(6);
53 |
54 | // Get the raw value from the sensor
55 | raw = LSvalRaw(LEGOLS);
56 |
57 | // Get the normalised value from the sensor
58 | nrm = LSvalNorm(LEGOLS);
59 |
60 | displayTextLine(5, "Raw: %4d", raw);
61 | displayTextLine(6, "Norm: %4d", nrm);
62 | sleep(50);
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/examples/lego-light-test2.c:
--------------------------------------------------------------------------------
1 | #pragma config(Sensor, S3, LEGOLS, sensorLightInactive)
2 | //*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
3 |
4 | /**
5 | * lego-light.h provides an API for the Lego Light Sensor. This program
6 | * demonstrates how to use that API to calibrate the sensor.
7 | *
8 | * Changelog:
9 | * - 0.1: Initial release
10 | * - 0.2: More comments
11 | *
12 | * License: You may use this code as you wish, provided you give credit where it's due.
13 | *
14 | * THIS CODE WILL ONLY WORK WITH ROBOTC VERSION 4.10 AND HIGHER
15 |
16 | * Xander Soldaat (xander_at_botbench.com)
17 | * 25 November 2009
18 | * version 0.2
19 | */
20 |
21 | #include "lego-light.h"
22 |
23 | task main () {
24 | short raw = 0;
25 | short nrm = 0;
26 | // Get control over the buttons
27 | nNxtButtonTask = -2;
28 |
29 | LSsetActive(LEGOLS);
30 | eraseDisplay();
31 | displayTextLine(0, "Light Sensor Cal.");
32 | displayTextLine(2, "Left: set black");
33 | displayTextLine(3, "Right: set white");
34 | displayTextLine(7, "Grey: exit");
35 |
36 | while (true) {
37 | switch(nNxtButtonPressed) {
38 | // if the left button is pressed calibrate the black value for the sensor
39 | case kLeftButton:
40 | LScalLow(LEGOLS);
41 | playSound(soundBeepBeep);
42 | while(bSoundActive) sleep(1);
43 | break;
44 |
45 | // if the left button is pressed calibrate the white value for the sensor
46 | case kRightButton:
47 | LScalHigh(LEGOLS);
48 | playSound(soundBeepBeep);
49 | while(bSoundActive) sleep(1);
50 | break;
51 | }
52 |
53 | displayClearTextLine(5);
54 | displayClearTextLine(6);
55 |
56 | // Read the raw value of the sensor
57 | raw = LSvalRaw(LEGOLS);
58 |
59 | // Read the normalised value of the sensor
60 | nrm = LSvalNorm(LEGOLS);
61 |
62 | // Display the raw and normalised values
63 | displayTextLine(5, "R: %4d N: %4d", raw, nrm);
64 |
65 | // Display the values for black and white
66 | displayTextLine(6, "B: %4d W: %4d", lslow[LEGOLS * 4], lshigh[LEGOLS * 4]);
67 | sleep(50);
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/examples/lego-touch-SMUX-test1.c:
--------------------------------------------------------------------------------
1 | #pragma config(Sensor, S1, HTSMUX, sensorI2CCustom)
2 | //*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
3 |
4 | /**
5 | * lego-touch.h provides an API for the Lego Touch Sensor. This program
6 | * demonstrates how to use that API through a SMUX.
7 | *
8 | * Changelog:
9 | * - 0.1: Initial release
10 | *
11 | * License: You may use this code as you wish, provided you give credit where it's due.
12 | *
13 | * THIS CODE WILL ONLY WORK WITH ROBOTC VERSION 4.10 AND HIGHER
14 |
15 | * Xander Soldaat (xander_at_botbench.com)
16 | * 08 December 2009
17 | * version 0.1
18 | */
19 |
20 | #include "hitechnic-sensormux.h"
21 | #include "lego-touch.h"
22 |
23 | // The sensor is connected to the first port
24 | // of the SMUX which is connected to the NXT port S1.
25 | // To access that sensor, we must use msensor_S1_1. If the sensor
26 | // were connected to 3rd port of the SMUX connected to the NXT port S4,
27 | // we would use msensor_S4_3
28 |
29 | // Give the sensor a nice easy to use name
30 | const tMUXSensor LEGOTOUCH = msensor_S1_1;
31 |
32 | task main() {
33 | displayCenteredTextLine(0, "Lego");
34 | displayCenteredBigTextLine(1, "TOUCH");
35 | displayCenteredTextLine(3, "SMUX Test");
36 | displayCenteredTextLine(5, "Connect SMUX to");
37 | displayCenteredTextLine(6, "S1 and sensor to");
38 | displayCenteredTextLine(7, "SMUX Port 1");
39 | sleep(2000);
40 |
41 | eraseDisplay();
42 |
43 | while (true) {
44 | // Check if the sensor is pressed or not.
45 | if (TSreadState(LEGOTOUCH))
46 | displayCenteredBigTextLine(3, "ACTIVE");
47 | else
48 | displayCenteredBigTextLine(3, "INACTIVE");
49 | sleep(50);
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/examples/lego-touch-test1.c:
--------------------------------------------------------------------------------
1 | #pragma config(Sensor, S1, LEGOTS, sensorAnalogInactive)
2 | //*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
3 |
4 | /**
5 | * LEGOLS-driver.h provides an API for the Lego Light Sensor. This program
6 | * demonstrates how to use that API.
7 | *
8 | * Changelog:
9 | * - 0.1: Initial release
10 | * - 0.2: More comments
11 | *
12 | * License: You may use this code as you wish, provided you give credit where it's due.
13 | *
14 | * THIS CODE WILL ONLY WORK WITH ROBOTC VERSION 4.10 AND HIGHER
15 |
16 | * Xander Soldaat (xander_at_botbench.com)
17 | * 25 November 2009
18 | * version 0.2
19 | */
20 |
21 | #include "lego-touch.h"
22 |
23 | task main() {
24 | displayCenteredTextLine(0, "Lego");
25 | displayCenteredBigTextLine(1, "TOUCH");
26 | displayCenteredTextLine(3, "Test 1");
27 | displayCenteredTextLine(5, "Connect sensor");
28 | displayCenteredTextLine(6, "to S1");
29 | sleep(2000);
30 |
31 | eraseDisplay();
32 |
33 | while (true) {
34 | if (TSreadState(LEGOTS))
35 | displayCenteredBigTextLine(3, "ACTIVE");
36 | else
37 | displayCenteredBigTextLine(3, "INACTIVE");
38 | sleep(50);
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/examples/lego-ultrasound-SMUX-test1.c:
--------------------------------------------------------------------------------
1 | #pragma config(Sensor, S1, HTSMUX, sensorLowSpeed)
2 | //*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
3 |
4 | /**
5 | * lego-ultrasound.h provides an API for the Lego US sensor. This program
6 | * demonstrates how to use that API.
7 | *
8 | * Changelog:
9 | * - 0.1: Initial release
10 | * - 0.2: More comments
11 | *
12 | * License: You may use this code as you wish, provided you give credit where it's due.
13 | *
14 | * THIS CODE WILL ONLY WORK WITH ROBOTC VERSION 4.10 AND HIGHER
15 |
16 | * Xander Soldaat (xander_at_botbench.com)
17 | * 25 November 2009
18 | * version 0.2
19 | */
20 |
21 | #include "hitechnic-sensormux.h"
22 | #include "lego-ultrasound.h"
23 |
24 | // The sensor is connected to the first port
25 | // of the SMUX which is connected to the NXT port S1.
26 | // To access that sensor, we must use msensor_S1_1. If the sensor
27 | // were connected to 3rd port of the SMUX connected to the NXT port S4,
28 | // we would use msensor_S4_3
29 |
30 | // Give the sensor a nice easy to use name
31 | const tMUXSensor LEGOUS = msensor_S1_1;
32 |
33 | task main () {
34 | short dist = 0;
35 |
36 | displayCenteredTextLine(0, "Lego");
37 | displayCenteredBigTextLine(1, "US");
38 | displayCenteredTextLine(3, "SMUX Test");
39 | displayCenteredTextLine(5, "Connect SMUX to");
40 | displayCenteredTextLine(6, "S1 and US sensor");
41 | displayCenteredTextLine(7, "to SMUX Port 1");
42 | sleep(2000);
43 |
44 | eraseDisplay();
45 | displayTextLine(0, "Lego US Sensor");
46 |
47 | while(true) {
48 | // Read the current distance detected.
49 | dist = USreadDist(LEGOUS);
50 |
51 | // display the info from the sensor
52 | displayTextLine(3, "Dist: %3d cm", dist);
53 | sleep(50);
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/examples/mainpage.h:
--------------------------------------------------------------------------------
1 |
2 |
3 | /** \mainpage ROBOTC Driver Suite
4 | *
5 | * \author Xander Soldaat
6 | *
7 | * \section intro Introduction
8 | * The aim of this project is to create an easy to use suite of drivers for ROBOTC.
9 | * ROBOTC supports many of the devices listed below. However, these built-in drivers
10 | * are often limited to a subset of the functionality that some of these sensors have
11 | * to offer. The drivers in this suite give you access to all of this functionality.
12 | * Care has been taken to document the use of these functions.
13 | *
14 | * For (almost) every driver there is at least one example file that shows you how to
15 | * use the API for that particular driver.
16 | *
17 | * Use the links on the left to navigate between the various drivers and test programs.
18 | *
19 | */
20 |
21 | /*! @defgroup common_includes Common functions
22 | Functions used by some or most drivers.
23 | */
24 |
25 | /*! @defgroup Dexter_Industries Dexter Industries
26 | Drivers for the Dexter Industries sensors.
27 | */
28 |
29 | /*! \defgroup HiTechnic HiTechnic
30 | Drivers for the HiTechnic sensors.
31 | */
32 |
33 | /*! \defgroup mindsensors Mindsensors
34 | Drivers for the Mindsensors sensors.
35 | */
36 |
37 | /*! \defgroup lego Lego
38 | Drivers for Lego sensors.
39 | */
40 |
41 | /*! \defgroup other Other
42 | Drivers for other sensors.
43 | */
44 |
--------------------------------------------------------------------------------
/examples/math-matrix-test1.c:
--------------------------------------------------------------------------------
1 | //*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
2 |
3 | /**
4 | * matrix-float .h provides an API for the some simple Matrix operations.
5 | *
6 | * Changelog:
7 | * - 0.1: Initial release
8 | *
9 | * Credits:
10 | * - Charlie Matlack for writing the Arduino version of this. I merely ported it to
11 | * ROBOTC and tweaked a few things.
12 | *
13 | * License: You may use this code as you wish, provided you give credit where it's due.
14 | *
15 | * THIS CODE WILL ONLY WORK WITH ROBOTC VERSION 4.10 AND HIGHER
16 |
17 | * Xander Soldaat (xander_at_botbench.com)
18 | * 03 March 2013
19 | * version 0.1
20 | */
21 |
22 | #include "math-matrix.h"
23 |
24 | task main ()
25 | {
26 | float one[2][2] = {{2.7, 2.1}, {1.1, 1.6}};
27 | float two[2][2] = {{12.1, 11.9}, {21, 82.1}};
28 | float three[2][2];
29 |
30 | long four[3][3] = {{1, 3, 3},
31 | {1, 4, 3},
32 | {1, 3, 4}};
33 |
34 | long five[3][3] = {{2, 1, 7},
35 | {3, 4, 1},
36 | {4, 2, 1}};
37 |
38 | long six[3][3];
39 |
40 | matrixPrintF(one, 2, 2, "one");
41 | matrixMultF(one, two, 2, 2, 2, three);
42 | matrixPrintF(three, 2, 2, "three");
43 | matrixCopyF(one, 2, 2, two);
44 | matrixPrintF(one, 2, 2, "one");
45 | matrixPrintF(two, 2, 2, "two");
46 |
47 | matrixAddL(four, five, 3, 3, six);
48 | matrixPrintL(six, 3, 3, "six");
49 |
50 | }
51 |
--------------------------------------------------------------------------------
/examples/microinfinity-cruizcore-test1.c:
--------------------------------------------------------------------------------
1 | #pragma config(Sensor, S1, MICC, sensorI2CCustom)
2 | //*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
3 |
4 | /**
5 | * microinfinity-cruizcore.h provides an API for the MicroInfinity CruizCore XG1300L sensor.
6 | * This program demonstrates how to use that API.
7 | *
8 | * Changelog:
9 | * - 0.1: Initial release
10 | *
11 | * Credits:
12 | * - Big thanks to MicroInfinity for providing me with the hardware necessary to write and test this.
13 | *
14 | * License: You may use this code as you wish, provided you give credit where it's due.
15 | *
16 | * THIS CODE WILL ONLY WORK WITH ROBOTC VERSION 4.10 AND HIGHER
17 |
18 | * Xander Soldaat (xander_at_botbench.com)
19 | * 29 May 2011
20 | * version 0.1
21 | */
22 |
23 | #include "microinfinity-cruizcore.h"
24 |
25 | task main () {
26 | short _x_accel = 0;
27 | short _y_accel = 0;
28 | short _z_accel = 0;
29 |
30 | short angleI = 0;
31 | float angleF = 0.0;
32 |
33 | short rotI = 0;
34 | float rotF = 0.0;
35 |
36 | displayCenteredTextLine(0, "MicroInfinity");
37 | displayTextLine(1, "CruizCore XG1300L");
38 | displayCenteredTextLine(3, "Test 1");
39 | sleep(2000);
40 | eraseDisplay();
41 |
42 | // There are 3 ranges the Cruizcore XG1300L can measure in
43 | // up to 2G
44 | // up to 4G
45 | // up to 8G
46 | MICCsetRange8G(MICC);
47 |
48 | // Make sure you always reset the sensor at the beginning of your program
49 | // The robot needs to be completely stationary or your heading and gyro
50 | // data won't be accurate.
51 | MICCreset(MICC);
52 |
53 | while(bSoundActive) sleep(1);
54 |
55 | displayTextLine(0, "CruizCore XG1300L");
56 | while (true) {
57 | // Read the relative heading from the sensor.
58 | angleI = MICCreadRelativeHeading(MICC);
59 | angleF = angleI / 100.0;
60 |
61 | // Read the rate of turn
62 | rotI = MICCreadTurnRate(MICC);
63 | rotF = rotI / 100.0;
64 |
65 | // Read the acceleration data from the sensor
66 | if (!MICCreadAccel(MICC, _x_accel, _y_accel, _z_accel)) {
67 | displayTextLine(4, "ERROR!!");
68 | sleep(2000);
69 | stopAllTasks();
70 | }
71 |
72 | displayTextLine(2, "Heading: %4.2f", angleF);
73 | displayTextLine(3, "RoT: %4.2f", rotF);
74 | displayTextLine(5, "X: %5.2f", _x_accel/100.0);
75 | displayTextLine(6, "Y: %5.2f", _y_accel/100.0);
76 | displayTextLine(7, "Z: %5.2f", _z_accel/100.0);
77 | sleep(50);
78 | }
79 | }
80 |
--------------------------------------------------------------------------------
/examples/mindensors-servo-test1.c:
--------------------------------------------------------------------------------
1 | #pragma config(Sensor, S1, NXTSERVO, sensorI2CCustom)
2 | //*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
3 |
4 | /**
5 | * mindensors-servo.h provides an API for the Mindsensors NXTServo Sensor. This program
6 | * demonstrates how to use that API.
7 | *
8 | * Changelog:
9 | * - 0.1: Initial release
10 | * - 0.2: More comments
11 | *
12 | * Credits:
13 | * - Big thanks to Mindsensors for providing me with the hardware necessary to write and test this.
14 | *
15 | * License: You may use this code as you wish, provided you give credit where it's due.
16 | *
17 | * THIS CODE WILL ONLY WORK WITH ROBOTC VERSION 4.10 AND HIGHER
18 |
19 | * Xander Soldaat (xander_at_botbench.com)
20 | * 28 November 2009
21 | * version 0.2
22 | */
23 |
24 | #include "mindensors-servo.h"
25 |
26 | task main () {
27 | short voltage = 0;
28 |
29 | displayCenteredTextLine(0, "Mindsensors");
30 | displayCenteredBigTextLine(1, "NXTServo");
31 | displayCenteredTextLine(3, "Demo prog");
32 | displayCenteredTextLine(5, "Connect NXServo");
33 | displayCenteredTextLine(6, "to S1 and servo");
34 | displayCenteredTextLine(7, "to connector 1");
35 | sleep(2000);
36 |
37 | eraseDisplay();
38 | while (true) {
39 |
40 | // read the current voltage of the power supply for the
41 | // sevos
42 | voltage = NXTServoReadVoltage(NXTSERVO);
43 | displayCenteredBigTextLine(1, "%dmV", voltage);
44 |
45 | // Move the servo to position "500" with max speed (0)
46 | NXTServoSetPos(NXTSERVO, 1, 500, 0);
47 | sleep(1000);
48 |
49 | // Move the servo to position "2500" with speed 30
50 | NXTServoSetPos(NXTSERVO, 1, 2500, 30);
51 |
52 | sleep(1000);
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/examples/mindsensors-accelerometer-test1.c:
--------------------------------------------------------------------------------
1 | #pragma config(Sensor, S1, MSAC, sensorI2CCustom)
2 | //*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
3 |
4 | /**
5 | * mindsensors-accelerometer.h provides an API for the Mindsensors Acceleration Sensor. This program
6 | * demonstrates how to use that API.
7 | *
8 | * Changelog:
9 | * - 0.1: Initial release
10 | * - 0.2: More comments
11 | * Make use of the new range defines
12 | *
13 | * Credits:
14 | * - Big thanks to Mindsensors for providing me with the hardware necessary to write and test this.
15 | *
16 | * License: You may use this code as you wish, provided you give credit where it's due.
17 | *
18 | * THIS CODE WILL ONLY WORK WITH ROBOTC VERSION 4.10 AND HIGHER
19 |
20 | * Xander Soldaat (xander_at_botbench.com)
21 | * 28 November 2009
22 | * version 0.2
23 | */
24 |
25 | #include "mindsensors-accelerometer.h"
26 |
27 | task main () {
28 | short _x_accel = 0;
29 | short _y_accel = 0;
30 | short _z_accel = 0;
31 |
32 | short _x_tilt = 0;
33 | short _y_tilt = 0;
34 | short _z_tilt = 0;
35 |
36 | string _tmp;
37 |
38 | displayCenteredTextLine(0, "Mindsensors");
39 | displayCenteredBigTextLine(1, "ACCEL-Nx");
40 | displayCenteredTextLine(3, "Test 1");
41 | sleep(2000);
42 |
43 | // There are four ranges the ACCL-Nx can measure in
44 | // up to 2.5G - MSAC_RANGE_2_5
45 | // up to 3.3G - MSAC_RANGE_3_3
46 | // up to 6.7G - MSAC_RANGE_6_7
47 | // up to 10G - MSAC_RANGE_10
48 | MSACsetRange(MSAC, MSAC_RANGE_10);
49 |
50 | playSound(soundBeepBeep);
51 | while(bSoundActive) sleep(1);
52 |
53 | while (true) {
54 | eraseDisplay();
55 |
56 | // Read the tilt data from the sensor
57 | if (!MSACreadTilt(MSAC, _x_tilt, _y_tilt, _z_tilt)) {
58 | displayTextLine(4, "ERROR!!");
59 | sleep(2000);
60 | stopAllTasks();
61 | }
62 |
63 | // Read the acceleration data from the sensor
64 | if (!MSACreadAccel(MSAC, _x_accel, _y_accel, _z_accel)) {
65 | displayTextLine(4, "ERROR!!");
66 | sleep(2000);
67 | stopAllTasks();
68 | }
69 |
70 | displayTextLine(0,"MSAC Test 1");
71 |
72 | // We can't provide more than 2 parameters to displayTextLine(),
73 | // so we'll do in two steps using stringFormat()
74 | displayTextLine(2, "Tilt X Y Z");
75 | stringFormat(_tmp, " %4d %4d", _x_tilt, _y_tilt);
76 | displayTextLine(3, "%s %4d", _tmp, _z_tilt);
77 |
78 | displayTextLine(4, "Acceleration:");
79 | displayTextLine(5, "X: %5d mG", _x_accel);
80 | displayTextLine(6, "Y: %5d mG", _y_accel);
81 | displayTextLine(7, "Z: %5d mG", _z_accel);
82 | sleep(100);
83 | }
84 | }
85 |
--------------------------------------------------------------------------------
/examples/mindsensors-accelerometer-test2.c:
--------------------------------------------------------------------------------
1 | #pragma config(Sensor, S1, MSAC, sensorI2CCustom)
2 | //*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
3 |
4 | /**
5 | * mindsensors-accelerometer.h provides an API for the Mindsensors Acceleration Sensor. This program
6 | * demonstrates how to use that API.
7 | *
8 | * Changelog:
9 | * - 0.1: Initial release
10 | * - 0.2: More comments
11 | * Make use of the new range defines
12 | *
13 | * Credits:
14 | * - Big thanks to Mindsensors for providing me with the hardware necessary to write and test this.
15 | *
16 | * License: You may use this code as you wish, provided you give credit where it's due.
17 | *
18 | * THIS CODE WILL ONLY WORK WITH ROBOTC VERSION 4.10 AND HIGHER
19 |
20 | * Xander Soldaat (xander_at_botbench.com)
21 | * 28 November 2009
22 | * version 0.2
23 | */
24 |
25 | #include "mindsensors-accelerometer.h"
26 |
27 | task main () {
28 | short _x_tilt = 0;
29 | short _y_tilt = 0;
30 | short _z_tilt = 0;
31 |
32 | short tone1;
33 | short tone2;
34 | short waitTime;
35 |
36 | displayCenteredTextLine(0, "Mindsensors");
37 | displayCenteredBigTextLine(1, "ACCEL-Nx");
38 | displayCenteredTextLine(3, "Test 2");
39 | sleep(2000);
40 |
41 | // There are four ranges the ACCL-Nx can measure in
42 | // up to 2.5G - MSAC_RANGE_2_5
43 | // up to 3.3G - MSAC_RANGE_3_3
44 | // up to 6.7G - MSAC_RANGE_6_7
45 | // up to 10G - MSAC_RANGE_10
46 | MSACsetRange(MSAC, MSAC_RANGE_10);
47 |
48 | playSound(soundBeepBeep);
49 | while(bSoundActive) sleep(1);
50 |
51 | while (true) {
52 | // Read the tilt data from the sensor
53 | if (!MSACreadTilt(MSAC, _x_tilt, _y_tilt, _z_tilt)) {
54 | displayTextLine(4, "ERROR!!");
55 | sleep(2000);
56 | stopAllTasks();
57 | }
58 |
59 | // Tilt values seem to go from about -20 to +20.
60 | // Adding 20 to them makes them go from 0 to 40.
61 |
62 | // Make sure the tones are at least 0Hz
63 | tone1 = max2(0, (_x_tilt + 20) * 20);
64 | tone2 = max2(0, (_z_tilt + 20) * 25);
65 |
66 | // Make sure the wait time is at least 10ms
67 | waitTime = max2(10, (_y_tilt + 20));
68 |
69 | playImmediateTone(tone1, 5);
70 | sleep(waitTime);
71 | playImmediateTone(tone2, 1);
72 | }
73 | }
74 |
--------------------------------------------------------------------------------
/examples/mindsensors-angle-test1.c:
--------------------------------------------------------------------------------
1 | #pragma config(Sensor, S1, MSANG, sensorI2CCustom)
2 | //*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
3 |
4 | /**
5 | * mindsensors-angle.h provides an API for the Mindsensors Angle Sensor. This program
6 | * demonstrates how to use that API.
7 | *
8 | * Changelog:
9 | * - 0.1: Initial release
10 | *
11 | * Credits:
12 | * - Big thanks to Mindsensors for providing me with the hardware necessary to write and test this.
13 | *
14 | * License: You may use this code as you wish, provided you give credit where it's due.
15 | *
16 | * THIS CODE WILL ONLY WORK WITH ROBOTC VERSION 4.10 AND HIGHER
17 |
18 | * Xander Soldaat (xander_at_botbench.com)
19 | * date 31 November 2012
20 | * version 0.1
21 | */
22 |
23 | #include "mindsensors-angle.h"
24 |
25 | task main () {
26 | nNxtButtonTask = -2;
27 | displayCenteredTextLine(0, "Mindsensors");
28 | displayCenteredBigTextLine(1, "Angle");
29 | displayCenteredTextLine(3, "Test 1");
30 | displayCenteredTextLine(5, "Connect sensor");
31 | displayCenteredTextLine(6, "to S1");
32 | sleep(2000);
33 |
34 | eraseDisplay();
35 | displayCenteredTextLine(0, "GlideWheel-AS");
36 | displayTextLine(1, "-------------------");
37 | displayTextLine(5, "-------------------");
38 | while (true) {
39 | // Reset the angle to 0
40 | if (nNxtButtonPressed == kEnterButton)
41 | {
42 | MSANGresetAngle(MSANG);
43 | while (nNxtButtonPressed != kNoButton) sleep(1);
44 | }
45 |
46 | // Read the current angle, accumulated angle and RPM and display them
47 | displayTextLine(2, "Ang: %7d deg", MSANGreadAngle(MSANG));
48 | displayTextLine(3, "Raw: %7d", MSANGreadRaw(MSANG));
49 | displayTextLine(4, "RPM: %7d", MSANGreadRPM(MSANG));
50 | displayTextLine(7, " Reset angle");
51 | sleep(50);
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/examples/mindsensors-ev3-grove-test1.c:
--------------------------------------------------------------------------------
1 | #pragma config(Sensor, S1, GROVE, sensorEV3_GenericI2C)
2 | //*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
3 |
4 | /**
5 | * mindsensors-ev3-grove.h provides an API for the Mindsensors EV3-Grove Sensor. This program
6 | * demonstrates how to use that API.
7 | *
8 | * Changelog:
9 | * - 0.1: Initial release
10 | *
11 | * Credits:
12 | * - Big thanks to Mindsensors for providing me with the hardware necessary to write and test this.
13 | *
14 | * License: You may use this code as you wish, provided you give credit where it's due.
15 | *
16 | * THIS CODE WILL ONLY WORK WITH ROBOTC VERSION 4.29 AND HIGHER
17 |
18 | * Xander Soldaat (xander_at_botbench.com)
19 | */
20 |
21 | #include "mindsensors-ev3-grove.h"
22 |
23 |
24 |
25 | // main task
26 | task main ()
27 | {
28 | displayCenteredTextLine(0, "Mindsensors");
29 | displayCenteredBigTextLine(1, "EV3-Grove");
30 | displayCenteredTextLine(3, "Test 1");
31 | sleep(2000);
32 |
33 | // Create struct to hold sensor data
34 | tGROVE groveSensor;
35 |
36 | // Initialise and configure struct, port and sensor type
37 | if (!initSensor(&groveSensor, S1, grove_AnalogLight))
38 | writeDebugStreamLine("Init failed!");
39 |
40 | while(true)
41 | {
42 | // Read the sensor data.
43 | readSensor(&groveSensor);
44 | displayTextLine(1, "A:%4d", groveSensor.analog);
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/examples/mindsensors-ev3-grove-test2.c:
--------------------------------------------------------------------------------
1 | #pragma config(Sensor, S1, GROVE, sensorI2CCustom)
2 | //*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
3 |
4 | /**
5 | * mindsensors-ev3-grove.h provides an API for the Mindsensors EV3-Grove Sensor. This program
6 | * demonstrates how to use that API.
7 | *
8 | * Changelog:
9 | * - 0.1: Initial release
10 | *
11 | * Credits:
12 | * - Big thanks to Mindsensors for providing me with the hardware necessary to write and test this.
13 | *
14 | * License: You may use this code as you wish, provided you give credit where it's due.
15 | *
16 | * THIS CODE WILL ONLY WORK WITH ROBOTC VERSION 4.29 AND HIGHER
17 |
18 | * Xander Soldaat (xander_at_botbench.com)
19 | */
20 |
21 | #include "mindsensors-ev3-grove.h"
22 |
23 | // Create struct to hold sensor data
24 | tGROVE groveSensor;
25 |
26 |
27 | // main task
28 | task main ()
29 | {
30 | displayCenteredTextLine(0, "Mindsensors");
31 | displayCenteredBigTextLine(1, "EV3-Grove");
32 | displayCenteredTextLine(3, "Test 1");
33 | sleep(2000);
34 |
35 | //// Create struct to hold sensor data
36 | //tGROVE groveSensor;
37 |
38 | // Initialise and configure struct, port and sensor type
39 | if (!initSensor(&groveSensor, S1, grove_DigitalLight))
40 | writeDebugStreamLine("Init failed!");
41 |
42 | while(true)
43 | {
44 | // Read the sensor data.
45 | readSensor(&groveSensor);
46 | displayTextLine(4, "0x%02X, ", groveSensor.read.data[0]);
47 | displayTextLine(5, "0x%02X, ", groveSensor.read.data[1]);
48 | displayTextLine(6, "0x%02X, ", groveSensor.read.data[2]);
49 | displayTextLine(7, "0x%02X, ", groveSensor.read.data[3]);
50 | // displayTextLine(1, "A:%4d", groveSensor.analog);
51 | sleep(100);
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/examples/mindsensors-hid-test1.c:
--------------------------------------------------------------------------------
1 | #pragma config(Sensor, S1, MSHID, sensorI2CCustom9V)
2 | //*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
3 |
4 | /**
5 | * mindsensors-hid.h provides an API for the Mindsensors HID Sensor. This program
6 | * demonstrates how to use that API.
7 | *
8 | * Changelog:
9 | * - 0.1: Initial release
10 | * - 0.2: More comments
11 | *
12 | * Credits:
13 | * - Big thanks to Mindsensors for providing me with the hardware necessary to write and test this.
14 | *
15 | * License: You may use this code as you wish, provided you give credit where it's due.
16 | *
17 | * THIS CODE WILL ONLY WORK WITH ROBOTC VERSION 4.10 AND HIGHER
18 |
19 | * Xander Soldaat (xander_at_botbench.com)
20 | * 28 November 2009
21 | * version 0.2
22 | */
23 |
24 | #include "mindsensors-hid.h"
25 |
26 | task main () {
27 | // |
28 | // 1234567890123456789
29 | string msg1 = "notepad\r\n";
30 | string msg2 = "hello world";
31 |
32 | // Tell the MSHID you are going to send raw keyboard data
33 | MSHIDsendCommand(MSHID, MSHID_DDATA);
34 |
35 | // The raw keyboard data (Windows Key + R)
36 | MSHIDsendKeyboardData(MSHID, MSHID_MOD_LGUI, 0x15);
37 |
38 | /// Transmit the data
39 | MSHIDsendCommand(MSHID, MSHID_XMIT);
40 |
41 | // Wait the command box to appear
42 | sleep(1000);
43 |
44 | // Set the MSHID to normal ACSII mode
45 | MSHIDsendCommand(MSHID, MSHID_ASCII);
46 |
47 | // Send the first command: "notepad" followed by \r\n (enter)
48 | MSHIDsendString(MSHID, msg1);
49 |
50 | // Wait for notepad to start up
51 | sleep(2000);
52 |
53 | // Send the second message "hello world"
54 | MSHIDsendString(MSHID, msg2);
55 | }
56 |
--------------------------------------------------------------------------------
/examples/mindsensors-imu-test1.c:
--------------------------------------------------------------------------------
1 | #pragma config(Sensor, S1, MSIMU, sensorI2CCustomFastSkipStates)
2 | //*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
3 |
4 | /**
5 | * mindsensors-imu.h provides an API for the Mindsensors AbsoluteIMU Sensor. This program
6 | * demonstrates how to use that API.
7 | *
8 | * Changelog:
9 | * - 0.1: Initial release
10 | *
11 | * Credits:
12 | * - Big thanks to Mindsensors for providing me with the hardware necessary to write and test this.
13 | *
14 | * License: You may use this code as you wish, provided you give credit where it's due.
15 | *
16 | * THIS CODE WILL ONLY WORK WITH ROBOTC VERSION 4.10 AND HIGHER
17 |
18 | * Xander Soldaat (xander_at_botbench.com)
19 | * 25 August 2012
20 | * version 0.1
21 | */
22 |
23 | #include "mindsensors-imu.h"
24 |
25 | task main(){
26 |
27 | short x_val, y_val, z_val; // axis values
28 |
29 | displayCenteredTextLine(0, "Mindsensors");
30 | displayCenteredBigTextLine(1, "IMU");
31 | displayCenteredTextLine(3, "Test 1");
32 | displayCenteredTextLine(5, "Connect sensor");
33 | displayCenteredTextLine(6, "to S1");
34 | sleep(2000);
35 | eraseDisplay();
36 |
37 | while (true){
38 |
39 | // Read the GYROSCOPE
40 | MSIMUreadGyroAxes(MSIMU, x_val, y_val, z_val);
41 |
42 | displayTextLine(1, "%d", x_val);
43 | displayTextLine(2, "%d", y_val);
44 | displayTextLine(3, "%d", z_val);
45 |
46 | // Read the accelerometer
47 | MSIMUreadAccelAxes(MSIMU, x_val, y_val, z_val);
48 |
49 | displayTextLine(5, "%d", x_val);
50 | displayTextLine(6, "%d", y_val);
51 | displayTextLine(7, "%d", z_val);
52 | sleep(50);
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/examples/mindsensors-imu-test2.c:
--------------------------------------------------------------------------------
1 | #pragma config(Sensor, S1, MSIMU, sensorI2CCustomFastSkipStates)
2 | //*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
3 |
4 | /**
5 | * mindsensors-imu.h provides an API for the Mindsensors AbsoluteIMU Sensor. This program
6 | * demonstrates how to use that API.
7 | *
8 | * Changelog:
9 | * - 0.1: Initial release
10 | *
11 | * Credits:
12 | * - Big thanks to Mindsensors for providing me with the hardware necessary to write and test this.
13 | *
14 | * License: You may use this code as you wish, provided you give credit where it's due.
15 | *
16 | * THIS CODE WILL ONLY WORK WITH ROBOTC VERSION 4.10 AND HIGHER
17 |
18 | * Xander Soldaat (xander_at_botbench.com)
19 | * 26 August 2012
20 | * version 0.1
21 | */
22 |
23 | #include "mindsensors-imu.h"
24 |
25 | task main(){
26 |
27 | short heading;
28 | short x_val, y_val, z_val; // axis values
29 |
30 | displayCenteredTextLine(0, "Mindsensors");
31 | displayCenteredBigTextLine(1, "IMU");
32 | displayCenteredTextLine(3, "Test 2");
33 | displayCenteredTextLine(5, "Connect sensor");
34 | displayCenteredTextLine(6, "to S1");
35 | sleep(2000);
36 | eraseDisplay();
37 |
38 | while (true){
39 |
40 | // Read the Compass
41 | heading = MSIMUreadHeading(MSIMU);
42 |
43 | displayTextLine(1, "%d", heading);
44 |
45 | // Read the tilt
46 | MSIMUreadTiltAxes(MSIMU, x_val, y_val, z_val);
47 |
48 | displayTextLine(5, "%d", x_val);
49 | displayTextLine(6, "%d", y_val);
50 | displayTextLine(7, "%d", z_val);
51 | sleep(50);
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/examples/mindsensors-imu-test3.c:
--------------------------------------------------------------------------------
1 | #pragma config(Sensor, S1, MSIMU, sensorI2CCustomFastSkipStates)
2 | //*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
3 |
4 | /**
5 | * mindsensors-imu.h provides an API for the Mindsensors AbsoluteIMU Sensor. This program
6 | * demonstrates how to use that API.
7 | *
8 | * Changelog:
9 | * - 0.1: Initial release
10 | *
11 | * Credits:
12 | * - Big thanks to Mindsensors for providing me with the hardware necessary to write and test this.
13 | *
14 | * License: You may use this code as you wish, provided you give credit where it's due.
15 | *
16 | * THIS CODE WILL ONLY WORK WITH ROBOTC VERSION 4.10 AND HIGHER
17 |
18 | * Xander Soldaat (xander_at_botbench.com)
19 | * 26 August 2012
20 | * version 0.1
21 | */
22 |
23 | #include "mindsensors-imu.h"
24 |
25 | task main(){
26 |
27 | short heading;
28 | short x_val, y_val, z_val; // axis values
29 |
30 | displayCenteredTextLine(0, "Mindsensors");
31 | displayCenteredBigTextLine(1, "IMU");
32 | displayCenteredTextLine(3, "Test 3");
33 | displayCenteredTextLine(5, "Connect sensor");
34 | displayCenteredTextLine(6, "to S1");
35 | sleep(2000);
36 | eraseDisplay();
37 |
38 | while (true){
39 |
40 | // Read the Compass
41 | heading = MSIMUreadHeading(MSIMU);
42 |
43 | displayTextLine(1, "Heading: %d", heading);
44 |
45 | // Read the magnetic fields (they're used to calculate the heading)
46 | MSIMUreadMagneticFields(MSIMU, x_val, y_val, z_val);
47 | displayTextLine(3, "Magnetic fields:");
48 | displayTextLine(4, "X: %d", x_val);
49 | displayTextLine(5, "Y: %d", y_val);
50 | displayTextLine(6, "Z: %d", z_val);
51 | sleep(50);
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/examples/mindsensors-irdist-test1.c:
--------------------------------------------------------------------------------
1 | #pragma config(Sensor, S1, MSDIST, sensorI2CCustomFastSkipStates9V)
2 | //*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
3 |
4 | /**
5 | * MSAC-driver.h provides an API for the Mindsensors Acceleration Sensor. This program
6 | * demonstrates how to use that API.
7 | *
8 | * Changelog:
9 | * - 0.1: Initial release
10 | * - 0.2: More comments
11 | * - 0.3: Fixed stupid typo
12 | * - 0.4: Removed sensor configuration call, now done automatically.
13 | *
14 | * Credits:
15 | * - Big thanks to Mindsensors for providing me with the hardware necessary to write and test this.
16 | *
17 | * License: You may use this code as you wish, provided you give credit where it's due.
18 | *
19 | * THIS CODE WILL ONLY WORK WITH ROBOTC VERSION 4.10 AND HIGHER
20 |
21 | * Xander Soldaat (xander_at_botbench.com)
22 | * 06 July 2010
23 | * version 0.4
24 | */
25 |
26 | #include "mindsensors-irdist.h"
27 |
28 | task main () {
29 | short distance = 0;
30 | short voltage = 0;
31 | short mindist = 0;
32 | short maxdist = 0;
33 | string type;
34 |
35 | displayCenteredTextLine(0, "Mindsensors");
36 | displayCenteredBigTextLine(1, "DIST-nx");
37 | displayCenteredTextLine(3, "Test 1");
38 |
39 | sleep(2000);
40 |
41 | playSound(soundBeepBeep);
42 | while(bSoundActive) sleep(1);
43 | eraseDisplay();
44 |
45 | // Read the minimum distance the sensor can "see"
46 | mindist = MSDISTreadMinDist(MSDIST);
47 |
48 | // Read the maximum distance the sensor can "see"
49 | maxdist = MSDISTreadMaxDist(MSDIST);
50 |
51 | // Get the type of Sharp IR module connected to the sensor
52 | switch(MSDISTreadModuleType(MSDIST)) {
53 | case MSDIST_GP2D12: type = " GP2D12"; break;
54 | case MSDIST_GP2D120: type = "GP2D120"; break;
55 | case MSDIST_GP2YA02: type = "GP2YA02"; break;
56 | case MSDIST_GP2YA21: type = "GP2YA21"; break;
57 | case MSDIST_CUSTOM: type = " CUSTOM"; break;
58 | }
59 |
60 | displayTextLine(5, "Type: %s", type);
61 | displayTextLine(6, "Min: %4dmm", mindist);
62 | displayTextLine(7, "Max: %4dmm", maxdist);
63 |
64 | while (true) {
65 | // Get the distance calculated based on the data from the IR Sharp module
66 | distance = MSDISTreadDist(MSDIST);
67 |
68 | // Get the raw voltage data from the Sharp IR module
69 | voltage = MSDISTreadVoltage(MSDIST);
70 | if (distance < 0) {
71 | displayTextLine(4, "ERROR!!");
72 | sleep(2000);
73 | stopAllTasks();
74 | }
75 |
76 | displayCenteredBigTextLine(0, "%4dmm", distance);
77 | displayCenteredBigTextLine(3, "%4dmV", voltage);
78 | sleep(50);
79 | }
80 | }
81 |
--------------------------------------------------------------------------------
/examples/mindsensors-irthermometer-test1.c:
--------------------------------------------------------------------------------
1 | /**
2 | * mindsensors-irthermometer.h provides an API for the Mindsensors IR Thermometer Sensor. This program
3 | * demonstrates how to use that API.
4 | *
5 | * Changelog:
6 | * - 0.1: Initial release
7 | *
8 | * Credits:
9 | * - Big thanks to Mindsensors for providing me with the hardware necessary to write and test this.
10 | *
11 | * License: You may use this code as you wish, provided you give credit where it's due.
12 | *
13 | * THIS CODE WILL ONLY WORK WITH ROBOTC VERSION 4.53 AND HIGHER
14 |
15 | * Xander Soldaat (xander_at_botbench.com)
16 | * 18 May 2016
17 | * version 0.1
18 | */
19 |
20 | #include "mindsensors-irthermometer.h"
21 |
22 | task main () {
23 | tSensors MSIR = S1;
24 | tMSIR irThermometer;
25 |
26 | displayCenteredTextLine(0, "Mindsensors");
27 | displayCenteredBigTextLine(1, "IR Thermo");
28 | displayCenteredTextLine(3, "Test 1");
29 | sleep(2000);
30 |
31 | eraseDisplay();
32 |
33 | // Create struct to hold sensor data
34 | // tMSIR irThermometer;
35 |
36 | // Initialise and configure struct and port
37 | // Set this to false to read in Farenheit
38 | bool bUseCelcius = true;
39 |
40 | initSensor(&irThermometer, MSIR, bUseCelcius);
41 |
42 | // You can omit bUseCelcius if you only want to measure in Celcius.
43 | // initSensor(&irThermometer, MSIR);
44 |
45 | while (true)
46 | {
47 | if (!readSensor(&irThermometer))
48 | writeDebugStreamLine("ERROR reading sensor!!");
49 |
50 | displayTextLine(0,"MSIR Test 1");
51 |
52 | displayTextLine(2, "Ambient: %4.2f%s", irThermometer.ambient, irThermometer.bUseCelcius ? "C" : "F");
53 | displayTextLine(3, "Target: %4.2f%s", irThermometer.target, irThermometer.bUseCelcius ? "C" : "F");
54 |
55 | sleep(100);
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/examples/mindsensors-ligthsensrarr-test1.c:
--------------------------------------------------------------------------------
1 | #pragma config(Sensor, S1, MSLSA, sensorEV3_GenericI2C)
2 | //*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
3 |
4 | /**
5 | * mindsensors-lightsensorarray.h provides an API for the Mindsensors LightSensorArray Sensor. This program
6 | * demonstrates how to use that API.
7 | *
8 | * Changelog:
9 | * - 0.1: Initial release
10 | *
11 | * Credits:
12 | * - Big thanks to Mindsensors for providing me with the hardware necessary to write and test this.
13 | *
14 | * License: You may use this code as you wish, provided you give credit where it's due.
15 | *
16 | * THIS CODE WILL ONLY WORK WITH ROBOTC VERSION 4.10 AND HIGHER
17 |
18 | * Xander Soldaat (xander_at_botbench.com)
19 | * 30 September 2012
20 | * version 0.1
21 | */
22 |
23 | #include "mindsensors-lightsensorarray.h"
24 |
25 | task main {
26 | tByteArray signalstr;
27 |
28 | MSLSAinit(MSLSA);
29 |
30 | writeDebugStreamLine("Type: %d, mode: %d", SensorType[MSLSA], SensorMode[MSLSA]);
31 | while (true) {
32 | if (!MSLSAreadSensors(MSLSA, &signalstr[0]))
33 | {
34 | //eraseDisplay();
35 | playSound(soundException);
36 | //displayCenteredTextLine(4, "error!");
37 | //sleep(5000);
38 | }
39 |
40 | // This clears the entire area occupied by the small rectangles
41 | eraseRect(6,62, 91, 43);
42 | for (short i = 0; i < 8; i++) {
43 | // Draw the rectangles for the signal strength first
44 | drawRect(6+(i*11),62, 14+(i*11), 50);
45 | fillRect(6+(i*11),51+signalstr[i]/10, 14+(i*11), 50);
46 | }
47 | // Display the actual signal strength for each sensor
48 | for (short i = 0; i < 7; i+=2) {
49 | displayTextLine(i/2+3, "S: %3d S: %3d", (short)signalstr[i], (short)signalstr[i+1]);
50 | }
51 | sleep(50);
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/examples/mindsensors-ligthsensrarr-test2.c:
--------------------------------------------------------------------------------
1 | #pragma config(Sensor, S1, MSLSA, sensorI2CCustom)
2 | //*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
3 |
4 | /**
5 | * mindsensors-lineleader.h provides an API for the Mindsensors LineLeader Sensor. This program
6 | * demonstrates how to use that API.
7 | *
8 | * Changelog:
9 | * - 0.1: Initial release
10 | * - 0.2: More comments
11 | *
12 | * Credits:
13 | * - Big thanks to Mindsensors for providing me with the hardware necessary to write and test this.
14 | *
15 | * License: You may use this code as you wish, provided you give credit where it's due.
16 | *
17 | * THIS CODE WILL ONLY WORK WITH ROBOTC VERSION 4.10 AND HIGHER
18 |
19 | * Xander Soldaat (xander_at_botbench.com)
20 | * 28 November 2009
21 | * version 0.2
22 | */
23 |
24 | #include "mindsensors-lightsensorarray.h"
25 |
26 | task main {
27 | tIntArray signalstr;
28 |
29 | MSLSAinit(MSLSA);
30 |
31 | while (true) {
32 | // Fetch all of the uncalibrated sensor values and display them
33 | if (!MSLSAreadRawSensors(MSLSA, &signalstr[0]))
34 | {
35 | eraseDisplay();
36 | playSound(soundException);
37 | displayCenteredTextLine(4, "error!");
38 | sleep(5000);
39 | }
40 | for (short i = 0; i < 8; i++) {
41 | displayTextLine(i, "S[%d]: %d", i, signalstr[i]);
42 | }
43 | sleep(50);
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/examples/mindsensors-ligthsensrarr-test3.c:
--------------------------------------------------------------------------------
1 | #pragma config(Sensor, S1, MSLSA, sensorI2CCustomFastSkipStates9V)
2 | //*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
3 |
4 | /**
5 | * mindsensors-lightsensorarray.h provides an API for the Mindsensors LightSensorArray Sensor. This program
6 | * demonstrates how to use that API.
7 | *
8 | * Changelog:
9 | * - 0.1: Initial release
10 | *
11 | * Credits:
12 | * - Big thanks to Mindsensors for providing me with the hardware necessary to write and test this.
13 | *
14 | * License: You may use this code as you wish, provided you give credit where it's due.
15 | *
16 | * THIS CODE WILL ONLY WORK WITH ROBOTC VERSION 4.10 AND HIGHER
17 |
18 | * Xander Soldaat (xander_at_botbench.com)
19 | * 30 September 2012
20 | * version 0.1
21 | */
22 |
23 | #include "mindsensors-lightsensorarray.h"
24 |
25 | const string frequencyNames[] = {"US", "UNI", "EU", };
26 |
27 | // Set the desired frequency compensation mode. This has to do with the frequency of the
28 | // AC current. It causes flickering of the lights at the same frequency and can
29 | // interfere with the sensor readings. This allows you to compensate for it.
30 | void setFrequency(short choice)
31 | {
32 | playSound(soundBlip);
33 | switch(choice)
34 | {
35 | case 0: MSLSAsetUS(MSLSA); break;
36 | case 1: MSLSAsetUni(MSLSA); break;
37 | case 2: MSLSAsetEU(MSLSA); break;
38 | }
39 | }
40 |
41 | task main {
42 | short choice = 1;
43 |
44 | while (true) {
45 | switch(nNxtButtonPressed)
46 | {
47 | case kEnterButton: setFrequency(choice); break;
48 | case kLeftButton: choice = (choice == 0) ? 0 : (choice - 1); break;
49 | case kRightButton: choice = (choice == 2) ? 2 : (choice + 1); break;
50 | }
51 |
52 | displayCenteredTextLine(0, "LightSensorArray");
53 | displayCenteredTextLine(1, "Freq. config");
54 | displayCenteredBigTextLine(3, frequencyNames[choice]);
55 | displayCenteredTextLine(6, "[enter] to set");
56 | displayTextLine(7, "< switch freq >");
57 |
58 | // Debounce
59 | while (nNxtButtonPressed != kNoButton) sleep(1);
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/examples/mindsensors-lineleader-test2.c:
--------------------------------------------------------------------------------
1 | #pragma config(Sensor, S1, LLEADER, sensorI2CCustom9V)
2 | //*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
3 |
4 | /**
5 | * mindsensors-lineleader.h provides an API for the Mindsensors LineLeader Sensor. This program
6 | * demonstrates how to use that API.
7 | *
8 | * Changelog:
9 | * - 0.1: Initial release
10 | * - 0.2: More comments
11 | *
12 | * Credits:
13 | * - Big thanks to Mindsensors for providing me with the hardware necessary to write and test this.
14 | *
15 | * License: You may use this code as you wish, provided you give credit where it's due.
16 | *
17 | * THIS CODE WILL ONLY WORK WITH ROBOTC VERSION 4.10 AND HIGHER
18 |
19 | * Xander Soldaat (xander_at_botbench.com)
20 | * 28 November 2009
21 | * version 0.2
22 | */
23 |
24 | #include "mindsensors-lineleader.h"
25 |
26 | task main {
27 | byte sensor = 0;
28 | tByteArray signalstr;
29 |
30 | while (true) {
31 | // Fetch the data from the sensor
32 | sensor = LLreadResult(LLEADER);
33 |
34 | // Re75ad the raw sensor data (8 bit data)
35 | LLreadSensorRaw(LLEADER, signalstr);
36 |
37 | // This clears the entire area occupied by the small rectangles
38 | eraseRect(6,62, 91, 43);
39 | for (short i = 0; i < 8; i++) {
40 | // Draw the rectangles for the signal strength first
41 | drawRect(6+(i*11),62, 14+(i*11), 50);
42 | fillRect(6+(i*11),51+signalstr[i]/10, 14+(i*11), 50);
43 | // Draw a black rectangle if the sensor has detected the line,
44 | // a hollow one when nothing has been detected.
45 | if ((sensor >> i) & 1) {
46 | fillRect(6+(i*11),48, 14+(i*11), 43);
47 | } else {
48 | drawRect(6+(i*11),48, 14+(i*11), 43);
49 | }
50 | }
51 | // Display the actual signal strength for each sensor
52 | for (short i = 0; i < 7; i+=2) {
53 | displayTextLine(i/2+3, "S: %3d S: %3d", (short)signalstr[i], (short)signalstr[i+1]);
54 | }
55 | sleep(50);
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/examples/mindsensors-lineleader-test4.c:
--------------------------------------------------------------------------------
1 | #pragma config(Sensor, S1, LLEADER, sensorI2CCustomFastSkipStates9V)
2 | //*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
3 |
4 | /** \file mindsensors-lineleader.c
5 | * \brief Mindsensors LineLeader Sensor demo program
6 | *
7 | * MSLL-test3.c is a demo program for the Mindsensors LineLeader Sensor.
8 | *
9 | * Changelog:
10 | * - 0.1: Initial release
11 | * - 0.2: More comments
12 | *
13 | * Credits:
14 | * - Big thanks to Mindsensors for providing me with the hardware necessary to write and test this.
15 | *
16 | * License: You may use this code as you wish, provided you give credit where its due.
17 | *
18 | * THIS CODE WILL ONLY WORK WITH ROBOTC VERSION 4.10 AND HIGHER
19 |
20 | * Xander Soldaat (xander_at_botbench.com)
21 | * 28 November 2009
22 | * version 0.2
23 | */
24 |
25 | #include "mindsensors-lineleader.h"
26 |
27 | task main {
28 | tIntArray signalstr;
29 |
30 | while (true) {
31 | // Fetch the data from the sensor. These are the 16 bit raw AD values.
32 | LLreadSensorUncalibrated(LLEADER, signalstr);
33 |
34 | // Display the actual signal strength for each sensor
35 | for (short i = 0; i < 7; i++) {
36 | displayTextLine(i, "S[%d]: %5d", i, signalstr[i]);
37 | }
38 | sleep(50);
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/examples/mindsensors-magicwand-test1.c:
--------------------------------------------------------------------------------
1 | #pragma config(Sensor, S1, MAGICWAND, sensorI2CCustomFastSkipStates)
2 | //*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
3 |
4 | /**
5 | * mindsensors-magicwand.h provides additional functionality on top of the PCF8574 driver for
6 | * the Mindsensors Magic Wand. This program demonstrates how to use that API to
7 | * control the LEDs for fun and profit!
8 | *
9 | * Changelog:
10 | * - 0.1: Initial release
11 | *
12 | * Credits:
13 | * - Magic Wand driver originally written by Mike Partain a.k.a. Spiked3 (http://www.spiked3.com/)
14 | * - Big thanks to Mindsensors for providing me with the hardware necessary to write and test this.
15 | *
16 | * License: You may use this code as you wish, provided you give credit where it's due.
17 | *
18 | * THIS CODE WILL ONLY WORK WITH ROBOTC VERSION 4.10 AND HIGHER
19 |
20 | * Xander Soldaat (xander_at_botbench.com)
21 | * 29 July 2012
22 | * version 0.1
23 | */
24 |
25 | #include "mindsensors-magicwand.h"
26 |
27 | task main () {
28 |
29 | MSMWclearALL(MAGICWAND);
30 |
31 | while (true)
32 | {
33 |
34 | // Blink LED 0 5 times
35 | for (short i = 0; i < 5; i++)
36 | {
37 | MSMWsetLED(MAGICWAND, 0, true);
38 | sleep(150);
39 | MSMWsetLED(MAGICWAND, 0, false);
40 | sleep(50);
41 | }
42 |
43 | // Do the same as above, only use the toggle function
44 | // Toggle LED 4
45 | for (short i = 0; i < 10; i++)
46 | {
47 | MSMWtoggleLED(MAGICWAND, 4);
48 | sleep(200);
49 | }
50 |
51 | // Flash pulse all of the LEDs quickly
52 | for (short i = 0; i < 3; i++)
53 | {
54 | MSMWsetALL(MAGICWAND);
55 | sleep(50);
56 | MSMWclearALL(MAGICWAND);
57 | sleep(150);
58 | }
59 |
60 | // Use a cool flash effect and clear them all
61 | MSMWflashAndClear(MAGICWAND, 4);
62 |
63 | for (short j = 1; j < 10; j++)
64 | {
65 | short r = random(7);
66 | MSMWsetLED(MAGICWAND, r, true);
67 | for (short i = 0; i < 10; i++)
68 | {
69 | MSMWtoggleLED(MAGICWAND, 4);
70 | sleep(100);
71 | }
72 | MSMWsetLED(MAGICWAND, r, false);
73 | }
74 | sleep(500);
75 | MSMWclearALL(MAGICWAND);
76 |
77 | }
78 |
79 | }
80 |
--------------------------------------------------------------------------------
/examples/mindsensors-motormux-test2.c:
--------------------------------------------------------------------------------
1 | #pragma config(Sensor, S1, MSMMUX, sensorI2CCustomFastSkipStates)
2 | //*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
3 |
4 | /**
5 | * mindsensors-motormux.h provides an API for the Mindsensors Motor MUX. This program
6 | * demonstrates how to use that API to control the motors attached to the MUX.
7 | *
8 | * Changelog:
9 | * - 0.1: Initial release
10 | *
11 | * Credits:
12 | * - Big thanks to Mindsensors for providing me with the hardware necessary to write and test this.
13 | *
14 | * License: You may use this code as you wish, provided you give credit where it's due.
15 | *
16 | * THIS CODE WILL ONLY WORK WITH ROBOTC VERSION 4.10 AND HIGHER
17 |
18 | * Xander Soldaat (xander_at_botbench.com)
19 | * 30 May 2011
20 | * version 0.1
21 | */
22 |
23 | #include "mindsensors-motormux.h"
24 | #include "mindsensors-irdist.h"
25 |
26 | // configure MSDIST to also be connected to S1 as well, through the MMUX
27 | #define MSDIST S1
28 |
29 | task main () {
30 | long encA = 0;
31 | long encB = 0;
32 |
33 | long distance = 0;
34 | long mindist = 0;
35 | long maxdist = 0;
36 |
37 | short motorSpeed = 0;
38 |
39 | eraseDisplay();
40 | MSMMUXinit();
41 |
42 | MSMotorStop(mmotor_S1_1);
43 | MSMotorStop(mmotor_S1_2);
44 |
45 | sleep(500);
46 |
47 | // Reset the encoders. This can be done individually or all at once.
48 | // You should do this at the start of your program.
49 | MSMMotorEncoderResetAll(MSMMUX);
50 |
51 | // Read the minimum distance the sensor can "see"
52 | mindist = MSDISTreadMinDist(MSDIST);
53 |
54 | // Read the maximum distance the sensor can "see"
55 | maxdist = MSDISTreadMaxDist(MSDIST);
56 |
57 | while (true) {
58 | distance = MSDISTreadDist(MSDIST);
59 |
60 | // Retrieve the motor-MUX's encoder counts
61 | encA = MSMMotorEncoder(mmotor_S1_1);
62 | encB = MSMMotorEncoder(mmotor_S1_2);
63 |
64 | // calculate the motor speed
65 | motorSpeed = ((distance - mindist) * 100) / (maxdist - mindist);
66 |
67 | // Tell the motors to start moving.
68 | MSMMotor(mmotor_S1_1, motorSpeed);
69 | MSMMotor(mmotor_S1_2, motorSpeed);
70 |
71 | // Display the info.
72 | displayTextLine(4, "D: %5d", distance);
73 | displayTextLine(5, "A: %5d (%3d)", encA, motorSpeed);
74 | displayTextLine(6, "B: %5d (%3d)", encB, motorSpeed);
75 | sleep(20);
76 | }
77 | }
78 |
--------------------------------------------------------------------------------
/examples/mindsensors-numericpad-test1.c:
--------------------------------------------------------------------------------
1 | #pragma config(Sensor, S1, MSNP, sensorI2CCustomFastSkipStates)
2 | //*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
3 |
4 | /**
5 | * mindsensors-numericpad.h provides an API for the Mindsensors Numeric Keypad Sensor. This program
6 | * demonstrates how to use that API.
7 | *
8 | * Changelog:
9 | * - 0.1: Initial release
10 | *
11 | * Credits:
12 | * - Big thanks to Mindsensors for providing me with the hardware necessary to write and test this.
13 | *
14 | * License: You may use this code as you wish, provided you give credit where it's due.
15 | *
16 | * THIS CODE WILL ONLY WORK WITH ROBOTC VERSION 4.10 AND HIGHER
17 |
18 | * Xander Soldaat (xander_at_botbench.com)
19 | * 30 October 2010
20 | * version 0.1
21 | */
22 |
23 | #include "mindsensors-numericpad.h"
24 |
25 | task main () {
26 |
27 | short keys = 0;
28 | unsigned byte key[] = {0};
29 | short number = 0;
30 | string output;
31 |
32 | displayCenteredTextLine(0, "Mindsensors");
33 | displayCenteredBigTextLine(1, "NumPad");
34 | displayCenteredTextLine(3, "Test 1");
35 | displayCenteredTextLine(5, "Connect sensor");
36 | displayCenteredTextLine(6, "to S1");
37 | sleep(2000);
38 |
39 | eraseDisplay();
40 | displayCenteredTextLine(0, "Mindsensors NP");
41 | displayTextLine(1, "-------------------");
42 | displayTextLine(5, "-------------------");
43 | displayTextLine(7, "X: no key");
44 | while (true) {
45 | // Which key is being pressed now?
46 | if (!MSNPscanKeys(MSNP, keys, key[0], number))
47 | stopAllTasks();
48 |
49 | // "convert" to string so we can print it
50 | output = key;
51 |
52 | displayTextLine(3, "Numpad Key: %s", output);
53 | displayTextLine(4, "Numpad Num: %d", number);
54 |
55 | sleep(100);
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/examples/mindsensors-nxtcam-test1.c:
--------------------------------------------------------------------------------
1 | /**
2 | * mindsensors-nxtcam.h provides an API for the Mindsensors NXTCam. This program
3 | * demonstrates how to use that API.
4 | *
5 | * Changelog:
6 | * - 0.1: Initial release
7 | * - 0.2: More comments
8 | *
9 | * Credits:
10 | * - Gordon Wyeth for writing the original driver and cam_display program
11 | *
12 | * License: You may use this code as you wish, provided you give credit where it's due.
13 | *
14 | * THIS CODE WILL ONLY WORK WITH ROBOTC VERSION 4.10 AND HIGHER
15 |
16 | * Xander Soldaat (xander_at_botbench.com)
17 | * 28 November 2009
18 | * version 0.2
19 | */
20 |
21 | #define NXTCAMV5
22 |
23 | #include "mindsensors-nxtcam.h"
24 |
25 | // short xscale(short x) - Scales x values from camera coordinates to screen coordinates.
26 | long xscale(long x) {
27 | return ((x - 12) * 177) / 175;
28 | }
29 |
30 | // short yscale(short y) - Scales y values from camera coordinates to screen coordinates.
31 | long yscale(long y) {
32 | return ((143 - y) * 127) / 143;
33 | }
34 |
35 | /*
36 | Main task
37 | */
38 | task main () {
39 |
40 | // Set up the port alias for the camera, configuration is handled by NXTCAMint()
41 | tSensors cam = S1;
42 |
43 | blob_array _blobs;
44 | // combine all colliding blobs into one
45 | bool _condensed = true;
46 |
47 | //blob_array _blobs;
48 | long _l, _t, _r, _b;
49 | long _x, _y;
50 | short _nblobs;
51 | eraseDisplay();
52 |
53 | // Initialise the camera, pick one of the following modes
54 | NXTCAMinit(cam); // Normal object (blob) tracking
55 | // NXTCaminitLine(cam); // Line tracking
56 | // NXTCaminitEyes(cam); // Eye tracking
57 | // NXTCaminitFace(cam); // Face tracking
58 |
59 | while(true) {
60 | // Fetch all the blobs, have the driver combine all
61 | // the colliding blobs.
62 | _nblobs = NXTCAMgetBlobs(cam, _blobs, _condensed);
63 | eraseDisplay();
64 | for (short i = 0; i < _nblobs; i++) {
65 | // Draw the scaled blobs
66 | _l = xscale(_blobs[i].x1);
67 | _t = yscale(_blobs[i].y1);
68 | _r = xscale(_blobs[i].x2);
69 | _b = yscale(_blobs[i].y2);
70 | fillRect(_l, _t, _r, _b);
71 | }
72 |
73 | // draw a crosshair on the screen for the average centre of all blobs with
74 | // colour index 1 and that are larger than 200 pixels square
75 | NXTCAMgetAverageCenter(_blobs, _nblobs, 1, 200,_x, _y);
76 | _x = xscale(_x);
77 | _y = yscale(_y);
78 | eraseRect(_x -2, _y-10, _x+2, _y+10);
79 | eraseRect(_x -10, _y-2, _x+10, _y+2);
80 | drawLine(_x, _y+8, _x, _y-8);
81 | drawLine(_x+8, _y, _x-8, _y);
82 | displayTextLine(1, "%d", _nblobs);
83 | sleep(100);
84 | }
85 | }
86 |
--------------------------------------------------------------------------------
/examples/mindsensors-nxtcam-test2.c:
--------------------------------------------------------------------------------
1 | /**
2 | * mindsensors-nxtcam.h provides an API for the Mindsensors NXTCam. This program
3 | * demonstrates how to use that API.
4 | *
5 | * Changelog:
6 | * - 0.1: Initial release
7 | * - 0.2: More comments
8 | *
9 | * Credits:
10 | * - Gordon Wyeth for writing the original driver and cam_display program
11 | *
12 | * License: You may use this code as you wish, provided you give credit where it's due.
13 | *
14 | * THIS CODE WILL ONLY WORK WITH ROBOTC VERSION 4.10 AND HIGHER
15 |
16 | * Xander Soldaat (xander_at_botbench.com)
17 | * 28 November 2009
18 | * version 0.2
19 | */
20 |
21 | #define NXTCAMV5
22 |
23 | #include "mindsensors-nxtcam.h"
24 |
25 | /*
26 | Main task
27 | */
28 | task main () {
29 |
30 | // Set up the port alias for the camera, configuration is handled by NXTCAMint()
31 | tSensors cam = S1;
32 |
33 | eraseDisplay();
34 |
35 | // Initialise the camera
36 | NXTCAMinit(cam);
37 | displayCenteredBigTextLine(2, "Insta-Pic");
38 | displayCenteredTextLine(6, "[LEFT] to take a still");
39 | displayCenteredTextLine(7, "[RIGHT] to take a short movie");
40 |
41 | while(true)
42 | {
43 |
44 | if (getXbuttonValue(xButtonLeft))
45 | {
46 | NXTCamCaptureStill(cam);
47 | playSound(soundBeepBeep);
48 | while (bSoundActive)
49 | sleep(10);
50 | }
51 | else if (getXbuttonValue(xButtonRight))
52 | {
53 | NXTCamCaptureMovie(cam);
54 | playSound(soundBeepBeep);
55 | while (bSoundActive)
56 | sleep(10);
57 | sleep(10000); // movie clips are 10s long
58 | }
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/examples/mindsensors-pressure-test1.c:
--------------------------------------------------------------------------------
1 | #pragma config(Sensor, S1, MSPPS, sensorI2CCustom)
2 | //*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
3 |
4 | #include "mindsensors-pressure.h"
5 |
6 | task main () {
7 | long abspressure;
8 | long gaugepressure;
9 |
10 | // set the sensor to kilo Pascals
11 | MSPPSsetUnit(MSPPS, MSPPS_UNIT_PSI);
12 |
13 | sleep(100);
14 | MSPPSsetRefPressure(MSPPS);
15 | sleep(100);
16 |
17 | displayCenteredTextLine(0, "Mindsensors");
18 | displayCenteredBigTextLine(1, "PPS-v3");
19 | displayCenteredTextLine(3, "Test 1");
20 | sleep(2000);
21 |
22 | // Read the current pressure and feed that to the ref pressure
23 | // abspressure = MSPPSreadAbsPressure(MSPPS);
24 | // MSPPSsetRefPressure(MSPPS, abspressure);
25 |
26 | // you can also do this
27 | MSPPSsetRefPressure(MSPPS);
28 |
29 | while (true) {
30 | eraseDisplay();
31 |
32 | abspressure = MSPPSreadAbsPressure(MSPPS);
33 | gaugepressure = MSPPSreadGaugePressure(MSPPS);
34 |
35 | displayTextLine(0,"MSPPS Test 1");
36 |
37 | displayTextLine(2, "Pressure (KPA):");
38 | displayTextLine(3, "Abs: %d", abspressure);
39 | displayTextLine(4, "Gauge: %d", gaugepressure);
40 | sleep(100);
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/examples/mindsensors-rcxmotormux-test1.c:
--------------------------------------------------------------------------------
1 | #pragma config(Sensor, S1, MSMTRMX, sensorI2CCustomFastSkipStates)
2 | //*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
3 |
4 | /**
5 | * mindsensors-rcxmotormux.h provides an API for the Mindsensors RCX Motor MUX.
6 | * This program demonstrates how to use the driver for the Mindsensors RCX Motor Mux.
7 | * Plug the mux into sensor port 1, and a motor into motor output 1. The motor will
8 | * gradually speed up to full power and then back again, and then the same backwards.
9 | * It will then gradually increase the braking force from nothing to full power, and
10 | * back to zero, before turning the motor off
11 | *
12 | * Changelog:
13 | * - 0.1: Initial release
14 | *
15 | * License: You may use this code as you wish, provided you give credit where it's due.
16 | *
17 | * THIS CODE WILL ONLY WORK WITH ROBOTC VERSION 4.10 AND HIGHER
18 |
19 | * Daniel Playfair Cal (daniel.playfair.cal_at_gmail.com)
20 | * 20 September 2011
21 | * version 0.1
22 | */
23 |
24 | #include "mindsensors-rcxmotormux.h"
25 |
26 | task main () {
27 |
28 | // Gradually speed up
29 | for (short power = 0; power <= 255; power++) {
30 | MSMTRMX_Control (MSMTRMX, MSMTRMX_M1, power);
31 | sleep (20);
32 | }
33 |
34 | // Gradually slow down
35 | for (short power = 255; power >=1; power--) {
36 | MSMTRMX_Control (MSMTRMX, MSMTRMX_M1, power);
37 | sleep (20);
38 | }
39 |
40 | // The same backwards
41 | for (short power = 0; power >= -255; power--) {
42 | MSMTRMX_Control (MSMTRMX, MSMTRMX_M1, power);
43 | sleep (20);
44 | }
45 |
46 | // Slow down again
47 | for (short power = -255; power <= -1; power++) {
48 | MSMTRMX_Control (MSMTRMX, MSMTRMX_M1, power);
49 | sleep (20);
50 | }
51 |
52 | // Gradually increase braking force
53 | for (short force = 0; force <= 255; force++) {
54 | MSMTRMX_Brake (MSMTRMX, MSMTRMX_M1, force);
55 | sleep (20);
56 | }
57 |
58 | // Gradually reduce braing force
59 | for (short force = 255; force >=1; force--) {
60 | MSMTRMX_Brake (MSMTRMX, MSMTRMX_M1, force);
61 | sleep (20);
62 | }
63 |
64 | // Turn off the motor
65 | MSMTRMX_Control (MSMTRMX, MSMTRMX_M1, 0);
66 | }
67 |
--------------------------------------------------------------------------------
/examples/mindsensors-rcxsensorsmux-test1.c:
--------------------------------------------------------------------------------
1 | #pragma config(Sensor, S1, MSRXMUX, sensorI2CCustom9V)
2 | //*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
3 |
4 | /**
5 | * mindsensors-rcxsensorsmux.h provides an API for the Mindsensors RCX Sensor MUX Sensor. This program
6 | * demonstrates how to use that API.
7 | *
8 | * Changelog:
9 | * - 0.1: Initial release
10 | * - 0.2: More comments
11 | *
12 | * Credits:
13 | * - Big thanks to Mindsensors for providing me with the hardware necessary to write and test this.
14 | *
15 | * License: You may use this code as you wish, provided you give credit where it's due.
16 | *
17 | * THIS CODE WILL ONLY WORK WITH ROBOTC VERSION 4.10 AND HIGHER
18 |
19 | * Xander Soldaat (xander_at_botbench.com)
20 | * 28 November 2009
21 | * version 0.2
22 | */
23 |
24 | #include "mindsensors-rcxsensorsmux.h"
25 |
26 | task main () {
27 |
28 | short chan1 = 0;
29 | short chan2 = 0;
30 | short chan4 = 0;
31 |
32 | displayCenteredTextLine(0, "Mindsensors");
33 | displayCenteredBigTextLine(1, "RXMUX");
34 | displayCenteredTextLine(3, "Test 1");
35 |
36 | sleep(2000);
37 |
38 | // Set up channel 1 on the RCX sensor MUX to a light sensor in percentage mode
39 | MSRXMUXsetupChan(MSRXMUX, 1, sensorReflection, modePercentage, 5);
40 |
41 | // Set up channel 2 on the RCX sensor MUX to a touch sensor in raw mode
42 | MSRXMUXsetupChan(MSRXMUX, 2, sensorTouch, modeRaw, 5);
43 |
44 | // Set up channel 4 on the RCX sensor MUX to rotation sensor in rotation mode
45 | MSRXMUXsetupChan(MSRXMUX, 4, sensorRotation, modeRotation, 5);
46 |
47 | while(true) {
48 | // Read from the channels and display
49 | chan1 = MSRXMUXreadChan(MSRXMUX, 1);
50 | chan2 = MSRXMUXreadChan(MSRXMUX, 2);
51 | chan4 = MSRXMUXreadChan(MSRXMUX, 4);
52 | displayBigTextLine(1, "%d", chan1);
53 | displayBigTextLine(3, "%d", chan2);
54 | displayBigTextLine(5, "%d", chan4);
55 | }
56 |
57 | playSound(soundBeepBeep);
58 | while(bSoundActive) sleep(1);
59 | eraseDisplay();
60 | while(1) sleep(1);
61 |
62 | }
63 |
--------------------------------------------------------------------------------
/examples/mindsensors-sensormux-test1.c:
--------------------------------------------------------------------------------
1 | #pragma config(Sensor, S1, MSSMUX, sensorI2CCustom)
2 | //*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
3 |
4 | /**
5 | * mindsensors-sensormux.h provides an API for the Mindsensors SensorMUX Sensor.
6 | * This program demonstrates how to use that API to read multiple sensors
7 | *
8 | * Changelog:
9 | * - 0.1: Initial release
10 | *
11 | * Credits:
12 | * - Big thanks to Mindsensors for providing me with the hardware necessary to write and test this.
13 | *
14 | * License: You may use this code as you wish, provided you give credit where it's due.
15 | *
16 | * THIS CODE WILL ONLY WORK WITH ROBOTC VERSION 4.10 AND HIGHER
17 |
18 | * Xander Soldaat (xander_at_botbench.com)
19 | * 03 March 2013
20 | * version 0.1
21 | */
22 |
23 | #include "mindsensors-sensormux.h"
24 | #include "mindsensors-angle.h"
25 | #include "mindsensors-accelerometer.h"
26 |
27 | task main()
28 | {
29 | short voltage = 0;
30 | short angle;
31 | short x, y, z;
32 | displayCenteredTextLine(0, "Mindsensors");
33 | displayCenteredBigTextLine(1, "SnsrMUX");
34 | displayCenteredTextLine(3, "Test 1");
35 |
36 | sleep(2000);
37 | eraseDisplay();
38 |
39 | displayCenteredTextLine(0, "SensorMUX");
40 | displayCenteredTextLine(1, "Multi-test");
41 | while(true)
42 | {
43 | // Read the voltage of the battery connected to the SMUX
44 | // This returns a value in mV
45 | voltage = MSSMUXreadBattery(MSSMUX);
46 |
47 | // To read from a specific channel, you must switch
48 | // to it and then set up the port for that specific sensor
49 |
50 | // We have a Mindsensors accelerometer attached to channel 1
51 | MSSMUXsetChan(MSSMUX, 1);
52 | SensorType[MSSMUX] = sensorI2CCustom;
53 | MSACreadAccel(MSSMUX, x, y, z);
54 |
55 | // We have a Angle Sensor attached to channel 2
56 | MSSMUXsetChan(MSSMUX, 2);
57 | SensorType[MSSMUX] = sensorI2CCustom;
58 | angle = MSANGreadAngle(MSSMUX);
59 |
60 | displayTextLine(3, "Batt: %d mV", voltage);
61 | displayTextLine(4, "Angle: %d deg", angle);
62 | displayTextLine(5, "Tilt: ");
63 | displayTextLine(6, "%d, %d, %d", x, y, z);
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/examples/mindsensors-touchmux-SMUX-test1.c:
--------------------------------------------------------------------------------
1 | #pragma config(Sensor, S1, HTSMUX, sensorI2CCustom)
2 | //*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
3 |
4 | /**
5 | * mindsensors-touchmux.h provides an API for the Mindsensors Touch Sensor MUX. This program
6 | * demonstrates how to use that API in combination with a HiTechnic Sensor MUX.
7 | *
8 | * The author of this program cannot be held responsible for the effects of this unholy
9 | * union. Loss of life due to universal existance failure or accidentally created
10 | * wormholes may occur. You have been warned.
11 | *
12 | * Changelog:
13 | * - 0.1: Initial release
14 | *
15 | * Credits:
16 | * - Big thanks to Mindsensors and HiTechnic for providing me with the hardware necessary to write and test this.
17 | *
18 | * License: You may use this code as you wish, provided you give credit where it's due.
19 | *
20 | * THIS CODE WILL ONLY WORK WITH ROBOTC VERSION 4.10 AND HIGHER
21 |
22 | * Xander Soldaat (xander_at_botbench.com)
23 | * 24-May-2010
24 | * version 0.1
25 | */
26 |
27 | #include "hitechnic-sensormux.h"
28 | #include "mindsensors-touchmux.h"
29 |
30 | // The sensor is connected to the first port
31 | // of the SMUX which is connected to the NXT port S1.
32 | // To access that sensor, we must use msensor_S1_1. If the sensor
33 | // were connected to 3rd port of the SMUX connected to the NXT port S4,
34 | // we would use msensor_S4_3
35 |
36 | // Give the sensor a nice easy to use name
37 | const tMUXSensor MSTMUX = msensor_S1_1;
38 |
39 | task main () {
40 | displayCenteredTextLine(0, "Mindsensors");
41 | displayCenteredBigTextLine(1, "TMUX");
42 | displayCenteredTextLine(3, "SMUX Test");
43 | displayCenteredTextLine(5, "Connect SMUX to");
44 | displayCenteredTextLine(6, "S1 and TMUX to");
45 | displayCenteredTextLine(7, "SMUX Port 1");
46 | sleep(2000);
47 |
48 | while (true) {
49 | eraseDisplay();
50 | displayTextLine(0, "MS Touch MUX");
51 |
52 | // Get the raw data from the sensor, this is not processed
53 | // by the driver in any way.
54 | displayTextLine(1, "Raw: %d", 1023 - HTSMUXreadAnalogue(MSTMUX));
55 |
56 | // Go through each possible touch switch attached to the TMUX
57 | // and display whether or not is active (pressed)
58 | for (short i = 1; i < 4; i++) {
59 | if (MSTMUXisActive(MSTMUX, i))
60 | displayTextLine(i+2, "Touch %d: on", i);
61 | else
62 | displayTextLine(i+2, "Touch %d: off", i);
63 | }
64 |
65 | // Display the binary value of the active touch switches
66 | // 0 = no touch, 1 = touch 1 active, 2 = touch 2 active, etc.
67 | // touch 1 + touch 2 active = 1 + 2 = 3.
68 | displayTextLine(7, "Status: %d", MSTMUXgetActive(MSTMUX));
69 | sleep(50);
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/examples/mindsensors-touchmux-test1.c:
--------------------------------------------------------------------------------
1 | #pragma config(Sensor, S1, MSTMUX, sensorLightInactive)
2 | //*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
3 |
4 | /**
5 | * mindsensors-touchmux.h provides an API for the Mindsensors Touch Sensor MUX. This program
6 | * demonstrates how to use that API.
7 | *
8 | * Changelog:
9 | * - 0.1: Initial release
10 | *
11 | * Credits:
12 | * - Big thanks to Mindsensors for providing me with the hardware necessary to write and test this.
13 | *
14 | * License: You may use this code as you wish, provided you give credit where it's due.
15 | *
16 | * THIS CODE WILL ONLY WORK WITH ROBOTC VERSION 4.10 AND HIGHER
17 |
18 | * Xander Soldaat (xander_at_botbench.com)
19 | * 11-May-2010
20 | * version 0.1
21 | */
22 |
23 | #include "mindsensors-touchmux.h"
24 |
25 | task main () {
26 | displayCenteredTextLine(0, "Mindsensors");
27 | displayCenteredBigTextLine(1, "TMUX");
28 | displayCenteredTextLine(3, "Test 1");
29 | displayCenteredTextLine(5, "This is for the");
30 | displayCenteredTextLine(6, "Touch MUX");
31 | sleep(2000);
32 | while (true) {
33 | eraseDisplay();
34 | displayTextLine(0, "MS Touch MUX");
35 |
36 | // Get the raw data from the sensor, this is not processed
37 | // by the driver in any way.
38 | displayTextLine(1, "Raw: %d", SensorRaw[MSTMUX]);
39 |
40 | // Go through each possible touch switch attached to the TMUX
41 | // and display whether or not is active (pressed)
42 | for (short i = 1; i < 4; i++) {
43 | if (MSTMUXisActive(MSTMUX, i))
44 | displayTextLine(i+2, "Touch %d: on", i);
45 | else
46 | displayTextLine(i+2, "Touch %d: off", i);
47 | }
48 |
49 | // Display the binary value of the active touch switches
50 | // 0 = no touch, 1 = touch 1 active, 2 = touch 2 active, etc.
51 | // touch 1 + touch 2 active = 1 + 2 = 3.
52 | displayTextLine(7, "Status: %d", MSTMUXgetActive(MSTMUX));
53 | sleep(50);
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/examples/mindsensors-touchpanel-test1.c:
--------------------------------------------------------------------------------
1 | #pragma config(Sensor, S3, MSTP, sensorI2CCustom)
2 | //*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
3 |
4 | /**
5 | * mindsensors-touchpanel.h provides an API for the Mindsensors TouchPanel. This program
6 | * demonstrates how to use that API.
7 | *
8 | * Changelog:
9 | * - 0.1: Initial release
10 | *
11 | * Credits:
12 | * - Big thanks to Mindsensors for providing me with the hardware necessary to write and test this.
13 | *
14 | * License: You may use this code as you wish, provided you give credit where it's due.
15 | *
16 | * THIS CODE WILL ONLY WORK WITH ROBOTC VERSION 4.10 AND HIGHER
17 |
18 | * Xander Soldaat (xander_at_botbench.com)
19 | * 30 November 2011
20 | * version 0.1
21 | */
22 |
23 | #include "mindsensors-touchpanel.h"
24 |
25 | task main () {
26 | displayCenteredTextLine(0, "MindSensors");
27 | displayCenteredBigTextLine(1, "TouchPnl");
28 | displayCenteredTextLine(3, "Noise-a-Tron");
29 | displayCenteredTextLine(5, "Connect sensor");
30 | displayCenteredTextLine(6, "to S3");
31 | sleep(2000);
32 | eraseDisplay();
33 |
34 | short x, y = 0;
35 | ubyte buttons = 0;
36 | short multiplierX = 10;
37 | short multiplierY = 10;
38 | while (true) {
39 | if (!MSTPgetTouch(MSTP, x, y, buttons))
40 | playSound(soundBlip);
41 | else if (isButtonTouched(buttons, BUTTON_L1))
42 | multiplierX = 10;
43 | else if (isButtonTouched(buttons, BUTTON_L2))
44 | multiplierX = 15;
45 | else if (isButtonTouched(buttons, BUTTON_L3))
46 | multiplierX = 20;
47 | else if (isButtonTouched(buttons, BUTTON_L4))
48 | multiplierX = 25;
49 | else if (isButtonTouched(buttons, BUTTON_R1))
50 | multiplierY = 10;
51 | else if (isButtonTouched(buttons, BUTTON_R2))
52 | multiplierY = 15;
53 | else if (isButtonTouched(buttons, BUTTON_R3))
54 | multiplierY = 20;
55 | else if (isButtonTouched(buttons, BUTTON_R4))
56 | multiplierY = 25;
57 |
58 | else if (x > 0 && y > 0)
59 | {
60 | playImmediateTone(x * multiplierX, 1);
61 | sleep(10);
62 | playImmediateTone(y * multiplierY, 1);
63 | setPixel(x, y);
64 | }
65 | sleep(1);
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/examples/monkey01.ric:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/botbench/robotcdriversuite/e612f3efc1f960e7363fbd3609057ca134fc82b6/examples/monkey01.ric
--------------------------------------------------------------------------------
/examples/monkey02.ric:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/botbench/robotcdriversuite/e612f3efc1f960e7363fbd3609057ca134fc82b6/examples/monkey02.ric
--------------------------------------------------------------------------------
/examples/monkey03.ric:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/botbench/robotcdriversuite/e612f3efc1f960e7363fbd3609057ca134fc82b6/examples/monkey03.ric
--------------------------------------------------------------------------------
/examples/monkey04.ric:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/botbench/robotcdriversuite/e612f3efc1f960e7363fbd3609057ca134fc82b6/examples/monkey04.ric
--------------------------------------------------------------------------------
/examples/monkey05.ric:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/botbench/robotcdriversuite/e612f3efc1f960e7363fbd3609057ca134fc82b6/examples/monkey05.ric
--------------------------------------------------------------------------------
/examples/monkey06.ric:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/botbench/robotcdriversuite/e612f3efc1f960e7363fbd3609057ca134fc82b6/examples/monkey06.ric
--------------------------------------------------------------------------------
/examples/monkey07.ric:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/botbench/robotcdriversuite/e612f3efc1f960e7363fbd3609057ca134fc82b6/examples/monkey07.ric
--------------------------------------------------------------------------------
/examples/philips-pcf8574-test1.c:
--------------------------------------------------------------------------------
1 | #pragma config(Sensor, S2, PCF8574, sensorI2CCustomFastSkipStates)
2 | //*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
3 |
4 | /**
5 | * philips-pcf8574.h provides an API for the Philips PCF8574 IO MUX. This program
6 | * demonstrates how to use that API.
7 | *
8 | * Changelog:
9 | * - 0.1: Initial release
10 | *
11 | * Credits:
12 | * - Big thanks to Mindsensors for providing me with the hardware necessary to write and test this.
13 | *
14 | * License: You may use this code as you wish, provided you give credit where it's due.
15 | *
16 | * THIS CODE WILL ONLY WORK WITH ROBOTC VERSION 4.10 AND HIGHER
17 |
18 | * Xander Soldaat (xander_at_botbench.com)
19 | * 30 March 2010
20 | * version 0.1
21 | */
22 |
23 | #include "philips-pcf8574.h"
24 |
25 | task main () {
26 | while (true) {
27 | for (short i = 0; i < 8; i++) {
28 | short foo = 1 << i;
29 | foo = ~foo;
30 | PCF8574sendBytes(PCF8574, foo);
31 | sleep(50);
32 | }
33 | for (short i = 7; i > -1; i--) {
34 | short foo = 1 << i;
35 | foo = ~foo;
36 | PCF8574sendBytes(PCF8574, foo);
37 | sleep(50);
38 | }
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/examples/stats-test1.c:
--------------------------------------------------------------------------------
1 | #include "stats.h"
2 |
3 | task main () {
4 | float x_Phi = 0.0; // should be 0.494233933 according to Excel
5 | float X_val = -20;
6 | float X_mean = -19.80093313; // mu
7 | float X_std = 13.77254704; // sigma
8 |
9 | x_Phi = Phi(X_val, X_mean, X_std);
10 |
11 | displayTextLine(2, "Phi(x): %f", x_Phi);
12 | while(nNxtButtonPressed != kEnterButton) sleep(1);
13 | }
14 |
--------------------------------------------------------------------------------
/examples/sumoLF.ric:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/botbench/robotcdriversuite/e612f3efc1f960e7363fbd3609057ca134fc82b6/examples/sumoLF.ric
--------------------------------------------------------------------------------
/examples/sumoLL.ric:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/botbench/robotcdriversuite/e612f3efc1f960e7363fbd3609057ca134fc82b6/examples/sumoLL.ric
--------------------------------------------------------------------------------
/examples/sumoLR.ric:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/botbench/robotcdriversuite/e612f3efc1f960e7363fbd3609057ca134fc82b6/examples/sumoLR.ric
--------------------------------------------------------------------------------
/examples/sumoSF.ric:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/botbench/robotcdriversuite/e612f3efc1f960e7363fbd3609057ca134fc82b6/examples/sumoSF.ric
--------------------------------------------------------------------------------
/examples/sumoSL.ric:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/botbench/robotcdriversuite/e612f3efc1f960e7363fbd3609057ca134fc82b6/examples/sumoSL.ric
--------------------------------------------------------------------------------
/examples/sumoSR.ric:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/botbench/robotcdriversuite/e612f3efc1f960e7363fbd3609057ca134fc82b6/examples/sumoSR.ric
--------------------------------------------------------------------------------
/examples/sumonone.ric:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/botbench/robotcdriversuite/e612f3efc1f960e7363fbd3609057ca134fc82b6/examples/sumonone.ric
--------------------------------------------------------------------------------
/examples/timer-test1.c:
--------------------------------------------------------------------------------
1 |
2 |
3 | /** \file timer.h
4 | * \brief Additional timers for ROBOTC.
5 | *
6 | * timer.h provides additional timers for ROBOTC. Please note that there is no
7 | * roll-over checking done at all. That means that if the program runs for more than
8 | * around 596 hours, it will roll over and weird stuff will happen.
9 | *
10 | * The default number of timers is 10, but this can be changed by defining MAX_TIMERS
11 | * before this driver is included.
12 | *
13 | * License: You may use this code as you wish, provided you give credit where its due.
14 | * THIS CODE WILL ONLY WORK WITH ROBOTC VERSION 4.10 AND HIGHER
15 |
16 | *
17 | * Changelog:
18 | * - 0.1: Initial release
19 | *
20 | * \author Xander Soldaat (xander_at_botbench.com)
21 | * \date 18 May 2010
22 | * \version 0.1
23 | * \example TMR-test1.c
24 | */
25 |
26 | #include "timer.h"
27 |
28 | task main () {
29 |
30 | // Create two new timer index numbers
31 | short timer1 = TMRnewTimer();
32 | short timer2 = TMRnewTimer();
33 |
34 | // Configure timer1 for 2000ms
35 | TMRsetup(timer1, 2000);
36 |
37 | // Configure timer2 for 5000ms
38 | TMRsetup(timer2, 5000);
39 |
40 | // Reset and start both timers
41 | TMRreset(timer1);
42 | TMRreset(timer2);
43 |
44 | while (true) {
45 | // If timer1 expires, make a small noise and reset it.
46 | if (TMRisExpired(timer1)) {
47 | playSound(soundBlip);
48 | while(bSoundActive) sleep(1);
49 | TMRreset(timer1);
50 | }
51 |
52 | // If timer2 expires, make a small noise and reset it.
53 | if (TMRisExpired(timer2)) {
54 | playSound(soundShortBlip);
55 | while(bSoundActive) sleep(1);
56 | TMRreset(timer2);
57 | }
58 | sleep(1);
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/header.txt:
--------------------------------------------------------------------------------
1 |
2 |
3 | 3rd Party ROBOTC Drivers
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/include/codatech-rfid.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/botbench/robotcdriversuite/e612f3efc1f960e7363fbd3609057ca134fc82b6/include/codatech-rfid.h
--------------------------------------------------------------------------------
/include/common-light.h:
--------------------------------------------------------------------------------
1 | /*!@addtogroup common_includes
2 | * @{
3 | * @defgroup light-common_h Light Functions
4 | * Functions common to light sensor drivers
5 | * @{
6 | */
7 |
8 | #ifndef __LIGHT_COMMON_H__
9 | #define __LIGHT_COMMON_H__
10 |
11 | #ifndef __COMMON_H__
12 | #include "common.h"
13 | #endif
14 |
15 | /** \file common-light.h
16 | * \brief Functions common to light sensor drivers
17 | *
18 | * common-light.h holds functions common to light sensor drivers.
19 | * Contains code to convert from RGB colors to HSV colors.
20 | *
21 | * \author Mike Henning, Max Bareiss
22 | * \author Xander Soldaat (minor modifications)
23 | * \date 27 April 2011
24 | */
25 |
26 | #pragma systemFile
27 |
28 | /**
29 | * Convert RGB colors to HSV
30 | * @param red the red input value
31 | * @param green the green input value
32 | * @param blue the blue input value
33 | * @param hue the hue output value (from 0 to 360, or -1 if n/a)
34 | * @param sat the saruration output value (from 0 to 100, or -1 if n/a)
35 | * @param value the value output value (from 0 to 100)
36 | * @return void
37 | */
38 | void RGBtoHSV(float red, float green, float blue, float *hue, float *sat, float *value)
39 | {
40 | *hue = 0;
41 | *sat = 0;
42 | *value = 0;
43 |
44 | // Value
45 | float rgb_max = max3(red, green, blue);
46 | float rgb_min;
47 | *value = rgb_max / 2.56;
48 | if ((value == 0) || (rgb_max == 0)){
49 | *hue = -1;
50 | *sat = -1;
51 | return;
52 | }
53 |
54 | // Saturation
55 | red /= rgb_max;
56 | green /= rgb_max;
57 | blue /= rgb_max;
58 |
59 | rgb_max = max3(red, green, blue);
60 | rgb_min = min3(red, green, blue);
61 | *sat = (rgb_max - rgb_min) * 100;
62 | if (*sat == 0){
63 | *hue = -1;
64 | return;
65 | }
66 |
67 | // Hue
68 |
69 | red = (red - rgb_min) / (rgb_max - rgb_min);
70 | green = (green - rgb_min) / (rgb_max - rgb_min);
71 | blue = (blue - rgb_min) / (rgb_max - rgb_min);
72 |
73 | rgb_max = max3(red, green,blue);
74 | rgb_min = min3(red, green,blue);
75 |
76 | if (rgb_max == red){
77 | *hue = 0.0 + 60.0*(green-blue);
78 | if (*hue < 0.0){
79 | *hue += 360.0;
80 | }
81 | } else if (rgb_max == green){
82 | *hue = 120.0 + 60.0 * (blue-red);
83 | } else {
84 | *hue = 240.0 + 60.0 * (red-green);
85 | }
86 | }
87 |
88 | #endif __LIGHT_COMMON_H__
89 |
90 | /* @} */
91 | /* @} */
92 |
--------------------------------------------------------------------------------
/include/common-mmux.h:
--------------------------------------------------------------------------------
1 | /*!@addtogroup common_includes
2 | * @{
3 | * @defgroup MMUX-common_h MMUX Functions
4 | * Commonly used types and defines used by Motor MUX drivers.
5 | * @{
6 | */
7 |
8 | /** \file common-MMUX.h
9 | * \brief Commonly used types and defines used by Motor MUX drivers.
10 | *
11 | * common-MMUX.h provides a number of frequently used types and defines that are useful for writing
12 | * Motor MUX drivers.
13 | *
14 | * License: You may use this code as you wish, provided you give credit where its due.
15 | *
16 | * THIS CODE WILL ONLY WORK WITH ROBOTC VERSION 4.10 AND HIGHER
17 |
18 | *
19 | * Changelog:
20 | * - 0.1: Initial release split from common.h
21 | *
22 | * \author Xander Soldaat (xander_at_botbench.com)
23 | * \date 18 January 2011
24 | * \version 0.1
25 | */
26 |
27 | #pragma systemFile
28 |
29 | #ifndef __MMUX_H__
30 | #define __MMUX_H__
31 |
32 | #ifndef SPORT
33 | #define SPORT(X) X / 4 /*!< Convert tMUXSensor to sensor port number */
34 | #endif
35 |
36 | #ifndef MPORT
37 | #define MPORT(X) X % 4 /*!< Convert tMUXSensor to MUX port number */
38 | #endif
39 |
40 | /*!< Struct to hold MMUX info */
41 | typedef struct {
42 | bool initialised; /*!< Has the MMUX been initialised yet? */
43 | bool runToTarget[4]; /*!< Indicate whether or not the motor is running to a target */
44 | long target[4]; /*!< Target we want the motor to run to */
45 | byte targetUnit[4]; /*!< Type of target we're running to, could be rotation, encoder or seconds */
46 | bool relTarget[4]; /*!< Whether or not the target is relative to current position */
47 | bool brake[4]; /*!< Whether or not to use braking or floating to stop motor */
48 | bool pidcontrol[4]; /*!< Use constant speed or just power control */
49 | byte ramping[4]; /*!< Ramp the motors, can be up, down, both */
50 | } mmuxDataT, tMMUXData;
51 |
52 | /*!< MUXmotor type, one for each permutation
53 | *
54 | * - mmotor_S1_1 means motor 1 connected to MMUX attached to sensor port 1
55 | * - mmotor_S4_2 means motor 2 connedted to MMUX attached to sensor port 4
56 | */
57 | typedef enum tMUXmotor {
58 | mmotor_S1_1 = 0,
59 | mmotor_S1_2 = 1,
60 | mmotor_S1_3 = 2,
61 | mmotor_S1_4 = 3,
62 | mmotor_S2_1 = 4,
63 | mmotor_S2_2 = 5,
64 | mmotor_S2_3 = 6,
65 | mmotor_S2_4 = 7,
66 | mmotor_S3_1 = 8,
67 | mmotor_S3_2 = 9,
68 | mmotor_S3_3 = 10,
69 | mmotor_S3_4 = 11,
70 | mmotor_S4_1 = 12,
71 | mmotor_S4_2 = 13,
72 | mmotor_S4_3 = 14,
73 | mmotor_S4_4 = 15
74 | } tMUXmotor;
75 |
76 | mmuxDataT mmuxData[4]; /*!< Holds all the MMUX info, one for each sensor port */
77 |
78 | #endif // __MMUX_H__
79 |
80 | /* @} */
81 | /* @} */
82 |
--------------------------------------------------------------------------------
/include/dexterind-compass.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/botbench/robotcdriversuite/e612f3efc1f960e7363fbd3609057ca134fc82b6/include/dexterind-compass.h
--------------------------------------------------------------------------------
/include/lego-sound.h:
--------------------------------------------------------------------------------
1 | /*!@addtogroup lego
2 | * @{
3 | * @defgroup legosnd Sound Sensor
4 | * Sound Sensor
5 | * @{
6 | */
7 |
8 | /** \file lego-sound.h
9 | * \brief SMUX driver for the Lego Sound sensor.
10 | *
11 | * lego-sound.h provides an API for the Lego Sound driver.
12 | *
13 | * Changelog:
14 | * - 0.1: Initial release
15 | * - 0.2: Make use of new calls for analogue SMUX sensors in common.h
16 | *
17 | * License: You may use this code as you wish, provided you give credit where its due.
18 | *
19 | * THIS CODE WILL ONLY WORK WITH ROBOTC VERSION 4.10 AND HIGHER
20 |
21 | * \author Xander Soldaat (xander_at_botbench.com)
22 | * \date 25 November 2009
23 | * \version 0.2
24 | * \example lego-sound-SMUX-test1.c
25 | */
26 |
27 | #pragma systemFile
28 |
29 | #ifndef __COMMON_H__
30 | #include "common.h"
31 | #endif
32 |
33 | #ifdef __HTSMUX_SUPPORT__
34 | short SNDreadRaw(tMUXSensor muxsensor);
35 | short SNDreadNorm(tMUXSensor muxsensor);
36 | void SNDsetDBA(tMUXSensor muxsensor);
37 | void SNDsetDB(tMUXSensor muxsensor);
38 |
39 | /**
40 | * Get the raw value from the sensor
41 | * @param muxsensor the SMUX sensor port number
42 | * @return the raw value of the Sound Sensor
43 | */
44 | short SNDreadRaw(tMUXSensor muxsensor) {
45 | return 1023 - HTSMUXreadAnalogue(muxsensor);
46 | }
47 |
48 | /**
49 | * Get the processed value from the sensor.
50 | * @param muxsensor the SMUX sensor port number
51 | * @return processed value of the sensor or -1 if no valid range has been specified.
52 | */
53 | short SNDreadNorm(tMUXSensor muxsensor) {
54 | short _val = ((long)SNDreadRaw(muxsensor) * (long)100) / (long)1024;
55 | return _val;
56 | }
57 |
58 | /**
59 | * Set the mode of the sensor to DBA, this is done
60 | * by switching off DIG0.
61 | * @param muxsensor the SMUX sensor port number
62 | */
63 | void SNDsetDBA(tMUXSensor muxsensor) {
64 | HTSMUXsetAnalogueInactive(muxsensor);
65 | }
66 |
67 | /**
68 | * Set the mode of the sensor to DB, this is done
69 | * by switching on DIG0.
70 | * @param muxsensor the SMUX sensor port number
71 | */
72 | void SNDsetDB(tMUXSensor muxsensor) {
73 | HTSMUXsetAnalogueActive(muxsensor);
74 | }
75 | #endif // __HTSMUX_SUPPORT__
76 |
77 | /* @} */
78 | /* @} */
79 |
--------------------------------------------------------------------------------
/include/lego-touch.h:
--------------------------------------------------------------------------------
1 | /*!@addtogroup lego
2 | * @{
3 | * @defgroup legots Touch Sensor
4 | * Touch Sensor
5 | * @{
6 | */
7 |
8 | #ifndef __LEGOTS_H__
9 | #define __LEGOTS_H__
10 | /** \file lego-touch.h
11 | * \brief Lego Touch Sensor driver
12 | *
13 | * lego-touch.h provides an API for the Lego Touch Sensor.
14 | *
15 | * Changelog:
16 | * - 0.1: Initial release
17 | *
18 | * License: You may use this code as you wish, provided you give credit where its due.
19 | *
20 | * THIS CODE WILL ONLY WORK WITH ROBOTC VERSION 4.10 AND HIGHER
21 |
22 | * \author Xander Soldaat (xander_at_botbench.com)
23 | * \date 08 December 2009
24 | * \version 0.1
25 | * \example lego-touch-test1.c
26 | * \example lego-touch-SMUX-test1.c
27 | */
28 |
29 | #pragma systemFile
30 |
31 | #ifndef __COMMON_H__
32 | #include "common.h"
33 | #endif
34 |
35 | // Function prototypes
36 | bool TSreadState(tSensors link);
37 |
38 | #ifdef __HTSMUX_SUPPORT__
39 | bool TSreadState(tMUXSensor muxsensor);
40 | #endif
41 |
42 | /**
43 | * Read the state of the touch sensor
44 | * @param link the Touch Sensor port number
45 | * @return true if the sensor is pressed, false if it's not
46 | */
47 | bool TSreadState(tSensors link) {
48 | if ((SensorType[link] != sensorTouch) && SensorMode[link] != modeBoolean) {
49 | SensorType[link] = sensorTouch ;
50 | SensorMode[link] = modeBoolean;
51 | sleep(10);
52 | }
53 |
54 | return (SensorRaw[link] < 500) ? true : false;
55 | }
56 |
57 | /**
58 | * Read the state of the touch sensor
59 | * @param muxsensor the SMUX sensor port number
60 | * @return true if the sensor is pressed, false if it's not
61 | */
62 | #ifdef __HTSMUX_SUPPORT__
63 | bool TSreadState(tMUXSensor muxsensor) {
64 | return (HTSMUXreadAnalogue(muxsensor) < 500) ? true : false;
65 | }
66 | #endif
67 |
68 | #endif // __LEGOTS_H__
69 |
70 | /* @} */
71 | /* @} */
72 |
--------------------------------------------------------------------------------
/include/philips-pcf8574.h:
--------------------------------------------------------------------------------
1 | /*!@addtogroup other
2 | * @{
3 | * @defgroup pcf8574 Philips PCF8574
4 | * Philips PCF8574
5 | * @{
6 | */
7 |
8 | #ifndef __PCF8574_H__
9 | #define __PCF8574_H__
10 | /** \file philips-pcf8574.h
11 | * \brief Philips PCF8574 IO MUX driver
12 | *
13 | * philips-pcf8574.h provides an API for the Philips PCF8574 IO MUX.
14 | *
15 | * Changelog:
16 | * - 0.1: Initial release
17 | *
18 | * Credits:
19 | * - Big thanks to Mindsensors for providing me with the hardware necessary to write and test this.
20 | *
21 | * License: You may use this code as you wish, provided you give credit where its due.
22 | *
23 | * THIS CODE WILL ONLY WORK WITH ROBOTC VERSION 4.10 AND HIGHER
24 |
25 | * \author Xander Soldaat (xander_at_botbench.com)
26 | * \date 30 March 2010
27 | * \version 0.1
28 | * \example philips-pcf8574-test1.c
29 | */
30 |
31 | #pragma systemFile
32 |
33 | #ifndef __COMMON_H__
34 | #include "common.h"
35 | #endif
36 |
37 | #define PCF8574_I2C_ADDR 0x70 /*!< HDMMUX I2C device address */
38 |
39 | tByteArray PCF8574_I2CRequest; /*!< Array to hold I2C command data */
40 | tByteArray PCF8574_I2CReply; /*!< Array to hold I2C reply data */
41 |
42 | // Function prototypes
43 | bool PCF8574sendBytes(tSensors link, ubyte _byte);
44 | bool PCF8574readBytes(tSensors link, ubyte &_byte);
45 |
46 | /**
47 | * Send a byte to the PCF8574 to set the IO ports
48 | *
49 | * @param link the PCF8574 port number
50 | * @param _byte the byte to be sent
51 | * @return true if no error occured, false if it did
52 | */
53 | bool PCF8574sendBytes(tSensors link, ubyte _byte) {
54 | memset(PCF8574_I2CRequest, 0, sizeof(tByteArray));
55 |
56 | PCF8574_I2CRequest[0] = 2; // Message size
57 | PCF8574_I2CRequest[1] = PCF8574_I2C_ADDR; // I2C Address
58 | PCF8574_I2CRequest[2] = _byte;
59 |
60 | return writeI2C(link, PCF8574_I2CRequest);
61 | }
62 |
63 | /**
64 | * Read the current state of the ports on the PCF8574
65 | *
66 | * @param link the PCF8574 port number
67 | * @param _byte the byte thats been read
68 | * @return true if no error occured, false if it did
69 | */
70 | bool PCF8574readBytes(tSensors link, ubyte &_byte) {
71 | memset(PCF8574_I2CRequest, 0, sizeof(tByteArray));
72 |
73 | PCF8574_I2CRequest[0] = 1; // Message size
74 | PCF8574_I2CRequest[1] = PCF8574_I2C_ADDR; // I2C Address
75 | PCF8574_I2CRequest[2] = _byte;
76 |
77 | if (!writeI2C(link, PCF8574_I2CRequest, PCF8574_I2CReply, 1))
78 | return false;
79 |
80 | _byte = PCF8574_I2CReply[0];
81 |
82 | return true;
83 |
84 | }
85 |
86 | #endif // __PCF8574_H__
87 |
88 | /* @} */
89 | /* @} */
90 |
--------------------------------------------------------------------------------
/scripts/batch-cleanup.pl:
--------------------------------------------------------------------------------
1 | #!/usr/bin/perl -w
2 | use strict;
3 | use warnings;
4 |
5 | my $inputFile = $ARGV[0]; #read first argument from the commandline as fileName
6 | print "$inputFile\n";
7 | open INPUTFILE, "+<", $inputFile or die $!; #Open File
8 |
9 | my $data = do { local $/ = undef; };
10 | close (INPUTFILE);
11 |
12 | # strip the dos end of line character
13 | $data =~ s/
//sg;
14 |
15 | # strip the $Id tags that span multiple lines
16 | $data =~ s/\/[^\/]+\$Id:[^\/]+\///sg;
17 |
18 | # Get rid of multiple empty lines
19 | $data =~ s/\n[\s]*\n[\s]*\n/\n\n/sg;
20 |
21 | # Remove the empty line at the end of the file
22 | $data =~ s/\n[\s]*\n$/\n/sg;
23 |
24 | # Replace the tabs with two spaces
25 | $data =~ s/ / /sg;
26 |
27 | # Add the DOS end of line character again
28 | $data =~ s/\n/
\n/sg;
29 |
30 | my $outputFile = $inputFile;
31 | open OUTPUTFILE, ">", $outputFile or die $!; #Open File
32 | print OUTPUTFILE $data;
33 | close (OUTPUTFILE);
34 |
--------------------------------------------------------------------------------
/scripts/migrate-types.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | for file in `find -type f -name "*.c" -or -name "*.h"`;
4 | do
5 | echo "$file"
6 | sed -i 's/\bint\b/short/' $file
7 | sed -i 's/\bint\b/short/' $file
8 | sed -i 's/ int / short /' $file
9 | done
10 |
--------------------------------------------------------------------------------
/scripts/run-batch-cleanup.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | # Absolute path to this script. /home/user/bin/foo.sh
4 | SCRIPT=$(readlink -f $0)
5 | # Absolute path this script is in. /home/user/bin
6 | SCRIPTPATH=`dirname $SCRIPT`
7 |
8 | for file in `find -type f -name "*.c" -or -name "*.h"`;
9 | do
10 | perl $SCRIPTPATH/batch-cleanup.pl $file
11 | done
12 |
--------------------------------------------------------------------------------
/status_drivers.xlsx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/botbench/robotcdriversuite/e612f3efc1f960e7363fbd3609057ca134fc82b6/status_drivers.xlsx
--------------------------------------------------------------------------------