DIY WiFi Sprinkler Controller using ESP8266

Great suggestion. I haven’t built any hardware yet but I’m thinking this might do the trick, see inline comments:

class ShiftRegisterSwitch : public Component, public switch_::Switch {
 private:
  int index;
  const uint8_t resetSR[8] = { 0, 0, 0, 0, 0, 0, 0, 0}; // Define an array to reset all pins
 
 public:
  ShiftRegisterSwitch(int output) {
    index = output;
  }
 
  void setup() override {
    sr.set(index, HIGH);
  }
 
  void write_state(bool state) override {
    if(state) {
      sr.setAll(resetSR); // Added to reset everything first when one pin gets set.
      sr.set(index, HIGH);
    } else {
      sr.set(index, LOW);
    }
 
    // Acknowledge new state by publishing it
    publish_state(state);
  }
};

I think this should reset all pins to zero before setting a pin to one… I’ve ordered my hardware so when it gets in I’ll have to proto something up and try it out.

1 Like