Can I start mirroring the LED color to my own LED?

hi I just have really quick question for mirroring LED from the board to my LED. What should I do to make it happen after I update the firmware to 0.4.5? I remember one of user mentioned about it last time. Does the function already available now on version 0.4.5?

2 Likes

https://docs.particle.io/reference/firmware/photon/#onchange-handler-

2 Likes

thank you so much.

1 Like

when I compile it it says class RGBClass has no member named ‘onChange’. is there anyway to see my photon version. I just run particle update and I don’t know what else I need to do to deal with it?

This is the Error message I have got.
error: ‘class RGBClass’ has no member named 'onChange’
RGB.onChange(ledChangeHandler);

Are you sure you have 0.4.5 selected against your device, assuming you’re building your app in Build?

void ledChangeHandler(uint8_t r, uint8_t g, uint8_t b)
{
analogWrite(redLED, r);
analogWrite(greenLED, g);
analogWrite(blueLED, b);
}

void setup(void)
{
pinMode(redLED,OUTPUT);
pinMode(greenLED,OUTPUT);
pinMode(blueLED,OUTPUT);
RGB.onChange(ledChangeHandler);
}
This is what I have from the code. I use CoolTerm to check the system it’s 0.4.5 already, when I compile it the error message from local compiler is as follow:
‘class RGBClass’ has no member named 'onChange’
RGB.onChange(ledChangeHandler);

The way I update the system firmware is update CLI first and then doing “particle update” in terminal line on my Mac.

There is an interesting thing. When I open spark_wiring_rgb.h, there is no functions of “onChange(ledChangeHandler);”

You talk about opening source files, so I guess you’re building locally. Have you pulled the latest changes from github?

git pull

i see

btw, If I run it on MANUAL mode, will function still work?

btw, which repo to pull?

I have update firmware and also pull the files from git, but my external LED display the all of color(RGB), and there is no action that associate with the RGB LED on the Board. What happen?

void ledChangeHandler(uint8_t r, uint8_t g, uint8_t b)
{
	analogWrite(redLED, r);
	analogWrite(greenLED, g);
	analogWrite(blueLED, b);
}

void setup(void) 
{ 
	pinMode(redLED,OUTPUT);
	pinMode(greenLED,OUTPUT);
	pinMode(blueLED,OUTPUT);
	
	RGB.onChange(ledChangeHandler);
	//Server to Client(Photon) command

	Spark.function("setLive", startLivePublish);

	#if TESTING
		
	#endif
}

Hi @mikelo

I tried this and I can’t make it work either using analogWrite. It does work with digitalWrite to D7 so I know that the handler is getting called.

I wonder if @mdma knows of any reason why this shouldn’t work with analogWrite? Timer problem?

I even tried doing an analogWrite(D7,0); in setup so that the timer was started.

So I just realized that I was using D7 and analogWrite() which do not play nice together.

So @mikelo

Are you using analogWrite capable pins? On Photon these are listed here:

On the Photon, this function works on pins D0, D1, D2, D3, A4, A5, WKP, RX and TX with a caveat: PWM timer peripheral is duplicated on two pins (A5/D2) and (A4/D3) for 7 total independent PWM outputs. For example: PWM may be used on A5 while D2 is used as a GPIO, or D2 as a PWM while A5 is used as an analog input. However A5 and D2 cannot be used as independently controlled PWM outputs at the same time.

1 Like

which pins are you trying to analogWrite to? Not all pins support analog write - please check yours in the docs https://docs.particle.io/reference/firmware/photon/#analogwrite-

@mikelo, in addition to @bko’s question regarding the correct pin selection, have you tested your external LEDs’ wiring to make sure the LEDs are working as expected?

@Moors7 asked me to chime in here with a quick code snippet from something I just wrote for another project. Instead of blinking a traditional RGB LED, I’m blinking an LED on an LED matrix panel.

SYSTEM_MODE(SEMI_AUTOMATIC);

void ledChangeHandler(uint8_t r, uint8_t g, uint8_t b) {
	if(!Particle.connected()) {
		matrix.drawPixel(0, 0, matrix.Color444(r, g, b));
		matrix.swapBuffers(true);
	}
}

void setup() {
	matrix.begin();
	matrix.setTextWrap(false); // Allow text to run off right edge
	matrix.setTextSize(1);
	matrix.setTextColor(matrix.Color333(210, 210, 210));

	RGB.onChange(ledChangeHandler);

	// Connect to the cloud
	Particle.connect();
	while(!Particle.connected()) {
	 	Particle.process();
	 	delay(1);
	}
}

I hope this helps!

5 Likes

yes, I am pretty sure the pins connect to external RGB LED correctly by using D0,D1 and D2. When I set their pin mode to output. All three LEDs are light up. There is nothing that external LED works like it’s mirroring the on-board LED.

@mikelo, do you have current limiting resistors for each LED?

1 Like

yes, I do, and it’s way before I ask this question. The concerns that you ask about are not real concern, but thank you for double check with me. The thing I want the external LED to do is pretty simple, just display the color and act exactly the same as the on-board LED.