title: Issues creating light sequence with pause button ARDUINO
body: <p>So I am trying to create a program that runs various light sequences using an Arduino board. I am not very familiar with C++ so I feel that my lack of syntax knowledge is preventing me from accomplishing my goal.</p>
  
  <p>My idea is to have various light sequences that are played depending on what button is pressed on an infrared remote. The amount of time that a light is on or off may or may not be the same as that of another light. Unfortunately, the sequences do not seem to be working which indicates that the issue is likely with the <code>toggleLight</code> function.</p>
  
  <p>I also wanted there to be a button that allows the user to pause the sequence (no matter where along the sequence it is). And once the button is pressed again, then the sequence continues where it left off. I read something about an interrupter and sleep mode using C++ but I am unfamiliar with this so it is not included in my code.</p>
  
  <p>The rest of my goals I have included within my code. I created an object "light" because I was trying to create the sequence without using the delay function as the interrupt does not work well with the delay function (as far as I am aware). Then I am able to call the function <code>toggleLight</code> on the specific light object. However, as I previously stated the sequences are not working.</p>
  
  <p>I am more familiar with OOP languages so perhaps creating an object is not the best for Arduino. If anyone has any ideas for how I can accomplish my goal it would be much appreciated.</p>
  
  <pre><code>unsigned long previousMillis = 0;
  unsigned long currentMillis = millis();
  
  //sets up the Infrared receiver for the remote controller
  const int RECV_PIN = 1;
  IRrecv irrecv(RECV_PIN);
  decode_results results;
  
  //Sets up the LED's pin number and light status
  class light{
     private:
     int _pinNumber;
     byte _Lstatus;
  
    public:
   //function that creates the objects with the parameters
    light(int pinNum, byte Lstat){
    _pinNumber = pinNum;
    _Lstatus = Lstat;}
  
    void toggleLight(long interval){
      //ensures that the "interval" amount of time has passed between the last LED blink
      if ((currentMillis - previousMillis) &gt;= interval) {
  
      // if the LED is off turn it on and vice-versa:
      if (_Lstatus == LOW) {
        _Lstatus = HIGH;
      } else if (_Lstatus == HIGH) {
        _Lstatus = LOW;
      }
      // set the LED with the ledState of the variable:
      digitalWrite(_pinNumber, _Lstatus);
      // save the last time you blinked the LED
      previousMillis = currentMillis;
    }
    }
  };
  //creating four light objects with the pins and initial status of off.
  light J1(13, LOW);
  light J2(11, LOW);
  light P1(12, LOW);
  light P2(10, LOW);
  
  
  void setup()
  {
      pinMode(13, OUTPUT);
      pinMode(12, OUTPUT);
      pinMode(11, OUTPUT);
      pinMode(10, OUTPUT);
  
  }
  //Sequence 1 is a mock sequence. It will probably be longer and the intervals would not all be 1000
  void seq1(){
    currentMillis = millis();
    J1.toggleLight(1000);
    P1.toggleLight(1000);
    J1.toggleLight(1000);
    P1.toggleLight(1000);
    J2.toggleLight(1000);
    P2.toggleLight(1000);
  }
  
  void seq2(){
    currentMillis = millis(); //I found that placing currentMillis = millis() here allows the lights to at least turn on
    J1.toggleLight(2000);
    J1.toggleLight(10);
    P1.toggleLight(1000);
    P1.toggleLight(0);
    J2.toggleLight(1500);
    J2.toggleLight(1);
    P2.toggleLight(2000);
    P2.toggleLight(1);
  }
  
  void loop()
  {
        /* So once i get the sequences working, my idea is to have different sequences play
      depending on what button on the remote is pressed. However, first I want to get the sequences and
      interrupter
  For now I have just tried running sequence #2 but it does not work.. Neither does Sequence #1. */
        seq2();
  
  
  
        //I MADE THESE LINES OF CODE COMMENTS FOR NOW. UNTIL I GET THE REST OF THE PROGRAM WORKING
        /*if (irrecv.decode(&amp;results))
        {
          switch (results.value) {
            case : 0xf00000 // When button #1 sequence one plays
              seq1();
              break;
            case : 0xf00000 // when button #2 is pressed, sequence two plays
              seq2();
              break;
      */
  
      }
  </code></pre>