Guest User

Untitled

a guest
Jul 22nd, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.14 KB | None | 0 0
  1. #include <SPI.h>
  2. #include <LiquidCrystal.h>
  3. #include <glcd.h>
  4. #include <fonts/allFonts.h>
  5. #define out1 2
  6. #define out2 3
  7. #define out3 4
  8. #define in 5
  9. #define button 10
  10. unsigned int KMAP[2][4];
  11. String BOOL = "";
  12. String Old = "1";
  13. int A;
  14. String TEST = "Test";
  15.  
  16. void setup()
  17. /* This section sets up the intial conditions required to execute
  18. / all subsequent functions, mostly setting the pins as input
  19. / and output and intializing the LCD libraries.
  20. */
  21. {
  22.  
  23. GLCD.Init(); //Initialize the graphic LCD
  24. GLCD.SelectFont(System5x7); //Select the 5x7 font
  25. pinMode(out1, OUTPUT); //Set these pins to output
  26. pinMode(out2, OUTPUT);
  27. pinMode(out3, OUTPUT);
  28. pinMode(in, INPUT); //Set these pins to input
  29. pinMode(button, INPUT);
  30. //digitalWrite(button, HIGH); //Turn on internal pullup resistor
  31. Serial.begin(9600); //Start serial communication
  32. Serial.println("Serial begin."); //Print the test line
  33.  
  34. }
  35. void loop()
  36. {
  37. A = digitalRead(10);
  38. if (A == LOW) {
  39. digitalWrite(13, HIGH);
  40. do {
  41. READ;
  42. } while (A == LOW);
  43. }
  44. //Serial.println(TEST);
  45. //delay(1000);
  46. //TEST += "ing";
  47. CONV;
  48. DISP;
  49.  
  50. }
  51.  
  52.  
  53. void READ()
  54. /* This section is the read and store section; it interacts with
  55. / the outside world via the designated output and input pins.
  56. / This section will write to each output, counting up in binary
  57. / with the MSB called A, and the LSB called C.
  58. */
  59. {
  60. Serial.println("Read running");
  61.  
  62. digitalWrite(out1, LOW); //Output C
  63. digitalWrite(out2, LOW); //Output B
  64. digitalWrite(out3, LOW); //Output A
  65. delay(2);
  66. KMAP[0][0] = digitalRead(in); //A'B'C'
  67. digitalWrite(out1, HIGH);
  68. delay(2);
  69. KMAP[1][0] = digitalRead(in); //A'B'C
  70. digitalWrite(out1, LOW);
  71. digitalWrite(out2, HIGH);
  72. delay(2);
  73. KMAP[0][1] = digitalRead(in); //A'BC'
  74. digitalWrite(out1, HIGH);
  75. delay(2);
  76. KMAP[1][1] = digitalRead(in); //A'BC
  77. digitalWrite(out1, LOW);
  78. digitalWrite(out2, LOW);
  79. digitalWrite(out3, HIGH);
  80. delay(2);
  81. KMAP[0][3] = digitalRead(in); //AB'C'
  82. digitalWrite(out1, HIGH);
  83. delay(2);
  84. KMAP[1][3] = digitalRead(in); //AB'C
  85. digitalWrite(out1, LOW);
  86. digitalWrite(out2, HIGH);
  87. delay(2);
  88. KMAP[0][2] = digitalRead(in); //ABC'
  89. digitalWrite(out1, HIGH);
  90. delay(2);
  91. KMAP[1][2] = digitalRead(in); //ABC
  92. Serial.print(KMAP[0][0]);
  93.  
  94. }
  95.  
  96. void CONV()
  97. /* This is the Karnaugh mapping section, which checks for contiguous
  98. / sections of true outputs on a grid created in the array BOOL.
  99. / This simplifies the expression by eliminating variables whose level
  100. / is irrelevant because the output is true when it is true or false.
  101. */
  102. {
  103. Serial.println("Convert running");
  104. if (KMAP[0][0] && KMAP[1][0] && KMAP[0][3] && KMAP[1][3]) {
  105. BOOL += "+ B'";
  106. }
  107. if (KMAP[0][0] && KMAP[1][0] && KMAP[0][1] && KMAP[1][1]) {
  108. BOOL += "+ A' ";
  109. }
  110. if (KMAP[0][1] && KMAP[1][1] && KMAP[0][2] && KMAP[1][2]) {
  111. BOOL += "+ B ";
  112. }
  113. if (KMAP[0][2] && KMAP[1][2] && KMAP[0][3] && KMAP[1][3]) {
  114. BOOL += "+ A ";
  115. }
  116. if (KMAP[0][0] && KMAP[0][1] && KMAP[0][2] && KMAP[0][3]) {
  117. BOOL += "+ C'";
  118. }
  119. if (KMAP[1][0] && KMAP[1][1] && KMAP[1][2] && KMAP[1][3]) {
  120. BOOL += "+ C";
  121. }
  122. if (KMAP[0][0] && KMAP[1][0]) {
  123. BOOL += "+ A'B' ";
  124. }
  125. if (KMAP[0][1] && KMAP[1][1]) {
  126. BOOL += "+ A'B ";
  127. }
  128. if (KMAP[0][2] && KMAP[1][2]) {
  129. BOOL += "+ AB ";
  130. }
  131. if (KMAP[0][3] && KMAP[1][3]) {
  132. BOOL += "+ AB' ";
  133. }
  134. if (KMAP[0][0]) {
  135. BOOL += "+ A'B'C' ";
  136. }
  137. if (KMAP[1][0]) {
  138. BOOL += "+ A'B'C ";
  139. }
  140. if (KMAP[0][1]) {
  141. BOOL += "+ A'BC' ";
  142. }
  143. if (KMAP[1][1]) {
  144. BOOL += "+ A'BC ";
  145. }
  146. if (KMAP[0][2]) {
  147. BOOL += "+ ABC' ";
  148. }
  149. if (KMAP[1][2]) {
  150. BOOL += "+ ABC ";
  151. }
  152. if (KMAP[0][3]) {
  153. BOOL += "+ AB'C' ";
  154. }
  155. if (KMAP[1][3]) {
  156. BOOL += "+ AB'C ";
  157. }
  158. }
  159.  
  160. void DISP()
  161. {
  162. Serial.println("Display running");
  163. if (Old != BOOL) {
  164. Serial.println(BOOL);
  165. Old = BOOL;
  166. }
  167.  
  168. }
Add Comment
Please, Sign In to add comment