Toggle LEDs on/off?

GPC2 script programming for Titan Two. Code examples, questions, requests.

Toggle LEDs on/off?

Postby Colour Magician » Sat Apr 15, 2023 8:56 am

This seems like something that should be easy, but I have not managed to find an example of someone doing this.
The goal is to have each of the 7 available colours mapped to 7 corresponding rapid-fire settings within the script, and then also a toggle to turn the LEDs on/off completely.

This would then allow each of the 7 colours to indicate an active setting, while then also having no lights active when the rapid-fire macro is disabled. The colours are currently activated as combos alongside each setting, since I can't find another way to bind each colour to each setting.

It is key that the toggle does not just change to another colour, since the settings are separate from the on/off toggle for the rapid-fire, which would leave incorrect colours showing if it toggled to another colour, since the correct colour would not be toggled back on, as they are mapped to 7 other inputs.

I have found no way to have a toggle which disables the LEDs entirely, but then turns them back on while recalling the previous selected colour. As far as I can tell, this should be very possible, to turn the LEDs on/off with a toggle.

Any help appreciated here, because this is embarrassingly eluding me.
User avatar
Colour Magician
Sergeant
Sergeant
 
Posts: 7
Joined: Sat Nov 17, 2018 9:57 pm

Re: Toggle LEDs on/off?

Postby Mad » Sun Apr 16, 2023 12:15 am

If I'm following you correctly here is an example you can work with.

Simply calling rgb(); will disable the LED color.
Or set your colors in rgb format - rgb(255, 0, 0) would be red.

Code: Select all
#include <xb1.gph>
bool toggle;
 
main {
    if(event_active(XB1_UP)) {
        toggle = !toggle;
        rgb();
        if(toggle) rgb(0, 255, 0);
    }
}
 
void rgb(int8 r, int8 g, int8 b) {
    led_set(LED_1, (fix32)b, 0);
    led_set(LED_2, (fix32)r, 0);
    led_set(LED_3, (fix32)g, 0);
    return;
}   
ConsoleTuner Support Team || ConsoleTuner Discord || InputSense Discord
Mad
Major General
Major General
 
Posts: 4536
Joined: Wed May 22, 2019 5:39 am

Re: Toggle LEDs on/off?

Postby Colour Magician » Sun Apr 16, 2023 12:50 pm

This does allow them to be turned off, so thank you for that. I am still unable, however, to find any way to recall previous colours by using this. It seems as though this is able to recall one colour, by switching between being off and being that colour, compared to being off or being one of the seven possible colours.

I struggle to explain this, but it would essentially be a case of making something that worked as:
When setting 1 is active, be yellow, when setting two is active, be green, setting 3 white, 4 blue, 5 red, 6 purple, 7 cyan. When no setting is active, lights are off. When they are active, be the respective colour.

I just can't work out how to turn what you've written into that, how to be active with any colour, then turn off, then back on while retaining that colour?


EDIT/UPDATE:

Nevermind, I got it working by adding in a thingy telling it to recall the colours from elsewhere, telling it if toggle = true then set the colour as "rainbow", then set rainbow as being linked to each setting and recalling the colour needed. I hope that makes sense to anyone who might look at this in future.

Again, thank you very much for the help, I've wanted to get this working for a long time.
User avatar
Colour Magician
Sergeant
Sergeant
 
Posts: 7
Joined: Sat Nov 17, 2018 9:57 pm


Return to GPC2 Script Programming

Who is online

Users browsing this forum: No registered users and 180 guests

cron