1 2 2

: Code Review

  1. #1
    stdio / Junior Member
    Jan 2018
    2
    1
    / 0 -0
    0
    Thanked 0 Times in 0 Posts

    Code Review

    .
    , .
    6 ( " 501").
    , , .
    ?
    \
    SETUP . "pinMode" ?




    :
    #define TIME 20 
    int ledPins[] = {2,3,4,5,6,7};
    int randReturn;
    int ledIndex;
    int ledModIndex;
    long randNumber;
    int piezoPin = 11;
    
    
    //──────────────────────┤       Play game Function       ├────────────────────────────
    void playGame(int _inRandNum){
      ledIndex = 0;
      int k = 1;
      blinkBoard();
      for (ledIndex = 0; ledIndex <= _inRandNum; ledIndex++){
        ledModIndex = ledIndex % 6;
        k++;
        digitalWrite(ledPins[ledModIndex], HIGH);
        tone(piezoPin, 3000, TIME * k);
        Serial.println(TIME * k);
        delay (TIME * k);
        if(ledIndex < _inRandNum){
          digitalWrite(ledPins[ledModIndex], LOW);
        }
        delay (TIME * k);
      }
    }
    //──────────────────────┤       Blink board Function       ├────────────────────────────
    void blinkBoard(){
      for (int i=0; i <= 3; i++){
        for (int iLP = 0; iLP <=5; iLP++){
          digitalWrite(ledPins[iLP], HIGH);
        }
        delay(100);
        for (int iLP = 0; iLP <=5; iLP++){
          digitalWrite(ledPins[iLP], LOW);
        }
        delay(100);
      }
    }
    //──────────────────────┤       Random number Function       ├────────────────────────────
    int setRand() {
      randNumber = random(9, 20);
      return randNumber;
    }
    //──────────────────────┤       Startup Function       ├────────────────────────────
    void startup(){
      blinkBoard();
      for (int suloop = 0; suloop <= 18; suloop++){
        ledModIndex = suloop % 6;
        digitalWrite(ledPins[ledModIndex], HIGH);
        delay (50);
        digitalWrite(ledPins[ledModIndex], LOW);
        delay (50);
      }
    }
    //──────────────────────┤       SETUP Function       ├────────────────────────────
    void setup() { 
      Serial.begin(9600);
      pinMode(0, INPUT_PULLUP);
      pinMode(13, OUTPUT);
      for (int iLPm = 0; iLPm <=5; iLPm++){
          pinMode(ledPins[iLPm], OUTPUT);
      }
      
      startup();
    }
    //──────────────────────┤       LOOP Function       ├────────────────────────────
    void loop() {
      int sensorVal = digitalRead(0);
      if (sensorVal == LOW) {
        randReturn = setRand();
        playGame(randReturn);
      }
      delay(500);
    }

  2. #2
    gbgb / Senior Member
    Aug 2013
    2,130
    15
    / 328 -292
    0
    Thanked 1 Time in 1 Post
    " , - .
    ( ? ?) .

  3. / -gbgb :

    stdio (28-01-2018)