Go Down

Topic: Paid Assignment. (Read 412 times) previous topic - next topic

fujtech

I'm seeking someone to write the code for the attach parameters including a text document explaining functions. Please look at the attached and discuss it with me for fees and time frame. Thank you.

techtidda

What do you mean by zero to low.


Mail me on. worldofembedded4u@gmail.com


mugambi

I saw this on Guru... right?

any

Paul_KD7HB

What do you mean by zero to low.


Mail me on. worldofembedded4u@gmail.com


Probably similar to "one of the only".

Paul

PaulMurrayCbr

#4
Aug 24, 2017, 05:35 pm Last Edit: Aug 24, 2017, 06:27 pm by PaulMurrayCbr
I don't understand this specification document. What are these 8 "sections"?

Ok … I think I get it. You have 8 little clusters of pins and you want them all to be doing their various jobs simultaneously (in effect).

Not sure what this means:
Code: [Select]

output 1 to go from (ZERO) to (LOW)


Normally, ZERO means the same thing as LOW. A pin can have one of 4 states - HIGH (connected to +5v), LOW (connected to ground), INPUT (floating) and INPUT_PULLUP (connected to +5v with a high impedance). I suspect that "LOW" means "pinmode OUTPUT, LOW" and "ZERO" means "pinMode INPUT (floating)".

Aside from this, this doesn't look super difficult. A function for each section, some variables for the usual 50ms debounce and to handle blinking.

Here's section 1 and 2 done:

Code: [Select]



inline void OZERO(byte pin) {
  pinMode(pin, INPUT);
}

inline void OLOW(byte pin) {
  pinMode(pin, OUTPUT);
  digitalWrite(pin, LOW);
}

inline void blink(byte pin) {
  digitalWrite(pin, millis() & (1 << 10) ? HIGH : LOW);
}

class Debounce {
    const byte pin;
    byte state, prev;
    uint16_t t; // more than enough precision for debounce

  public:
    Debounce(byte pin) : pin(pin) {}

    void setup() {
      pinMode(pin, INPUT); // the input has an external pulldown, I assume
      state = prev = digitalRead(pin);
    }

    void loop() {
      if(state != prev) {
        if (((uint16_t) millis()) - t < 50) return;
      }
      prev = state;
      state = digitalRead(pin);
      if(state != prev) {
        t = (uint16_t) millis();
      }
    }

    inline boolean high() {
      return state == HIGH;
    }
    inline boolean low() {
      return state == LOW;
    }
    inline boolean rising() {
      return prev == LOW && state == HIGH;
    }
    inline boolean falling() {
      return prev == HIGH && state == LOW;
    }
};

class Runner {
    static Runner *head;
    Runner *next;
    virtual void setup() = 0;
    virtual void loop() = 0;

  public:

    Runner() {
      next = head;
      head = this;
    }

    static void setupAll() {
      for (Runner *r = head; r; r = r->next) {
        r->setup();
      }
    }

    static void loopAll() {
      for (Runner *r = head; r; r = r->next) {
        r->loop();
      }
    }
};

Runner *Runner::head = NULL;

/*
   With a single momentary (high) input, output 1 will blink from zero (nothing) to low continuously and output 2
   will go from low to zero (nothing).
   This means, that output 2 will be low at power on of mega and turn off (nothing) when output 1 is active.

   With a single momentary (high) input again, output 1 will stop blinking and return to zero (nothing) and output 2
   will return to low from zero (nothing)."
*/
class Section1 : public Runner {
    Debounce input;
    const byte output1;
    const byte output2;
    byte active;


    void setup() {
      input.setup();
      active = false;
      OZERO(output1);
      OLOW(output2);
    }

    void loop() {
      input.loop();
      if (input.rising()) {
        if ((active = !active)) {
          OLOW(output1);
          OZERO(output2);
        }
        else {
          OZERO(output1);
          OLOW(output2);
        }
      }

      if (active) {
        blink(output1);
      }
    }

  public:

    Section1(byte zinput, byte zoutput1, byte zoutput2) :
      input(zinput), output1(zoutput1), output2(zoutput2) {}


};


/*
  "With a single momentary (high) input, output 1 will go from zero (nothing) to low continuously
  and output 2 will go from low to zero (nothing).This means, that output 2 will be low at power
  on of mega and turn off (nothing) when output 1 is active. With a single momentary (high) input again,
  output 1 will return to zero (nothing) and output 2 will return to low from zero (nothing)."

*/
class Section2 : public Runner {
    Debounce input;
    const byte output1;
    const byte output2;
    byte active;


    void setup() {
      input.setup();
      active = false;
      OZERO(output1);
      OLOW(output2);
    }

    void loop() {
      input.loop();
      if (input.rising()) {
        if ((active = !active)) {
          OLOW(output1);
          OZERO(output2);
        }
        else {
          OZERO(output1);
          OLOW(output2);
        }
      }
    }

  public:
    Section2(byte zinput, byte zoutput1, byte zoutput2) :
      input(zinput), output1(zoutput1), output2(zoutput2) {}
};


////////////////////////////////////////////////////////////////////////
// PINOUT

Section1 i0(0, A0, A1);    //debounce I, O ZERO-LOW blinking (500), Ob LOW-ZERO  -Output L/T;
Section1 i1(1, A2, A3);    //debounce I, O ZERO-LOW blinking (500), Ob LOW-ZERO  -Output R/T;

Section2 i2(2, A4, A5);    //debounce I, O ZERO-LOW, Ob LOW-ZERO  -Output H/L;
Section2 i3(3, A6, A7);    //debounce I, O ZERO-LOW, Ob LOW-ZERO  -Output H/H;

void setup() {
  Runner::setupAll();
}

void loop() {
  Runner::loopAll();
}


If this works, and you would like me to bang out the rest of it, then that will be $50 AUD via paypal.
http://paulmurraycbr.github.io/ArduinoTheOOWay.html

Go Up