DualShock 4 LED Bar Color Toggles with Recall

This script is similar to the previous one, except that this script will remember your previous color and can be used with other scripts to maintain the same color when changing memory slots. To toggle forward through colors, tap TRIANGLE; to toggle backward, tap CROSS.
Version1.0
Authorperfecthuntr
Publish DateMon, 27 Apr 2015 - 03:08
Last UpdateMon, 27 Apr 2015 - 03:08
Downloads81
ForumAnnouncement Topic
RATE


4

0

Code: Select all
/* =============================================================================================================================================
* Controller:           DualShock 4
* GPC Author:           PerfectHuntr
**/

 
/* ---------------------------------------------------------------------------------------------------------------------------------------------
* LED COLOR DEFINITIONS FOR PS4
* fSetLED(0,0,0,0); // Off
* fSetLED(1,0,0,0); // Blue
* fSetLED(0,1,0,0); // Red
* fSetLED(0,0,1,0); // Green
* fSetLED(0,0,0,1); // Pink
* fSetLED(1,0,1,0); // Cyan
* fSetLED(0,1,1,0); // Amber
* fSetLED(1,1,1,1); // White
**/

 
/* -----------------------------------------------------------------------------
 *  VARIABLES
**/

int a, b, c, d, i, change;
 
/* -----------------------------------------------------------------------------
 *  INITIALIZATION
**/

init {
    a = get_pvar(PVAR_1, 0, 1, 0);
    b = get_pvar(PVAR_2, 0, 1, 0);
    c = get_pvar(PVAR_3, 0, 1, 0);
    d = get_pvar(PVAR_4, 0, 1, 0);
    if      (a == 0 && b == 1 && c == 0 && d == 0) { i = 0; }
    else if (a == 0 && b == 1 && c == 1 && d == 0) { i = 1; }
    else if (a == 0 && b == 0 && c == 1 && d == 0) { i = 2; }
    else if (a == 1 && b == 0 && c == 0 && d == 0) { i = 3; }
    else if (a == 1 && b == 0 && c == 1 && d == 0) { i = 4; }
    else if (a == 0 && b == 0 && c == 0 && d == 1) { i = 5; }
    else if (a == 1 && b == 1 && c == 1 && d == 1) { i = 6; }
    color(i);
}
 
/* ---------------------------------------------------------------------------------------------------------------------------------------------
* MAIN SCRIPT
**/

main {
    if (event_press(PS4_TRIANGLE))   { i = i+1; change = 1; }
    else if (event_press(PS4_CROSS)) { i = i-1; change = 1; }
    if      (i < 0) { i = 6; }
    else if (i > 6) { i = 0; }
    if (change) { change = 0; color(i); }
}
 
/* ---------------------------------------------------------------------------------------------------------------------------------------------
* FUNCTIONS
**/

// Color Lookup
function color(a) {
    if      (i == 0) { fSetLED(0,1,0,0); } // Red
    else if (i == 1) { fSetLED(0,1,1,0); } // Amber
    else if (i == 2) { fSetLED(0,0,1,0); } // Green
    else if (i == 3) { fSetLED(1,0,0,0); } // Blue
    else if (i == 4) { fSetLED(1,0,1,0); } // Cyan
    else if (i == 5) { fSetLED(0,0,0,1); } // Magenta
    else if (i == 6) { fSetLED(1,1,1,1); } // White
}
 
// LED function for PS4
function fSetLED(a, b, c, d) {
    set_led(LED_1, a);
    set_led(LED_2, b);
    set_led(LED_3, c);
    set_led(LED_4, d);
    set_pvar(PVAR_1, a);
    set_pvar(PVAR_2, b);
    set_pvar(PVAR_3, c);
    set_pvar(PVAR_4, d);
}