0
\$\begingroup\$

I am very new to programming. For a project I decided to make a game of cyclone using some LEDs,a push button, and a raspberry pi. I researched how to at least start on the game, but the problem that I encounter is that most examples of this game utilizes an arduino and python code, when I am familiar with the raspberry pi and c code. I would like to know to loop lighting up multiple LEDs one at a time with a decent amount of speed for a fun reaction game. My code starts out as this:

    #define pinOutYOne 0 //first yellow LED
    #define pinOutYTwo 3 //second yellow LED
    #define pinOutGOne 21 //green LED one
    #define pinOutGTwo 22 //green LED two
    #define pinOutBOne 23 //blue LED one...etc
    #define pinOutBTwo 25 //
    #define pinOutROne 4
    #define pinOutRTwo 5

    int  main(void){
      //set up pin mode as output
      pinMode(pinOutYOne, OUTPUT); //syntax for pinMode(pinNumber, Mode)
      pinMode(pinOutYTwo, OUTPUT);
      pinMode(pinOutGOne, OUTPUT);
      pinMode(pinOutGTwo, OUTPUT);
      pinMode(pinOutBOne, OUTPUT);
      pinMode(pinOutBTwo, OUTPUT);
      pinMode(pinOutROne, OUTPUT);
      pinMode(pinOutRTwo, OUTPUT);

      //clear output
      digitalWrite(pinOutYOne, 0); //write 0 (low) to output pin
      digitalWrite(pinOutYTwo, 0);
      digitalWrite(pinOutGOne, 0);
      digitalWrite(pinOutGTwo, 0);
      digitalWrite(pinOutBOne, 0);
      digitalWrite(pinOutBTwo, 0);
      digitalWrite(pinOutROne, 0);
      digitalWrite(pinOutRTwo, 0);

     //loop to allow blinking
     while (1 == 1){
       //light up the LED for 1 second
       digitalWrite(pinOutYOne, 1);
       digitalWrite(pinOutYTwo, 1);
       digitalWrite(pinOutGOne, 1);
       digitalWrite(pinOutGTwo, 1);
       digitalWrite(pinOutBOne, 1);
       digitalWrite(pinOutBTwo, 1);
       digitalWrite(pinOutROne, 1);
       digitalWrite(pinOutRTwo, 1);
       puts("LED on"); //display a message on console
       delay(1000); //1 for 1 milliseconds, 1000 for 1 second

    //turn off for 1 second
      digitalWrite(pinOutYOne, 0); //write 0 (low) to output pin
      digitalWrite(pinOutYTwo, 0);
      digitalWrite(pinOutGOne, 0);
      digitalWrite(pinOutGTwo, 0);
      digitalWrite(pinOutBOne, 0);
      digitalWrite(pinOutBTwo, 0);
      digitalWrite(pinOutROne, 0);
      digitalWrite(pinOutRTwo, 0);
      puts("LED off");
      delay(1000);
     }
 }

**I do know that this code lights all of the LEDs at once, I'm not sure how to implement a loop and light them up one at a time in sequence

\$\endgroup\$
  • \$\begingroup\$ I'm not sure what you are asking. Why is there C++ and C#. Is that C code working? Are you asking how to do a loop? I see a loop there. Do you need a counter? I have no idea how those functions are defined. But here, take this search. \$\endgroup\$ – Theraot Dec 2 '19 at 7:56
  • \$\begingroup\$ @Theraot i can't help but u seems know and i think he tries to light them all up in the same time if he do a loop it willl ligh one by one like a wave \$\endgroup\$ – younlok Dec 2 '19 at 8:09
  • \$\begingroup\$ You've tagged this with 3 different languages. What language are you after exactly? A c++ solution will not be exactly the same as a c solution. \$\endgroup\$ – Vaillancourt Dec 4 '19 at 4:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.