LEDs and Buttons

  • Name of puzzle: Stop the bomb.
  • The idea of this puzzle was to find away to stop the lights from blinking with the right clicking combination.
  • I managed to configure the buttons and LEDs to separate digital pins and control them with code.However, I don’t know how to input the number of times the button was clicked in order to result in something.
  • In the end this became more of a learning experience, as it took me longer than expected to debug the mechanical components.
const int led = 8; //red
const int led2 = 10; //blue
const int led3 = 3;//green
const int blueButton = 6;
const int redButton = 5;
const int greenButton = 4;


void setup() {
  pinMode(led, OUTPUT);
  pinMode(led2, OUTPUT);
  pinMode(led3, OUTPUT);
  pinMode(blueButton, INPUT_PULLUP);
  pinMode(redButton, INPUT_PULLUP);
  pinMode(greenButton, INPUT_PULLUP);
};
void loop() {
  bool bluebuttonState = digitalRead(blueButton);
  bool redbuttonState = digitalRead(redButton);
  bool greenbuttonState = digitalRead(greenButton);


  if (bluebuttonState == HIGH) {
    digitalWrite(led, LOW);

  } else {
    digitalWrite(led, HIGH);

  };
  if (redbuttonState == HIGH) {
    digitalWrite(led, LOW);
    digitalWrite(led2, LOW);
    digitalWrite(led3, LOW);

  } else {
    digitalWrite(led, HIGH);
    digitalWrite(led2, HIGH);
    digitalWrite(led3, HIGH);

  };

  if (greenbuttonState == HIGH) {

    digitalWrite(led2, LOW);

  } else {

    digitalWrite(led2, HIGH);

  };

};

Leave a Reply