Browse Source

Fix error in led module

fastled 1.2.0
Xose Pérez 8 years ago
parent
commit
abf07476b6
1 changed files with 5 additions and 4 deletions
  1. +5
    -4
      code/src/led.ino

+ 5
- 4
code/src/led.ino View File

@ -22,25 +22,25 @@ std::vector<led_t> _leds;
bool ledAuto; bool ledAuto;
bool ledStatus(unsigned char id) { bool ledStatus(unsigned char id) {
if (id <= _leds.size()) return false;
if (id >= _leds.size()) return false;
bool status = digitalRead(_leds[id].pin); bool status = digitalRead(_leds[id].pin);
return _leds[id].reverse ? !status : status; return _leds[id].reverse ? !status : status;
} }
bool ledStatus(unsigned char id, bool status) { bool ledStatus(unsigned char id, bool status) {
if (id <= _leds.size()) return false;
if (id >= _leds.size()) return false;
bool s = _leds[id].reverse ? !status : status; bool s = _leds[id].reverse ? !status : status;
digitalWrite(_leds[id].pin, _leds[id].reverse ? !status : status); digitalWrite(_leds[id].pin, _leds[id].reverse ? !status : status);
return status; return status;
} }
bool ledToggle(unsigned char id) { bool ledToggle(unsigned char id) {
if (id <= _leds.size()) return false;
if (id >= _leds.size()) return false;
return ledStatus(id, !ledStatus(id)); return ledStatus(id, !ledStatus(id));
} }
void ledBlink(unsigned char id, unsigned long delayOff, unsigned long delayOn) { void ledBlink(unsigned char id, unsigned long delayOff, unsigned long delayOn) {
if (id <= _leds.size()) return;
if (id >= _leds.size()) return;
static unsigned long next = millis(); static unsigned long next = millis();
if (next < millis()) { if (next < millis()) {
next += (ledToggle(id) ? delayOn : delayOff); next += (ledToggle(id) ? delayOn : delayOff);
@ -134,6 +134,7 @@ void ledSetup() {
mqttRegister(ledMQTTCallback); mqttRegister(ledMQTTCallback);
DEBUG_MSG("[LED] Number of leds: %d\n", _leds.size()); DEBUG_MSG("[LED] Number of leds: %d\n", _leds.size());
DEBUG_MSG("[LED] Led auto indicator is %s.\n", ledAuto ? "ON" : "OFF" );
} }


Loading…
Cancel
Save