Re: Detector Building C
Posted: January 28th, 2020, 5:02 am
How is having multiple LEDs on at once any more difficult than having a single LED on at once?MTV<=>Operator wrote: ↑January 29th, 2020, 5:05 pm Sorry if this was answered already, but on the rules it states that you might be required to display more than one LED color at a time. In other words, the ranges will overlap. How would one do this?
Do whatever works for your device.
so there is not a restricted amount of codes? i just need a program(s) to make my device work right?lindsmaurer wrote: ↑January 30th, 2020, 4:28 pmDo whatever works for your device.
If you’re asking about logs, my highlights are on one set of code instead of multiple copies
For a single LED at once, you only need 3 temperature ranges, one for each LED. But if part of one range requires two LEDs to be on but another part of that range requires only one LED to be on, how would you do this? I tried making 5 temperature ranges, 3 for a single LED and 2 for multiple LEDs, but compound inequalities don't seem to work in the arduino code. Did I just misinterpret the rules?LIPX3 wrote: ↑January 29th, 2020, 7:37 pmHow is having multiple LEDs on at once any more difficult than having a single LED on at once?MTV<=>Operator wrote: ↑January 29th, 2020, 5:05 pm Sorry if this was answered already, but on the rules it states that you might be required to display more than one LED color at a time. In other words, the ranges will overlap. How would one do this?
That's where the beauty of multiple "else if" statements can help you. The code will select the first case that is true and run the code inside. In this case, if temp = 33, it would skip over the first block of code and move to the second block, triggering the red and blue LEDs simultaneously.MTV<=>Operator wrote: ↑January 30th, 2020, 7:26 pmFor a single LED at once, you only need 3 temperature ranges, one for each LED. But if part of one range requires two LEDs to be on but another part of that range requires only one LED to be on, how would you do this? I tried making 5 temperature ranges, 3 for a single LED and 2 for multiple LEDs, but compound inequalities don't seem to work in the arduino code. Did I just misinterpret the rules?LIPX3 wrote: ↑January 29th, 2020, 7:37 pmHow is having multiple LEDs on at once any more difficult than having a single LED on at once?MTV<=>Operator wrote: ↑January 29th, 2020, 5:05 pm Sorry if this was answered already, but on the rules it states that you might be required to display more than one LED color at a time. In other words, the ranges will overlap. How would one do this?
Code: Select all
if (temp < 25) {
// Red Only
redLED(on);
greenLED(off);
blueLED(off);
} else if (temp < 35) {
// Red and Blue
redLED(on);
greenLED(off);
blueLED(on);
} else if (temp < 50) {
// Green Only
redLED(off);
greenLED(on);
blueLED(off);
} else if (temp < 75) {
// Blue Only
redLED(off);
greenLED(off);
blueLED(on);
}
This provides a sufficient example. There's no need to make 5 temperature ranges - just make each temperature range control the LEDs as required.pepperonipi wrote: ↑January 30th, 2020, 8:13 pmThat's where the beauty of multiple "else if" statements can help you. The code will select the first case that is true and run the code inside. In this case, if temp = 33, it would skip over the first block of code and move to the second block, triggering the red and blue LEDs simultaneously.MTV<=>Operator wrote: ↑January 30th, 2020, 7:26 pmFor a single LED at once, you only need 3 temperature ranges, one for each LED. But if part of one range requires two LEDs to be on but another part of that range requires only one LED to be on, how would you do this? I tried making 5 temperature ranges, 3 for a single LED and 2 for multiple LEDs, but compound inequalities don't seem to work in the arduino code. Did I just misinterpret the rules?Code: Select all
if (temp < 25) { // Red Only redLED(on); greenLED(off); blueLED(off); } else if (temp < 35) { // Red and Blue redLED(on); greenLED(off); blueLED(on); } else if (temp < 50) { // Green Only redLED(off); greenLED(on); blueLED(off); } else if (temp < 75) { // Blue Only redLED(off); greenLED(off); blueLED(on); }