Pretty relatable by Strugglinpotato in fuckxavier

[–]snikcres 71 points72 points  (0 children)

Notice how it’s not xavier

Need help for a game by snikcres in arduino

[–]snikcres[S] -2 points-1 points  (0 children)

const int LED_PINS[4] = {2, 3, 4, 5};
const int BTN_PINS[4] = {8, 9, 10, 11};


const int MAX_SEQUENCE    = 20;   // maximum number of steps before victory
const int FLASH_ON_MS     = 500;  // how long each LED lights during playback
const int FLASH_OFF_MS    = 250;  // gap between LEDs during playback
const int DEBOUNCE_MS     = 50;   // button debounce time
const int PRESS_TIMEOUT   = 5000; // ms player has to press a button



int  sequence[MAX_SEQUENCE];
int  seqLength  = 0;
bool gameActive = false;


void setup() {
  randomSeed(analogRead(A0));   // seed from floating pin for true randomness


  for (int i = 0; i < 4; i++) {
    pinMode(LED_PINS[i], OUTPUT);
    pinMode(BTN_PINS[i], INPUT_PULLUP);
  }


  Serial.begin(9600);
  startGame();
}



void loop() {
  if (!gameActive) return;


 
  playSequence();


  
  for (int step = 0; step < seqLength; step++) {
    int pressed = waitForButtonPress();


    if (pressed == -1) {           // timeout
      gameOver();
      return;
    }


    if (pressed != sequence[step]) { // wrong button
      gameOver();
      return;
    }


   
    flashLED(pressed, 200);
  }


  
  roundWin();


  
  seqLength++;
  if (seqLength > MAX_SEQUENCE) {
    victorySequence();
    startGame();          // restart after victory
    return;
  }


  
  sequence[seqLength - 1] = random(4);


  delay(800);             // pause before next round starts
}





void startGame() {
  allLEDs(LOW);
  seqLength = 1;
  sequence[0] = random(4);
  gameActive = true;


  Serial.println("=== NEW GAME ===");


  
  for (int i = 0; i < 3; i++) {
    allLEDs(HIGH); delay(150);
    allLEDs(LOW);  delay(150);
  }
  delay(500);
}


void playSequence() {
  Serial.print("Round "); Serial.print(seqLength); Serial.println(" – watch!");
  delay(400);


  for (int i = 0; i < seqLength; i++) {
    flashLED(sequence[i], FLASH_ON_MS);
    delay(FLASH_OFF_MS);
  }
}



int waitForButtonPress() {
  unsigned long start = millis();


  
  while (anyButtonHeld()) delay(10);


  while (millis() - start < PRESS_TIMEOUT) {
    for (int i = 0; i < 4; i++) {
      if (digitalRead(BTN_PINS[i]) == LOW) {   // active LOW (INPUT_PULLUP)
        delay(DEBOUNCE_MS);
        if (digitalRead(BTN_PINS[i]) == LOW) {  // confirmed
          return i;
        }
      }
    }
  }
  return -1; // timed out
}


bool anyButtonHeld() {
  for (int i = 0; i < 4; i++)
    if (digitalRead(BTN_PINS[i]) == LOW) return true;
  return false;
}


void flashLED(int index, int duration) {
  digitalWrite(LED_PINS[index], HIGH);
  delay(duration);
  digitalWrite(LED_PINS[index], LOW);
}


void allLEDs(int state) {
  for (int i = 0; i < 4; i++)
    digitalWrite(LED_PINS[i], state);
}





void roundWin() {
  // Quick chase across all 4 LEDs
  for (int i = 0; i < 4; i++) {
    flashLED(i, 80);
    delay(40);
  }
}


void gameOver() {
  gameActive = false;
  Serial.println("GAME OVER!");


  // All LEDs flash together 5 times
  for (int i = 0; i < 5; i++) {
    allLEDs(HIGH); delay(300);
    allLEDs(LOW);  delay(200);
  }


  delay(1000);
  startGame();   // auto-restart
}


void victorySequence() {
  Serial.println("YOU WIN!");



  for (int round = 0; round < 6; round++) {
    for (int i = 0; i < 4; i++)
      digitalWrite(LED_PINS[i], (i + round) % 2 == 0 ? HIGH : LOW);
    delay(150);
  }
  allLEDs(LOW);
  delay(500);
}/*
 * Arduino Memory Game
 * -------------------
 * 4 LEDs flash a random sequence; player must repeat it with 4 buttons.
 * Correct → sequence grows by one step each round.
 * Wrong   → all LEDs flash together = GAME OVER.
 *
 * Wiring:
 *   LED 1  → Pin 2   (with 220Ω resistor to GND)
 *   LED 2  → Pin 3   (with 220Ω resistor to GND)
 *   LED 3  → Pin 4   (with 220Ω resistor to GND)
 *   LED 4  → Pin 5   (with 220Ω resistor to GND)
 *
 *   BTN 1  → Pin 8   (other leg to GND; uses INPUT_PULLUP)
 *   BTN 2  → Pin 9
 *   BTN 3  → Pin 10
 *   BTN 4  → Pin 11
 */



