SHARE
TWEET

Untitled

a guest Apr 18th, 2019 78 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //Declaring Variables for Neopixels
  2. #include <Adafruit_NeoPixel.h>
  3. #define PIN 6
  4. #define NUM_LEDS 64
  5. Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUM_LEDS, PIN, NEO_GRB + NEO_KHZ800);
  6.  
  7. //Declaring Servo
  8. #include <Servo.h>
  9.  
  10. Servo servodoor;
  11. int servopin = 13;
  12.  
  13. // Declaring 12 Button Variables
  14. int buttona = 2;
  15. int counta = 0;
  16. boolean curBa = false;
  17. boolean prevBa = false;
  18.  
  19. int buttonb = 3;
  20. int countb = 0;
  21. boolean curBb = false;
  22. boolean prevBb = false;
  23.  
  24. int buttonc = 4;
  25. int countc = 0;
  26. boolean curBc = false;
  27. boolean prevBc = false;
  28.  
  29. int buttond = 5;
  30. int countd = 0;
  31. boolean curBd = false;
  32. boolean prevBd = false;
  33.  
  34. int buttone = 7;
  35. int counte = 0;
  36. boolean curBe = false;
  37. boolean prevBe = false;
  38.  
  39. int buttonf = 8;
  40. int countf = 0;
  41. boolean curBf = false;
  42. boolean prevBf = false;
  43.  
  44. int buttong = 9;
  45. int countg = 0;
  46. boolean curBg = false;
  47. boolean prevBg = false;
  48.  
  49. int buttonh = 10;
  50. int counth = 0;
  51. boolean curBh = false;
  52. boolean prevBh = false;
  53.  
  54. int buttoni = 12;
  55. int counti = 0;
  56. boolean curBi = false;
  57. boolean prevBi = false;
  58.  
  59. int buttonj = 13;
  60. int countj = 0;
  61. boolean curBj = false;
  62. boolean prevBj = false;
  63.  
  64. void setup() {
  65.  
  66.   // put your setup code here, to run once:
  67.   strip.begin();
  68.   strip.show();
  69.   servodoor.attach(servopin);
  70.   servodoor.write(90);// The door is closed
  71.   Serial.begin(9600);
  72.  
  73. // declaring the pins
  74.   pinMode(buttona, INPUT);
  75.   pinMode(buttonb, INPUT);
  76.   pinMode(buttonc, INPUT);
  77.   pinMode(buttond, INPUT);
  78.   pinMode(buttone, INPUT);
  79.   pinMode(buttonf, INPUT);
  80.   pinMode(buttong, INPUT);
  81.   pinMode(buttonh, INPUT);
  82.   pinMode(buttoni, INPUT);
  83.   pinMode(buttonj, INPUT);
  84.   pinMode(6, OUTPUT);
  85.   pinMode(13, OUTPUT);
  86. }
  87.  
  88. void loop() {
  89.   // put your main code here, to run repeatedly:
  90.   //The buttons count but if it becomes greater than 1 it returns to 0
  91.   //BUTTON A, light 1
  92.   curBa = digitalRead(buttona);
  93.   Serial.print("count a is ");
  94.   Serial.println(counta);
  95.   if (curBa != prevBa) {
  96.  
  97.     if (curBa == HIGH) {
  98.       counta++;
  99.  
  100.     }
  101.     delay(70);
  102.   }
  103.   prevBa = curBa;
  104.   if (counta > 1) {
  105.     counta = 0;
  106.   }
  107.   //BUTTON B, light 2
  108.  
  109.   curBb = digitalRead(buttonb);
  110.   Serial.print("count is ");
  111.   Serial.println(countb);
  112.   if (curBb != prevBb) {
  113.  
  114.     if (curBb == HIGH) {
  115.       countb++;
  116.     }
  117.     delay(70);
  118.   }
  119.   prevBb = curBb;
  120.  
  121.   if (countb > 1) {
  122.     countb = 0;
  123.  
  124.   }
  125.  
  126.   //BUTTON C, light 3
  127.   curBc = digitalRead(buttonc);
  128.   if (curBc != prevBc) {
  129.  
  130.     if (curBc == HIGH) {
  131.       countc++;
  132.     }
  133.     delay(70);
  134.   }
  135.   prevBc = curBc;
  136.   if (countc > 1) {
  137.     countc = 0;
  138.   }
  139.  
  140.   //BUTTON D, light 4
  141.   curBd = digitalRead(buttond);
  142.   if (curBd != prevBd) {
  143.  
  144.     if (curBd == HIGH) {
  145.       countd++;
  146.     }
  147.     delay(70);
  148.   }
  149.   prevBd = curBd;
  150.   if (countd > 1) {
  151.     countd = 0;
  152.   }
  153.  
  154.   //BUTTON E, light 5
  155.   curBe = digitalRead(buttone);
  156.   if (curBe != prevBe) {
  157.  
  158.     if (curBe == HIGH) {
  159.       counte++;
  160.     }
  161.     delay(70);
  162.   }
  163.   prevBe = curBe;
  164.   if (counte > 1) {
  165.     counte = 0;
  166.   }
  167.  
  168.   //BUTTON F, light 6
  169.   curBf = digitalRead(buttonf);
  170.   if (curBf != prevBf) {
  171.  
  172.     if (curBf == HIGH) {
  173.       countf++;
  174.     }
  175.     delay(70);
  176.   }
  177.   prevBf = curBf;
  178.   if (countf > 1) {
  179.     countf = 0;
  180.   }
  181.  
  182.   //BUTTON G, light 7
  183.   curBg = digitalRead(buttong);
  184.   if (curBg != prevBg) {
  185.  
  186.     if (curBg == HIGH) {
  187.       countg++;
  188.     }
  189.     delay(70);
  190.   }
  191.   prevBg = curBg;
  192.   if (countg > 1) {
  193.     countg = 0;
  194.   }
  195.  
  196.   //BUTTON H, light 8
  197.   curBh = digitalRead(buttonh);
  198.   if (curBh != prevBh) {
  199.  
  200.     if (curBh == HIGH) {
  201.       counth++;
  202.     }
  203.     delay(70);
  204.   }
  205.   prevBh = curBh;
  206.   if (counth > 1) {
  207.     counth = 0;
  208.   }
  209.  
  210.   //BUTTON I, light 9
  211.   curBi = digitalRead(buttoni);
  212.   if (curBi != prevBi) {
  213.  
  214.     if (curBi == HIGH) {
  215.       counti++;
  216.     }
  217.     delay(70);
  218.   }
  219.   prevBi = curBi;
  220.   if (counti > 1) {
  221.     counti = 0;
  222.   }
  223.  
  224.   //BUTTON J, light 0
  225.   curBj = digitalRead(buttonj);
  226.   if (curBj != prevBj) {
  227.  
  228.     if (curBj == HIGH) {
  229.       countj++;
  230.     }
  231.     delay(70);
  232.   }
  233.   prevBj = curBj;
  234.   if (countj > 1) {
  235.     countj = 0;
  236.   }
  237.  
  238.   // How the lights turn on, if the button is pressed and it count is equal to 1
  239.   //the neopixel lights up
  240.  
  241.   if (counta == 1) {
  242.     strip.setPixelColor(0, strip.Color(255, 0, 0));
  243.     strip.show();
  244.   } else {
  245.     strip.setPixelColor(0, strip.Color(0, 0, 0));
  246.     strip.show();
  247.   }
  248.  
  249.   if (countb == 1) {
  250.     strip.setPixelColor(1, strip.Color(255, 0, 0));
  251.     strip.show();
  252.   } else {
  253.     strip.setPixelColor(1, strip.Color(0, 0, 0));
  254.     strip.show();
  255.   }
  256.  
  257.   if (countc == 1) {
  258.     strip.setPixelColor(2, strip.Color(255, 0, 0));
  259.     strip.show();
  260.   } else {
  261.     strip.setPixelColor(2, strip.Color(0, 0, 0));
  262.     strip.show();
  263.   }
  264.  
  265.   if (countd == 1) {
  266.     strip.setPixelColor(3, strip.Color(255, 0, 0));
  267.     strip.show();
  268.   } else {
  269.     strip.setPixelColor(3, strip.Color(0, 0, 0));
  270.     strip.show();
  271.   }
  272.  
  273.   if (counte == 1) {
  274.     strip.setPixelColor(4, strip.Color(255, 0, 0));
  275.     strip.show();
  276.   } else {
  277.     strip.setPixelColor(4, strip.Color(0, 0, 0));
  278.     strip.show();
  279.   }
  280.  
  281.   if (countf == 1) {
  282.     strip.setPixelColor(5, strip.Color(255, 0, 0));
  283.     strip.show();
  284.   } else {
  285.     strip.setPixelColor(5, strip.Color(0, 0, 0));
  286.     strip.show();
  287.   }
  288.  
  289.   if (countg == 1) {
  290.     strip.setPixelColor(6, strip.Color(255, 0, 0));
  291.     strip.show();
  292.   } else {
  293.     strip.setPixelColor(6, strip.Color(0, 0, 0));
  294.     strip.show();
  295.   }
  296.  
  297.   if (counth == 1) {
  298.     strip.setPixelColor(7, strip.Color(255, 0, 0));
  299.     strip.show();
  300.   } else {
  301.     strip.setPixelColor(7, strip.Color(0, 0, 0));
  302.     strip.show();
  303.   }
  304.  
  305.   if (counti == 1) {
  306.     strip.setPixelColor(8, strip.Color(255, 0, 0));
  307.     strip.show();
  308.   } else {
  309.     strip.setPixelColor(8, strip.Color(0, 0, 0));
  310.     strip.show();
  311.   }
  312.  
  313.   if (countj == 1) {
  314.     strip.setPixelColor(9, strip.Color(255, 0, 0));
  315.     strip.show();
  316.   } else {
  317.     strip.setPixelColor(9, strip.Color(0, 0, 0));
  318.     strip.show();
  319.   }
  320.  
  321.  
  322.   //DOOR CONTROLS
  323.   //if all the four corect buttons are pressed, the servo is turned and the player receives the wire
  324.   if (countf == 1 && countc == 1 && countg == 1 && countj == 1) {
  325.     servodoor.write(180);
  326.   } else {
  327.     servodoor.write(90);
  328.   }
  329. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top