Go Down

Topic: LED Scene selection? (Read 684 times) previous topic - next topic

Nancenificent

Code: [Select]

int R = 2;
int I = 3;
int C = 4;
int K = 5;
int Y = 6;
int D = 7;
int A = 8;
int L = 9;
int E = 10;

const int select = 12;
const int maxScene = 3;

int scene = 0;


void setup() {
  pinMode(select, INPUT_PULLUP);
  pinMode(R, OUTPUT);
  pinMode(I, OUTPUT);
  pinMode(C, OUTPUT);
  pinMode(K, OUTPUT);
  pinMode(Y, OUTPUT);
  pinMode(D, OUTPUT);
  pinMode(A, OUTPUT);
  pinMode(L, OUTPUT);
  pinMode(E, OUTPUT);


}

void loop() {
  switch (scene) {
    case 0:
      digitalWrite(R, LOW);
      digitalWrite(I, LOW);
      digitalWrite(C, LOW);
      digitalWrite(K, LOW);
      digitalWrite(Y, LOW);
      digitalWrite(D, LOW);
      digitalWrite(A, LOW);
      digitalWrite(L, LOW);
      digitalWrite(E, LOW);
      delay(50);


      digitalWrite(R, HIGH);
      myDelay (100);
      digitalWrite(R, LOW);
      myDelay (100);
      digitalWrite(I, HIGH);
      myDelay (100);
      digitalWrite(I, LOW);
      myDelay (100);
      digitalWrite(C, HIGH);
      myDelay (100);
      digitalWrite(C, LOW);
      myDelay (100);
      digitalWrite(K, HIGH);
      myDelay (100);
      digitalWrite(K, LOW);
      myDelay (100);
      digitalWrite(Y, HIGH);
      myDelay (100);
      digitalWrite(Y, LOW);
      myDelay (100);
      digitalWrite(D, HIGH);
      myDelay (100);
      digitalWrite(D, LOW);
      myDelay (100);
      digitalWrite(A, HIGH);
      myDelay (100);
      digitalWrite(A, LOW);
      myDelay (100);
      digitalWrite(L, HIGH);
      myDelay (100);
      digitalWrite(L, LOW);
      myDelay (100);
      digitalWrite(E, HIGH);
      myDelay (100);
      digitalWrite(E, LOW);
      myDelay (100);
      break;

    case 1:
      digitalWrite(R, HIGH);
      myDelay(100);
      digitalWrite(R, LOW);
      myDelay(100);
      digitalWrite(I, HIGH);
      myDelay(100);
      digitalWrite(I, LOW);
      myDelay(100);
      digitalWrite(C, HIGH);
      myDelay(100);
      digitalWrite(C, LOW);
      myDelay(100);
      digitalWrite(K, HIGH);
      myDelay(100);
      digitalWrite(K, LOW);
      myDelay(100);
      digitalWrite(Y, HIGH);
      myDelay(100);
      digitalWrite(Y, LOW);
      myDelay(100);
      digitalWrite(D, HIGH);
      myDelay(100);
      digitalWrite(D, LOW);
      myDelay(100);
      digitalWrite(A, HIGH);
      myDelay(100);
      digitalWrite(A, LOW);
      myDelay(100);
      digitalWrite(L, HIGH);
      myDelay(100);
      digitalWrite(L, LOW);
      myDelay(100);
      digitalWrite(E, HIGH);
      myDelay(100);
      digitalWrite(E, LOW);
      myDelay(100);
      digitalWrite(L, HIGH);
      myDelay(100);
      digitalWrite(L, LOW);
      myDelay(100);
      digitalWrite(A, HIGH);
      myDelay(100);
      digitalWrite(A, LOW);
      myDelay(100);
      digitalWrite(D, HIGH);
      myDelay(100);
      digitalWrite(D, LOW);
      myDelay(100);
      digitalWrite(Y, HIGH);
      myDelay(100);
      digitalWrite(Y, LOW);
      myDelay(100);
      digitalWrite(K, HIGH);
      myDelay(100);
      digitalWrite(K, LOW);
      myDelay(100);
      digitalWrite(C, HIGH);
      myDelay(100);
      digitalWrite(C, LOW);
      myDelay(100);
      digitalWrite(I, HIGH);
      myDelay(100);
      digitalWrite(I, LOW);
      myDelay(100);
      break;

    case 2:
      digitalWrite(R, HIGH);
      digitalWrite(E, HIGH);
      myDelay(100);
      digitalWrite(R, LOW);
      digitalWrite(E, LOW);
      myDelay(100);
      digitalWrite(I, HIGH);
      digitalWrite(L, HIGH);
      myDelay(100);
      digitalWrite(I, LOW);
      digitalWrite(L, LOW);
      myDelay(100);
      digitalWrite(C, HIGH);
      digitalWrite(A, HIGH);
      myDelay(100);
      digitalWrite(C, LOW);
      digitalWrite(A, LOW);
      myDelay(100);
      digitalWrite(K, HIGH);
      digitalWrite(D, HIGH);
      myDelay(100);
      digitalWrite(K, LOW);
      digitalWrite(D, LOW);
      myDelay(100);
      digitalWrite(Y, HIGH);
      myDelay(100);
      digitalWrite(Y, LOW);
      myDelay(100);
      digitalWrite(K, HIGH);
      digitalWrite(D, HIGH);
      myDelay(100);
      digitalWrite(K, LOW);
      digitalWrite(D, LOW);
      myDelay(100);
      digitalWrite(C, HIGH);
      digitalWrite(A, HIGH);
      myDelay(100);
      digitalWrite(C, LOW);
      digitalWrite(A, LOW);
      myDelay(100);
      digitalWrite(I, HIGH);
      digitalWrite(L, HIGH);
      myDelay(100);
      digitalWrite(I, LOW);
      digitalWrite(L, LOW);
      myDelay(100);

      break;

    case 3:
      digitalWrite(D, HIGH);
      digitalWrite(A, HIGH);
      digitalWrite(L, HIGH);
      digitalWrite(E, HIGH);

      digitalWrite(R, HIGH);
      digitalWrite(I, HIGH);
      digitalWrite(C, HIGH);
      digitalWrite(K, HIGH);
      digitalWrite(Y, HIGH);
      myDelay(100);

      digitalWrite(R, LOW);
      digitalWrite(I, LOW);
      digitalWrite(C, LOW);
      digitalWrite(K, LOW);
      digitalWrite(Y, LOW);
      myDelay(100);

      break;





  }

}
void myDelay(int delayTime) {
  if (digitalRead(select) == LOW) {
    scene++;
    if (scene > maxScene) {
      scene = 0;
    }
  }
  delay(delayTime);
}



Final product, working as I wanted. I'm sure there is an easier way to do this, but I'm happy with it.

Thank you all for the help.



Grumpy_Mike

#16
Aug 31, 2017, 12:51 am Last Edit: Aug 31, 2017, 02:05 am by Grumpy_Mike
Your myDelay function is quite frankly rubbish. The idea is to remove ALL delay calls and you still have one in the myDelay function.
That function should hold in a loop until the delay time is finished as measured by the millis timer OR the push button has been pressed.
Do not try any push counting in this functionality.

Girishchenna

Hi,

I was also trying the same kind of programming, I am not successful with it. Scene is not switching to different cases.
I tried your above codes with my board as it is, only one case is working other two are not worked.
could you succeed with the above code? 

Go Up