ColorLED.gph : Control the LED of your Controller / T2
Posted: Mon Dec 03, 2018 5:47 pm
This code adds the function "ColorLED ( Color, BlinkOnTime, BlinkOffTime, BlinkCount, PostColor )"
to control the LED of your Controller / Titan Two.
Usage:
Download the Headerfile "ColorLED.gph" from the Online Resource.
Place this file into the same directory where your script file is.
Add this line to your script:
! Do not call this function on every interaction of main !
Only call it when you want to change the LED.
If you understand this you will have no trouble with the led, rumble or segment display control functions.
Correct:
Correct too:
Wrong:
Wrong too:
The color names / numbers:
Example function calls:
Blink in Color Green 200ms on / 200ms off, 2 times and reset the LED :
Blink in Color Purple 100ms on / 100ms off, 4 times and set the LED to Green :
Permanent Color Red:
to control the LED of your Controller / Titan Two.
Usage:
Download the Headerfile "ColorLED.gph" from the Online Resource.
Place this file into the same directory where your script file is.
Add this line to your script:
- Code: Select all
#include "ColorLED.gph"
! Do not call this function on every interaction of main !
Only call it when you want to change the LED.
If you understand this you will have no trouble with the led, rumble or segment display control functions.
Correct:
- Code: Select all
bool Toggle=FALSE;
main {
if (event_active(BUTTON_10)) ColorLED(CB,100,100,4); // blink 4x Blue, each with 100ms ON and 100ms OFF, after blinking it calls led_reset();
if (event_active(BUTTON_11)) { // toggle state change, this will only be run once on every change of the toggle state
Toggle=!Toggle;
if (Toggle) ColorLED(CG,200,200,2,CB); // blink 2x Green, each with 200ms ON and 200ms OFF, after blinking set it to Blue
else ColorLED(CR,200,200,2,CB); // blink 2x Green, each with 200ms ON and 200ms OFF, after blinking set it to Blue
}
if (Toggle) {
// put here the real code that should be run as long as the toggle is active
}
}
Correct too:
- Code: Select all
main {
if (event_active(BUTTON_5)) ColorLED(CR); // sets the color to red permanent/not blinking
}
Wrong:
- Code: Select all
bool Toggle=FALSE;
main {
// this part is still correct
if (event_active(BUTTON_10)) ColorLED(CB,100,100,4); // blink 4x Blue, each with 100ms ON and 100ms OFF, after blinking it calls led_reset();
if (event_active(BUTTON_11)) Toggle=!Toggle;
// this is where the bad things happen, ColorLED will be run all the time
if (Toggle) {
ColorLED(CG,200,200,2,CB); // WRONG: while TOGGLE is TRUE it will run the ColorLED function over and over again,
// crashing the T2 or resulting in disconnects of your controller
// put here the real code that should be run when the toggle is active
} else {
ColorLED(CR,200,200,2,CB); // WRONG: while TOGGLE is FALSE it will run the ColorLED function over and over again,
// crashing the T2 or resulting in disconnects of your controller
}
}
Wrong too:
- Code: Select all
main {
// bad, issue: sets the color to red permanent/not blinking each ms or faster as long as the button is pressed.
if (get_val(BUTTON_5)) ColorLED(CR);
}
The color names / numbers:
- Code: Select all
CB 1 // blue
CR 5 // red
CG 9 // green
CP 13 // purple
CC 17 // cyan
CA 21 // amber
CW 25 // white
Example function calls:
Blink in Color Green 200ms on / 200ms off, 2 times and reset the LED :
- Code: Select all
ColorLED(CG,200,200,2);
Blink in Color Purple 100ms on / 100ms off, 4 times and set the LED to Green :
- Code: Select all
ColorLED(CP,100,100,4,CG);
Permanent Color Red:
- Code: Select all
ColorLED(CR);