SHARE
TWEET

Untitled

a guest Jun 12th, 2019 67 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. int PUSH_BUTTON_1 = 41;
  2. int PUSH_BUTTON_2 = 49;
  3. int PUSH_BUTTON_3 = 47;
  4. int PUSH_BUTTON_4 = 43;
  5. int PUSH_BUTTON_5 = 51;
  6. int PUSH_BUTTON_6 = 45;
  7. int PUSH_BUTTON_7 = 53;
  8. int DIRECTION_SWITCH = 9;
  9.  
  10. int clockPins[4] = { 22,25,28,31 }; // pin 11
  11. int latchPins[4] = { 23,26,29,32 }; // pin 12
  12. int dataPins[4] = { 24,27,30,33 }; // pin 14
  13. int output[4];
  14. int room[4];
  15. int temp;
  16. int button1, button2, button3, button4, button5, button6, button7, directionSwitch;
  17.  
  18. void setup() {
  19.   Serial.begin(9600);
  20.   Serial.print("setup");
  21.   int room[4] = {0,0,0,0};
  22.   int output[4] = {111,111,111,111};
  23.  
  24.   pinMode(PUSH_BUTTON_1, INPUT);
  25.   pinMode(PUSH_BUTTON_2, INPUT);
  26.   pinMode(PUSH_BUTTON_3, INPUT);
  27.   pinMode(PUSH_BUTTON_4, INPUT);
  28.   pinMode(PUSH_BUTTON_5, INPUT);
  29.   pinMode(PUSH_BUTTON_6, INPUT);
  30.   pinMode(PUSH_BUTTON_7, INPUT);
  31.   pinMode(DIRECTION_SWITCH, INPUT);
  32.  
  33.   digitalWrite(PUSH_BUTTON_1, HIGH);
  34.   digitalWrite(PUSH_BUTTON_2, HIGH);
  35.   digitalWrite(PUSH_BUTTON_3, HIGH);
  36.   digitalWrite(PUSH_BUTTON_4, HIGH);
  37.   digitalWrite(PUSH_BUTTON_5, HIGH);
  38.   digitalWrite(PUSH_BUTTON_6, HIGH);
  39.   digitalWrite(PUSH_BUTTON_7, HIGH);
  40.   digitalWrite(DIRECTION_SWITCH, HIGH);
  41.  
  42.   for (int i = 0; i < 4; i++) {
  43.     pinMode(clockPins[i], OUTPUT);
  44.     pinMode(latchPins[i], OUTPUT);
  45.     pinMode(dataPins[i], OUTPUT);
  46.   }
  47.  
  48.   writeAllRegisters();
  49. }
  50.  
  51. void writeAllRegisters() {
  52.   for (int i = 0; i < 4; i++) {
  53.     writeRegister(i);
  54.   }
  55. }
  56.  
  57. void writeRegister(int regNum) {
  58.   digitalWrite(latchPins[regNum],LOW);  
  59.   temp = output[regNum];
  60.   if(temp != 111){
  61.     temp += 128;
  62.   }
  63.   shiftOut(dataPins[regNum], clockPins[regNum], MSBFIRST, temp);
  64.   digitalWrite(latchPins[regNum],HIGH);
  65. }
  66.  
  67. void setOne(int regNum) {
  68.   output[regNum] = 9;
  69. }
  70.  
  71. void setTwo(int regNum) {
  72.   output[regNum] = 87;
  73. }
  74.  
  75. void setThree(int regNum) {
  76.   output[regNum] = 93;
  77. }
  78.  
  79. void setFour(int regNum) {
  80.   output[regNum] = 57;
  81. }
  82.  
  83. void setFive(int regNum) {
  84.   output[regNum] = 124;
  85. }
  86.  
  87. void setSix(int regNum) {
  88.   output[regNum] = 126;
  89. }
  90.  
  91. void setSeven(int regNum) {
  92.   output[regNum] = 73;
  93. }
  94.  
  95. void setEight(int regNum) {
  96.   output[regNum] = 127;
  97. }
  98.  
  99. void setNine(int regNum) {
  100.   output[regNum] = 125;
  101. }
  102.  
  103. void setZero(int regNum) {
  104.   output[regNum] = 111;
  105. }
  106.  
  107. void setH(int regNum){
  108.   output[regNum] = 59;
  109. }
  110.  
  111. void setHex(int regNum, int number){  
  112.   if(number > 9){
  113.     setH(regNum);
  114.   }
  115.   if(number == 0){
  116.     setZero(regNum);
  117.   }
  118.   if(number == 1){
  119.     setOne(regNum);
  120.   }
  121.   if(number == 2){
  122.     setTwo(regNum);
  123.   }
  124.   if(number == 3){
  125.     setThree(regNum);
  126.   }
  127.   if(number == 4){
  128.     setFour(regNum);
  129.   }
  130.   if(number == 5){
  131.     setFive(regNum);
  132.   }
  133.   if(number == 6){
  134.     setSix(regNum);
  135.   }
  136.   if(number == 7){
  137.     setSeven(regNum);
  138.   }
  139.   if(number == 8){
  140.     setEight(regNum);
  141.   }
  142.   if(number == 9){
  143.     setNine(regNum);
  144.   }
  145. }
  146.  
  147. void setAllHex(){
  148.   for(int i=0;i<4;i++){
  149.     setHex(i,room[i]);
  150.   }
  151. }
  152.  
  153.  
  154. void loop() {  
  155.   Serial.print("ROOMS: ");
  156.   Serial.print(room[0]);
  157.   Serial.print(room[1]);
  158.   Serial.print(room[2]);
  159.   Serial.print(room[3]);
  160.   Serial.println();
  161.   button1 = digitalRead(PUSH_BUTTON_1);
  162.   button2 = digitalRead(PUSH_BUTTON_2);
  163.   button3 = digitalRead(PUSH_BUTTON_3);
  164.   button4 = digitalRead(PUSH_BUTTON_4);
  165.   button5 = digitalRead(PUSH_BUTTON_5);
  166.   button6 = digitalRead(PUSH_BUTTON_6);
  167.   button7 = digitalRead(PUSH_BUTTON_7);
  168.   directionSwitch = digitalRead(DIRECTION_SWITCH);
  169.  
  170.   if (button1 == LOW) {
  171.     Serial.println("BUTTON1");
  172.     if (directionSwitch == LOW) {
  173.       room[0]++;
  174.     }
  175.     else {
  176.       if (room[0] > 0) {
  177.         room[0]--;
  178.       }
  179.     }
  180.   }
  181.  
  182.   if (button2 == LOW) {
  183.     Serial.println("BUTTON2");
  184.     if (directionSwitch == LOW) {
  185.       if (room[0] > 0) {
  186.         room[0]--;
  187.         room[1]++;
  188.       }
  189.     }
  190.     else {
  191.       if (room[1] > 0) {
  192.         room[0]++;
  193.         room[1]--;
  194.       }
  195.     }
  196.   }
  197.  
  198.   if (button3 == LOW) {
  199.     Serial.println("BUTTON3");
  200.     if (directionSwitch == LOW) {
  201.       if (room[0] > 0) {
  202.         room[0]--;
  203.         room[2]++;
  204.       }
  205.     }
  206.     else {
  207.       if (room[2] > 0) {
  208.         room[2]--;
  209.         room[0]++;
  210.       }
  211.     }
  212.   }
  213.  
  214.   if (button4 == LOW) {
  215.     Serial.println("BUTTON4");
  216.     if (directionSwitch == LOW) {
  217.       if (room[1] > 0) {
  218.         room[1]--;
  219.         room[2]++;
  220.       }
  221.     }
  222.     else {
  223.       if (room[2] > 0) {
  224.         room[2]--;
  225.         room[1]++;
  226.       }
  227.     }
  228.   }
  229.  
  230.   if (button5 == LOW) {
  231.     Serial.println("BUTTON5");
  232.     if (directionSwitch == LOW) {
  233.       if (room[1] > 0) {
  234.         room[1]--;
  235.         room[3]++;
  236.       }
  237.     }
  238.     else {
  239.       if (room[3] > 0) {
  240.         room[3]--;
  241.         room[1]++;
  242.       }
  243.     }
  244.   }
  245.  
  246.   if (button6 == LOW) {
  247.     Serial.println("BUTTON6");
  248.     if (directionSwitch == LOW) {
  249.       if (room[2] > 0) {
  250.         room[2]--;
  251.         room[3]++;
  252.       }
  253.     }
  254.     else {
  255.       if (room[3] > 0) {
  256.         room[3]--;
  257.         room[2]++;
  258.       }
  259.     }
  260.   }
  261.  
  262.   if (button7 == LOW) {
  263.     Serial.println("BUTTON7");
  264.     if (directionSwitch == LOW) {
  265.       if (room[3] > 0) {
  266.         room[3]--;
  267.       }
  268.     }
  269.     else {
  270.       room[3]++;
  271.     }
  272.   }
  273.   delay(250);
  274.  
  275.   setAllHex();
  276.   writeAllRegisters();
  277. }
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