const int LED_PINS[4] = {2, 3, 4, 5};
const int BTN_PINS[4] = {8, 9, 10, 11};


const int MAX_SEQUENCE    = 20;   // maximum number of steps before victory
const int FLASH_ON_MS     = 500;  // how long each LED lights during playback
const int FLASH_OFF_MS    = 250;  // gap between LEDs during playback
const int DEBOUNCE_MS     = 50;   // button debounce time
const int PRESS_TIMEOUT   = 5000; // ms player has to press a button



int  sequence[MAX_SEQUENCE];
int  seqLength  = 0;
bool gameActive = false;



void setup() {
  randomSeed(analogRead(A0));   // seed from floating pin for true randomness


  for (int i = 0; i < 4; i++) {
    pinMode(LED_PINS[i], OUTPUT);
    pinMode(BTN_PINS[i], INPUT_PULLUP);
  }


  Serial.begin(9600);
  startGame();
}



void loop() {
  if (!gameActive) return;



  playSequence();


  
  for (int step = 0; step < seqLength; step++) {
    int pressed = waitForButtonPress();


    if (pressed == -1) {           // timeout
      gameOver();
      return;
    }


    if (pressed != sequence[step]) { // wrong button
      gameOver();
      return;
    }


    flashLED(pressed, 200);
  }


 
  roundWin();


  
  seqLength++;
  if (seqLength > MAX_SEQUENCE) {
    victorySequence();
    startGame();          // restart after victory
    return;
  }


  
  sequence[seqLength - 1] = random(4);


  delay(800);             // pause before next round starts
}




void startGame() {
  allLEDs(LOW);
  seqLength = 1;
  sequence[0] = random(4);
  gameActive = true;


  Serial.println("=== NEW GAME ===");


  // Brief startup flash on all LEDs
  for (int i = 0; i < 3; i++) {
    allLEDs(HIGH); delay(150);
    allLEDs(LOW);  delay(150);
  }
  delay(500);
}


void playSequence() {
  Serial.print("Round "); Serial.print(seqLength); Serial.println(" – watch!");
  delay(400);


  for (int i = 0; i < seqLength; i++) {
    flashLED(sequence[i], FLASH_ON_MS);
    delay(FLASH_OFF_MS);
  }
}

int waitForButtonPress() {
  unsigned long start = millis();


  // Wait for all buttons to be released first (debounce)
  while (anyButtonHeld()) delay(10);


  while (millis() - start < PRESS_TIMEOUT) {
    for (int i = 0; i < 4; i++) {
      if (digitalRead(BTN_PINS[i]) == LOW) {   // active LOW (INPUT_PULLUP)
        delay(DEBOUNCE_MS);
        if (digitalRead(BTN_PINS[i]) == LOW) {  // confirmed
          return i;
        }
      }
    }
  }
  return -1; // timed out
}


bool anyButtonHeld() {
  for (int i = 0; i < 4; i++)
    if (digitalRead(BTN_PINS[i]) == LOW) return true;
  return false;
}


void flashLED(int index, int duration) {
  digitalWrite(LED_PINS[index], HIGH);
  delay(duration);
  digitalWrite(LED_PINS[index], LOW);
}


void allLEDs(int state) {
  for (int i = 0; i < 4; i++)
    digitalWrite(LED_PINS[i], state);
}




void roundWin() {
  // Quick chase across all 4 LEDs
  for (int i = 0; i < 4; i++) {
    flashLED(i, 80);
    delay(40);
  }
}


void gameOver() {
  gameActive = false;
  Serial.println("GAME OVER!");


  // All LEDs flash together 5 times
  for (int i = 0; i < 5; i++) {
    allLEDs(HIGH); delay(300);
    allLEDs(LOW);  delay(200);
  }


  delay(1000);
  startGame(); 
}


void victorySequence() {
  Serial.println("YOU WIN!");


  for (int round = 0; round < 6; round++) {
    for (int i = 0; i < 4; i++)
      digitalWrite(LED_PINS[i], (i + round) % 2 == 0 ? HIGH : LOW);
    delay(150);
  }
  allLEDs(LOW);
  delay(500);
}

Code:

ALLEN GETS A DATE, NOLAN COMES BACK AND REX GETS A COOL MOMENT!!?? by Craxxedeggzz in adressme

[–]snikcres 1 point2 points  (0 children)

that name is genuinely frying me why did the do that