Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int firstButton = 2;
- int secondButton = 3;
- int thirdButton = 4;
- int fourthButton = 5;
- unsigned long startMillis;
- unsigned long currentMillis;
- const unsigned long period = 1000;
- void setup() {
- const int redLEDPin = 10;
- const int greenLEDPin = 9;
- const int secondGreenLEDPin = 11;
- const int secondRedLEDPin = 12;
- const int thirdGreenLEDPin = 8;
- const int thirdRedLEDPin = 13;
- const int fourthRedLEDPin = 6;
- const int fourthGreenLEDPin = 7;
- pinMode(9, OUTPUT); // First blue light
- pinMode(10, OUTPUT); // first green light
- pinMode(2, INPUT); // first button
- pinMode(12, OUTPUT); // second green light
- pinMode(11, OUTPUT); // second blue light
- pinMode(3, INPUT); // Second button
- pinMode(13, OUTPUT); // third green light
- pinMode(8, OUTPUT); // third blue light
- pinMode(4, INPUT); // Third button
- pinMode(6, OUTPUT); // Fourth green light
- pinMode(7, OUTPUT); // Fourth blue light
- pinMode(5, INPUT); // fourth button
- pinMode(1, OUTPUT); // Sound
- }
- void loop() {
- int whichLight(random(1,5));
- int currentMillis = millis();
- if (whichLight == 1) {
- firstButton = digitalRead(2);
- int lightOne(random(1, 3));
- if (lightOne == 1) {
- digitalWrite(10, HIGH); // first green light
- }
- else {
- digitalWrite(9, HIGH); // first blue light
- tone(1, 880, 50);
- }
- if (firstButton == HIGH) {
- digitalWrite(10, LOW);
- delay(150);
- }
- delay(1000);
- digitalWrite(10, LOW);
- digitalWrite(9, LOW);
- delay(50);
- }
- else if (whichLight == 2) {
- secondButton = digitalRead(3);
- int lightSecond(random(1, 3));
- if (lightSecond == 1) {
- digitalWrite(12, HIGH); // second green light
- }
- else {
- digitalWrite(11, HIGH); // second blue light
- tone(1, 880, 50);
- }
- if (secondButton == HIGH) {
- digitalWrite(12, LOW);
- delay(150);
- }
- delay(1000);
- digitalWrite(12, LOW);
- digitalWrite(11, LOW);
- delay(50);
- }
- else if (whichLight == 3) {
- thirdButton = digitalRead(4);
- int lightThird(random(1, 3));
- if (lightThird == 1) {
- digitalWrite(13, HIGH); // third green light
- }
- else {
- digitalWrite(8, HIGH); // third blue light
- tone(1, 880, 50);
- }
- if (thirdButton == HIGH) {
- digitalWrite(13, LOW);
- delay(150);
- }
- delay(1000);
- digitalWrite(13, LOW);
- digitalWrite(8, LOW);
- delay(50);
- }
- else if(whichLight == 4) {
- fourthButton = digitalRead(5);
- int lightFourth(random(1, 3));
- if (lightFourth == 1){
- digitalWrite(6, HIGH); // fourth green light
- }
- else {
- digitalWrite(7, HIGH); // fourth blue light
- tone(1, 880, 50);
- }
- if (fourthButton == HIGH) {
- digitalWrite(6, LOW);
- delay(150);
- }
- delay(1000);
- digitalWrite(7, LOW);
- digitalWrite(6, LOW);
- delay(50);
- }
- }
Add Comment
Please, Sign In to add comment