Advertisement
tigerthelion

4 Segment LED

Feb 19th, 2018
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.13 KB | None | 0 0
  1. /*
  2.   Showing number 0-9 on a Common Anode 7-segment LED display
  3.   Displays the numbers 0-9 on the display, with one second inbetween.
  4.     A
  5.    ---
  6. F |   | B
  7.   | G |
  8.    ---
  9. E |   | C
  10.   |   |
  11.    ---
  12.     D
  13.   This example code is in the public domain.
  14.  */
  15. int i=0;
  16. // LED DISPLAY SET UP
  17. // Pin 2-8 is connected to the 7 segments of the display.
  18. // Array of what pins are connected to what UNO pinouts (See diagram and pull hair for details).
  19. int pinAssign[7] = {2,3,4,5,6,7,8}; //{A,B,C,D,E,F,G}
  20. // Display segment pinout Left to right (This Model D1 & D4 do not work)
  21. //Re enabled this block and disabled my while init statement below because it wasn't working
  22. int pinA=2;  
  23. int pinB=3;    
  24. int pinC=4;    
  25. int pinD=5;    
  26. int pinE=6;    
  27. int pinF=7;    
  28. int pinG=8;  
  29.  
  30.  
  31.  
  32.  
  33. //Display pins
  34. int D1;
  35. int D2 = 10;
  36. int D3 = 11;
  37. int D4;
  38. int disp = D2;
  39.  
  40. //Flood Set Up
  41. int floodInterval = 0;
  42. //BUTTON SET-UP
  43. int buttonLeft = 16;
  44. int buttonRight = 17;
  45. int buttonLstate = 0;
  46. int buttonRstate = 0;
  47.  
  48.  
  49.  
  50.  
  51. //Number Assignments Matrix. They follow the same clockwise pattern left to right as the top diagram
  52. int numMatrix[10][7] =
  53.   {
  54.     {0,0,0,0,0,0,1}, //Zero
  55.     {1,0,0,1,1,1,1}, //One
  56.     {0,0,1,0,0,1,0}, //Two
  57.     {0,0,0,0,1,1,0}, //Three
  58.     {1,0,0,1,1,0,0}, //Four
  59.     {0,1,0,0,1,0,0}, //Five
  60.     {0,1,0,0,0,0,0}, //Six
  61.     {0,0,0,1,1,1,1}, //Seven
  62.     {0,0,0,0,0,0,0}, //Eight
  63.     {0,0,0,1,1,0,0}, //Nine
  64.   };
  65. //int numZero[7] = {0,0,0,0,0,0,1};
  66. //int numOne[7] = {1,0,0,1,1,1,1};
  67. //int numTwo[7] = {0,0,1,0,0,1,0};
  68. //int numThree[7] = {0,0,0,0,1,1,0};
  69. //int numFour[7] = {1,0,0,1,1,0,0};
  70. //int numFive[7] = {0,1,0,0,1,0,0};
  71. //int numSix[7] = {0,1,0,0,0,0,0};
  72. //int numSeven[7] = {0,0,0,1,1,1,1};
  73. //int numEight[7] = {0,0,0,0,0,0,0};
  74. //int numNine[7] = {0,0,0,1,1,0,0};
  75. // the setup routine runs once when you press reset:
  76. void setup() {                
  77.   // initialize the digital pins as outputs. (not working? Or bad hardware)
  78. //while (i <= sizeof(pinAssign))
  79. //{
  80. //  pinMode(pinAssign[i], OUTPUT);
  81. //  i++;
  82. //}
  83. //i=0;  
  84.  
  85. //Un needed if above stmt is working
  86.   pinMode(pinA, OUTPUT);    
  87.   pinMode(pinB, OUTPUT);    
  88.   pinMode(pinC, OUTPUT);    
  89.   pinMode(pinD, OUTPUT);    
  90.   pinMode(pinE, OUTPUT);    
  91.   pinMode(pinF, OUTPUT);    
  92.   pinMode(pinG, OUTPUT);  
  93.  
  94.    
  95.   pinMode(D1, OUTPUT);  
  96.   pinMode(D2, OUTPUT);  
  97.   pinMode(D3, OUTPUT);  
  98.   pinMode(D4, OUTPUT);
  99.   Serial.begin(19200);
  100.  
  101.   delay(5000); //Safety init
  102. }
  103. //Assign the numbers to the pins
  104. void numdisplay(int disp, int num){
  105.  
  106.   while (i < 7){
  107.    
  108.     //Serial.println(numMatrix[num][i]);
  109.     digitalWrite(disp, HIGH);
  110.     digitalWrite(pinAssign[i], numMatrix[num][i]);
  111.     delay(5);
  112.     i++;
  113.    }
  114.    delay(200);
  115.    i =0;
  116.      
  117. }
  118.  
  119. //unhashed button function. Not reliable
  120. int buttonPress(int button)
  121. {
  122.   if (digitalRead(button) == HIGH)
  123.   {
  124.   delay(500);
  125.   return 1;
  126.   }
  127.   return 0;
  128. }
  129. // the loop routine runs over and over again forever:
  130. void loop() {
  131.  
  132. //Problem with this is- need to cycle between low and high to use two digits.
  133.  
  134.   numdisplay(D2,9);
  135.   numdisplay(D2,8);
  136.   numdisplay(D2,7);
  137.   numdisplay(D2,6);
  138.   numdisplay(D2,5);
  139.   numdisplay(D2,4);
  140.   numdisplay(D2,3);
  141.   numdisplay(D2,2);
  142.   numdisplay(D2,1);
  143.   numdisplay(D2,0);
  144.   numdisplay(D3,9);
  145.   numdisplay(D3,8);
  146.   numdisplay(D3,7);
  147.   numdisplay(D3,6);
  148.   numdisplay(D3,5);
  149.   numdisplay(D3,4);
  150.   numdisplay(D3,3);
  151.   numdisplay(D3,2);
  152.   numdisplay(D3,1);
  153.   numdisplay(D3,0);
  154.  
  155.  
  156. //BEGINNING OF ACTUAL FLOOD TABLE LOGIC FML
  157. //if (buttonPress(buttonLeft) == 1) {
  158. //    floodInterval++;
  159. //}
  160. //    if (0 <= floodInterval <= 9)
  161. //    {
  162. //      numdisplay(D3,floodInterval);
  163. //      
  164. //      
  165. //    }
  166. //    if (10 <= floodInterval <= 19) {
  167. //      numdisplay(D2,1);
  168. //      numdisplay(D3,(floodInterval - 10));
  169. //  
  170. //
  171. //    }
  172. //    if (20 <= floodInterval <= 29) {
  173. //      numdisplay(D2,2);
  174. //      numdisplay(D3,(floodInterval - 10));
  175. //
  176. //    }
  177. //    
  178. //  
  179. //  
  180. //
  181. //  
  182. //
  183. //
  184. //
  185. //if (buttonPress(buttonRight) == 1) {
  186. //  numdisplay(D3,9);
  187. //  delay(3000);
  188. //  digitalWrite(D3, LOW);
  189. //}
  190. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement