Chinese LED hacking HELP!

Yeah == true would have been an awful lot easier but as they are different types its a no go... You did however get me googling the right things! I think (will test with the leds attached tomorrow) I have it working as intended. The code is

Code:
  String requestString = String(request);
  int indexPosition = requestString.indexOf('?');
  if (requestString.charAt(indexPosition + 1) == 'W') {
    requestString = requestString.substring(12, 16);
    whiteLevel = requestString.toInt();
    Serial.println("White LEVEL SET TO = ");
    Serial.println(whiteLevel);
    analogWrite(whiteLedPin, whiteLevel);

  }

  if (requestString.charAt(indexPosition + 1) == 'B') {
    requestString = requestString.substring(11, 15);
    blueLevel = requestString.toInt();
    Serial.println("BLUE LEVEL SET TO = ");
    Serial.println(blueLevel);
    analogWrite(blueLedPin, blueLevel);
  }

for anyone interested. I will test and if it works as intended I will link the whole thing once I have tidied it all up and commented it as required.

I also picked up a used MarsAqua LED 165w with the dimmer knobs on top. I will be adding that and will show the wiring when I have it buttoned up. Its different and requires a transistor on each channel but nice and easy to do :)
 
Last edited:
Yeah == true would have been an awful lot easier but as they are different types its a no go...
Shouldn't be - String.startsWith returns boolean true or false so you should have been able to do that. However...
You did however get me googling the right things! I think (will test with the leds attached tomorrow) I have it working as intended. The code is

Code:
  String requestString = String(request);
  int indexPosition = requestString.indexOf('?');
  if (requestString.charAt(indexPosition + 1) == 'W') {
    requestString = requestString.substring(12, 16);
    whiteLevel = requestString.toInt();
    Serial.println("White LEVEL SET TO = ");
    Serial.println(whiteLevel);
    analogWrite(whiteLedPin, whiteLevel);

  }

  if (requestString.charAt(indexPosition + 1) == 'B') {
    requestString = requestString.substring(11, 15);
    blueLevel = requestString.toInt();
    Serial.println("BLUE LEVEL SET TO = ");
    Serial.println(blueLevel);
    analogWrite(blueLedPin, blueLevel);
  }

for anyone interested. I will test and if it works as intended I will link the whole thing once I have tidied it all up and commented it as required.

I also picked up a used MarsAqua LED 165w with the dimmer knobs on top. I will be adding that and will show the wiring when I have it buttoned up. Its different and requires a transistor on each channel but nice and easy to do :)
Looks good :)

Tim
 
Ok so it works. I can set the intensity of either channel on the web interface and it sets the leds as expected. I thought this was a super simple thing to accomplish but the more you know...

I now need to add some scheduling to this. I am not using an RTC but getting the current time from the NTC servers. Anyone worked with time before? As its non linear I have no idea how to interact with it as a variable. if time == the time i need x to happen seems like a lot of if statements running every loop unnecessarily.

Current code is:

https://pastebin.com/b798nBc1
 
Lots of ways to do it. One way would be to define an array of times and LED settings and loop thru that rather than lots of ifs. But you need to decide how you want to hold the time. You can just build it to a number made of the hours and minutes (eg 815 for 08:15, 2045 for 20:45) which is fairly simple and fairly readable. Or you can base it on number of minutes/seconds since midnight (a popular way of doing it).

In reality, loads of ways to do it that will work. Do you know what version of the time library you are using?

Tim
 
Back
Top