SparkFun Forums 

Where electronics enthusiasts find answers.

Have questions about a SparkFun product or board? This is the place to be.
By BarryUK
#186433
I have a BOB13601 SX1509 (16 way I/O Expander board) hooked up to a Pro Mini, and using the supplied SparkFun Library can get most functions relating to LED control to work fine, but there is one issue I cannot seem to solve. If I set an LED to BLINK or BREATHE it does just that, but I cannot find a way to stop it! If I reset the pin to "normal" digitalWrite mode, and set the pin HIGH my LED is on full time (as it should be), but once I set it LOW it continues to BLINK or BREATHE. I've tried lots of ways to make it revert to ON/OFF control, such as setting the pin to an INPUT, then to OUTPUT, but no success so far. I'm no software expert, but I've looked through the library code and the Data Sheet but cannot solve this issue. I can call a RESET to set all pins back to an undefined state, but that means subsequently resetting all the pins I am using (ideally all 16), which causes a visible glitch that is not acceptable for my application, where I am monitoring a number of functions, and some functions (normally only one at a time) need to BLINK to show they are active, while other pins need to be ON or OFF. If anyone can offer any suggested solutions for me to try I would be really grateful! Thanks
By kill
#194285
Sorry for the necroing off this post
But i had a similar problem: fade in and fade out
and for anyone coming by this question here is a solution:

According to the datasheet of the SX1509, §4.9 Ledriver, page 18 -> the led driver operates in 3 distinct modes
Static, oneshot, and blink.
The modes are controlled by TxOn and TxOff
For static mode you need to set the TxON register to 0 and on/off is solely controlled by the controll bit in dataX register, if the driver previously has been sett into breath or blink mode
in my case i need to set the led into 1 of 4 states: Off, On, Breathe and Panic where On / Off should fade In / out respectively and Breath should be a slow breath cycle and Panic a faster one.
the following code shows how to switch between the different modes. Observ though that the led divisor clock needs to be set rather high to get a good result, and the sparkfun library sets the clock to 1 meaning in several places giving a 2 Mhz clock, i have hacked the lib to be able to select the correct clkX divisor)
Code: Select all
switch (newStatus) {

			case Off: {			//Fade out
					Serial.println("Off");
					breathe(BREATH_IO,		//pin
					0,	// TON , time on ms needs to be 0 for static mode
					1,	// T0FF, time off ms, needs to be !=0 for static mode
					0,	// fade in,	raise time / speed ms
					8000	// fade outi,	fall time / speed ms
				);
				digitalWrite(BREATH_IO,1); // turn led on, it will slowly fade in
			}; break;

			case On: {		// Fade in
					Serial.println("On");
					breathe(BREATH_IO,		//pin
					0,	// tOn , time on ms, needs to be 0 for static mode
					1,	// tOff, time off ms, need to be != 0 for static mode
					8000,	// fade in, raise time in ms
					0	// fade out fall time in ms
				);
				digitalWrite(BREATH_IO,0); // turn led on, it will slowly fade out
			}; break;

			case Breath: {
					Serial.println("Breathing");
					breathe(BREATH_IO,		//pin
					500,	// tOn , time on ms , needs to !=0 for blink/breath mode
					500,	// tOff, time off ms
					4800,	// rise,	raise time / speed ms
					1000	// fall	fall time / speed ms
				);
				digitalWrite(BREATH_IO,0); // turn led on
			}; break;

			case Panic: {
					Serial.println("Panic");
					breathe(BREATH_IO,		//pin
					500,	// tOn , time on ms  //neds to be !=0 for breath/blink mode
					500,	// tOff, time off ms
					600,	// rise,	raise time / speed ms
					600	// fall	fall time / speed ms
				);
				digitalWrite(BREATH_IO,0); // turn led on
			}; break;

			}
		}