Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Declaring Variables for Neopixels
- #include <Adafruit_NeoPixel.h>
- #define PIN 6
- #define NUM_LEDS 64
- Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUM_LEDS, PIN, NEO_GRB + NEO_KHZ800);
- //Declaring Servo
- #include <Servo.h>
- Servo servodoor;
- int servopin = 13;
- // Declaring 12 Button Variables
- int buttona = 2;
- int counta = 0;
- boolean curBa = false;
- boolean prevBa = false;
- int buttonb = 3;
- int countb = 0;
- boolean curBb = false;
- boolean prevBb = false;
- int buttonc = 4;
- int countc = 0;
- boolean curBc = false;
- boolean prevBc = false;
- int buttond = 5;
- int countd = 0;
- boolean curBd = false;
- boolean prevBd = false;
- int buttone = 7;
- int counte = 0;
- boolean curBe = false;
- boolean prevBe = false;
- int buttonf = 8;
- int countf = 0;
- boolean curBf = false;
- boolean prevBf = false;
- int buttong = 9;
- int countg = 0;
- boolean curBg = false;
- boolean prevBg = false;
- int buttonh = 10;
- int counth = 0;
- boolean curBh = false;
- boolean prevBh = false;
- int buttoni = 12;
- int counti = 0;
- boolean curBi = false;
- boolean prevBi = false;
- int buttonj = 13;
- int countj = 0;
- boolean curBj = false;
- boolean prevBj = false;
- void setup() {
- // put your setup code here, to run once:
- strip.begin();
- strip.show();
- servodoor.attach(servopin);
- servodoor.write(90);// The door is closed
- Serial.begin(9600);
- // declaring the pins
- pinMode(buttona, INPUT);
- pinMode(buttonb, INPUT);
- pinMode(buttonc, INPUT);
- pinMode(buttond, INPUT);
- pinMode(buttone, INPUT);
- pinMode(buttonf, INPUT);
- pinMode(buttong, INPUT);
- pinMode(buttonh, INPUT);
- pinMode(buttoni, INPUT);
- pinMode(buttonj, INPUT);
- pinMode(6, OUTPUT);
- pinMode(13, OUTPUT);
- }
- void loop() {
- // put your main code here, to run repeatedly:
- //The buttons count but if it becomes greater than 1 it returns to 0
- //BUTTON A, light 1
- curBa = digitalRead(buttona);
- Serial.print("count a is ");
- Serial.println(counta);
- if (curBa != prevBa) {
- if (curBa == HIGH) {
- counta++;
- }
- delay(70);
- }
- prevBa = curBa;
- if (counta > 1) {
- counta = 0;
- }
- //BUTTON B, light 2
- curBb = digitalRead(buttonb);
- Serial.print("count is ");
- Serial.println(countb);
- if (curBb != prevBb) {
- if (curBb == HIGH) {
- countb++;
- }
- delay(70);
- }
- prevBb = curBb;
- if (countb > 1) {
- countb = 0;
- }
- //BUTTON C, light 3
- curBc = digitalRead(buttonc);
- if (curBc != prevBc) {
- if (curBc == HIGH) {
- countc++;
- }
- delay(70);
- }
- prevBc = curBc;
- if (countc > 1) {
- countc = 0;
- }
- //BUTTON D, light 4
- curBd = digitalRead(buttond);
- if (curBd != prevBd) {
- if (curBd == HIGH) {
- countd++;
- }
- delay(70);
- }
- prevBd = curBd;
- if (countd > 1) {
- countd = 0;
- }
- //BUTTON E, light 5
- curBe = digitalRead(buttone);
- if (curBe != prevBe) {
- if (curBe == HIGH) {
- counte++;
- }
- delay(70);
- }
- prevBe = curBe;
- if (counte > 1) {
- counte = 0;
- }
- //BUTTON F, light 6
- curBf = digitalRead(buttonf);
- if (curBf != prevBf) {
- if (curBf == HIGH) {
- countf++;
- }
- delay(70);
- }
- prevBf = curBf;
- if (countf > 1) {
- countf = 0;
- }
- //BUTTON G, light 7
- curBg = digitalRead(buttong);
- if (curBg != prevBg) {
- if (curBg == HIGH) {
- countg++;
- }
- delay(70);
- }
- prevBg = curBg;
- if (countg > 1) {
- countg = 0;
- }
- //BUTTON H, light 8
- curBh = digitalRead(buttonh);
- if (curBh != prevBh) {
- if (curBh == HIGH) {
- counth++;
- }
- delay(70);
- }
- prevBh = curBh;
- if (counth > 1) {
- counth = 0;
- }
- //BUTTON I, light 9
- curBi = digitalRead(buttoni);
- if (curBi != prevBi) {
- if (curBi == HIGH) {
- counti++;
- }
- delay(70);
- }
- prevBi = curBi;
- if (counti > 1) {
- counti = 0;
- }
- //BUTTON J, light 0
- curBj = digitalRead(buttonj);
- if (curBj != prevBj) {
- if (curBj == HIGH) {
- countj++;
- }
- delay(70);
- }
- prevBj = curBj;
- if (countj > 1) {
- countj = 0;
- }
- // How the lights turn on, if the button is pressed and it count is equal to 1
- //the neopixel lights up
- if (counta == 1) {
- strip.setPixelColor(0, strip.Color(255, 0, 0));
- strip.show();
- } else {
- strip.setPixelColor(0, strip.Color(0, 0, 0));
- strip.show();
- }
- if (countb == 1) {
- strip.setPixelColor(1, strip.Color(255, 0, 0));
- strip.show();
- } else {
- strip.setPixelColor(1, strip.Color(0, 0, 0));
- strip.show();
- }
- if (countc == 1) {
- strip.setPixelColor(2, strip.Color(255, 0, 0));
- strip.show();
- } else {
- strip.setPixelColor(2, strip.Color(0, 0, 0));
- strip.show();
- }
- if (countd == 1) {
- strip.setPixelColor(3, strip.Color(255, 0, 0));
- strip.show();
- } else {
- strip.setPixelColor(3, strip.Color(0, 0, 0));
- strip.show();
- }
- if (counte == 1) {
- strip.setPixelColor(4, strip.Color(255, 0, 0));
- strip.show();
- } else {
- strip.setPixelColor(4, strip.Color(0, 0, 0));
- strip.show();
- }
- if (countf == 1) {
- strip.setPixelColor(5, strip.Color(255, 0, 0));
- strip.show();
- } else {
- strip.setPixelColor(5, strip.Color(0, 0, 0));
- strip.show();
- }
- if (countg == 1) {
- strip.setPixelColor(6, strip.Color(255, 0, 0));
- strip.show();
- } else {
- strip.setPixelColor(6, strip.Color(0, 0, 0));
- strip.show();
- }
- if (counth == 1) {
- strip.setPixelColor(7, strip.Color(255, 0, 0));
- strip.show();
- } else {
- strip.setPixelColor(7, strip.Color(0, 0, 0));
- strip.show();
- }
- if (counti == 1) {
- strip.setPixelColor(8, strip.Color(255, 0, 0));
- strip.show();
- } else {
- strip.setPixelColor(8, strip.Color(0, 0, 0));
- strip.show();
- }
- if (countj == 1) {
- strip.setPixelColor(9, strip.Color(255, 0, 0));
- strip.show();
- } else {
- strip.setPixelColor(9, strip.Color(0, 0, 0));
- strip.show();
- }
- //DOOR CONTROLS
- //if all the four corect buttons are pressed, the servo is turned and the player receives the wire
- if (countf == 1 && countc == 1 && countg == 1 && countj == 1) {
- servodoor.write(180);
- } else {
- servodoor.write(90);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement