-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmindsensors-sensormux-test2.c
89 lines (78 loc) · 2.52 KB
/
mindsensors-sensormux-test2.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#pragma config(Sensor, S1, MSSMUX, sensorI2CCustom)
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
/*
* $Id: mindsensors-sensormux-test2.c 133 2013-03-10 15:15:38Z xander $
*/
/**
* mindsensors-sensormux.h provides an API for the Mindsensors SensorMUX Sensor.
* This program demonstrates how to create a small disco party in your LEGO room
*
* Changelog:
* - 0.1: Initial release
*
* Credits:
* - Big thanks to Mindsensors for providing me with the hardware necessary to write and test this.
*
* License: You may use this code as you wish, provided you give credit where it's due.
*
* THIS CODE WILL ONLY WORK WITH ROBOTC VERSION 3.59 AND HIGHER.
* Xander Soldaat (xander_at_botbench.com)
* 30 March 2010
* version 0.1
*/
// Copy these to your brick
#define MONNKEY01 "monkey01.ric"
#define MONNKEY02 "monkey02.ric"
#define MONNKEY03 "monkey03.ric"
#define MONNKEY04 "monkey04.ric"
#define MONNKEY05 "monkey05.ric"
#define MONNKEY06 "monkey06.ric"
#define MONNKEY07 "monkey07.ric"
#include "drivers/mindsensors-sensormux.h"
tSensors disco[] = {sensorCOLORGREEN, sensorCOLORBLUE, sensorCOLORRED};
task danceMOnkeyDance()
{
const int X_COORD = 30;
const int Y_COORD = 0;
const int WAITTIME = 100;
while (true) {
nxtDisplayRICFile(X_COORD,Y_COORD, MONNKEY01);
wait1Msec(WAITTIME);
nxtDisplayRICFile(X_COORD,Y_COORD, MONNKEY02);
wait1Msec(WAITTIME);
nxtDisplayRICFile(X_COORD,Y_COORD, MONNKEY03);
wait1Msec(WAITTIME);
nxtDisplayRICFile(X_COORD,Y_COORD, MONNKEY04);
wait1Msec(WAITTIME);
nxtDisplayRICFile(X_COORD,Y_COORD, MONNKEY05);
wait1Msec(WAITTIME);
nxtDisplayRICFile(X_COORD,Y_COORD, MONNKEY06);
wait1Msec(WAITTIME);
nxtDisplayRICFile(X_COORD,Y_COORD, MONNKEY07);
wait1Msec(WAITTIME);
}
}
task main()
{
long counter = 0;
nxtDisplayCenteredTextLine(0, "Mindsensors");
nxtDisplayCenteredBigTextLine(1, "SnsrMUX");
nxtDisplayCenteredTextLine(3, "Test 2");
nxtDisplayCenteredTextLine(5, "Connect LEGO");
nxtDisplayCenteredTextLine(6, "Color Sensors");
nxtDisplayCenteredTextLine(7, "to ports 1-4");
wait1Msec(2000);
eraseDisplay();
StartTask(danceMOnkeyDance);
// Let's get the party started!
while(true)
{
// Set the channel to a random one
MSSMUXsetChan(MSSMUX, (counter++%4) + 1);
// Set the sensor to a random colour, R, G or B
SetSensorType(MSSMUX, disco[abs(rand() % 3)]);
// Wait a random time before switching
wait1Msec(abs(rand() % 100) + 100);
// Do a little dance!
}
}