top of page

Color Boop Code

#define but A0

#define R 11

#define G 9

#define B 10

#define light 2

 

bool butpush = false;

long long time = millis();

int timerLen = 30 * 1000;

int count = 0;

int deductions = 0;

 

void setup() {

  pinMode(but, INPUT);

  pinMode(R, OUTPUT);

  pinMode(G, OUTPUT);

  pinMode(B, OUTPUT);

  pinMode(light, OUTPUT);

}

 

void loop() {

  digitalWrite(light, HIGH);

  long long int endTime = millis() + timerLen;

  while (millis() < endTime) {

    if (analogRead(but) >= 512) {

      butpush = false;

      count++;

      delay(5000);

      if (analogRead(but) >= 512) {

        encode();

      }

      break;

    }

  }

  digitalWrite(light, LOW);

  delay(random(1000, timerLen / 2));

  deductions = count / 5;

  timerLen -= deductions * 2500;

}

 

void encode() {

  if (count <= 10) {

    digitalWrite(R, HIGH);

  } else if (count <= 20) {

    digitalWrite(G, HIGH);

  } else if (count <= 30) {

    digitalWrite(B, HIGH);

  } else if (count <= 40) {

    digitalWrite(G, HIGH);

    digitalWrite(B, HIGH);

  } else {

    digitalWrite(R, HIGH);

    digitalWrite(G, HIGH);

    digitalWrite(B, HIGH);

  }

  delay(10000);

  count = 0;

  digitalWrite(R, LOW);

  digitalWrite(G, LOW);

  digitalWrite(B, LOW);

}

bottom of page