-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdexterind-dlight-test1.c
120 lines (100 loc) · 3.19 KB
/
dexterind-dlight-test1.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#pragma config(Sensor, S1, DLIGHT, sensorI2CCustomFastSkipStates)
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
/*
* $Id: dexterind-dlight-test1.c 133 2013-03-10 15:15:38Z xander $
*/
/**
* dexterind-dlight.h provides an API for the Dexter In Angle Sensor. This program
* demonstrates how to use that API.
*
* Changelog:
* - 0.1: Initial release
*
* Credits:
* - Big thanks to Mindsensors for providing me with the hardware necessary to write and test this.
*
* License: You may use this code as you wish, provided you give credit where it's due.
*
* THIS CODE WILL ONLY WORK WITH ROBOTC VERSION 3.59 AND HIGHER.
* Xander Soldaat (xander_at_botbench.com)
* date 31 November 2012
* version 0.1
*/
#include "drivers/dexterind-dlight.h"
task main()
{
int max = 200;
// Initialise all of the dLights
DLIGHTinit(DLIGHT, DLIGHT_I2C_ADDR_ALL);
wait1Msec(50);
// Make all the lights white
DLIGHTsetColor(DLIGHT, DLIGHT_I2C_ADDR_ALL, 0xFF, 0xFF, 0xFF);
wait1Msec(1000);
// Make all of the lights red
DLIGHTsetColor(DLIGHT, DLIGHT_I2C_ADDR_ALL, 0xFF, 0, 0);
wait1Msec(1000);
// Make all of the lights...green
DLIGHTsetColor(DLIGHT, DLIGHT_I2C_ADDR_ALL, 0, 0xFF, 0);
wait1Msec(1000);
// Make all of the lights, you guessed it, red, no wait, blue!
DLIGHTsetColor(DLIGHT, DLIGHT_I2C_ADDR_ALL, 0, 0, 0xFF);
wait1Msec(1000);
// Make a nice sort of rainbow effect by cycling through colours
for (int value = 0; value < max; value++)
{
int midpoint = max / 2;
int currvalue = max - value;
int red = 0;
int green = 0;
int blue = 0;
if (currvalue <= midpoint)
{
red = 255 - ((255 / midpoint) * currvalue);
green = (255 / (midpoint) * currvalue);
blue = 0;
}
else
{
red = 0;
green = 255 - ((255 / midpoint) * (currvalue - midpoint));
blue = 255 / (midpoint) * (currvalue - (midpoint));
}
if (red < 0 || red > 255)
red = 0;
if (green < 0 || green > 255)
green = 0;
if (blue < 0 || blue > 255)
blue = 0;
DLIGHTsetColor(DLIGHT, DLIGHT_I2C_ADDR_ALL, red, green, blue);
wait1Msec(50);
}
// Make the lights blink!
// Configure for 1 Hz with a 10% duty rate
DLIGHTsetBlinking(DLIGHT, DLIGHT_I2C_ADDR_ALL, 1, 10);
wait1Msec(10);
// Set the colour
DLIGHTsetColor(DLIGHT, DLIGHT_I2C_ADDR_ALL, 0, 0xFF, 0xFF);
wait1Msec(10);
// Start blinking!
DLIGHTstartBlinking(DLIGHT, DLIGHT_I2C_ADDR_ALL);
wait1Msec(5000);
// Stop the blinking
DLIGHTstopBlinking(DLIGHT, DLIGHT_I2C_ADDR_ALL);
wait1Msec(10);
// Turn off all of the
DLIGHTdisable(DLIGHT, DLIGHT_I2C_ADDR_ALL);
//DLIGHTsetColor(DLIGHT, DLIGHT_I2C_ADDR_1, 0xFF, 0, 0);
//wait1Msec(500);
//DLIGHTstartBlinking(DLIGHT, DLIGHT_I2C_ADDR_1);
//DLIGHTsetColor(DLIGHT, DLIGHT_I2C_ADDR_2, 0, 0xFF, 0);
//wait1Msec(500);
//DLIGHTstartBlinking(DLIGHT, DLIGHT_I2C_ADDR_2);
//DLIGHTsetColor(DLIGHT, DLIGHT_I2C_ADDR_3, 0, 0, 0xFF);
//wait1Msec(500);
//DLIGHTstartBlinking(DLIGHT, DLIGHT_I2C_ADDR_3);
//DLIGHTsetColor(DLIGHT, DLIGHT_I2C_ADDR_4, 0xFF, 0xFF, 0xFF);
//wait1Msec(500);
//DLIGHTstartBlinking(DLIGHT, DLIGHT_I2C_ADDR_4);
//wait1Msec(2000);
//DLIGHTstopBlinking(DLIGHT, DLIGHT_I2C_ADDR_ALL);
}