0
|
1 #include <Arduino.h>
|
|
2 #include <LiquidCrystal.h>
|
|
3
|
|
4 const int pinLogicMain = 8;
|
|
5 const int pinLogicSecondary = 9;
|
|
6 const int pinNextGate = 10;
|
|
7 const int pinEnter = 11;
|
|
8 const int pinLed = 12;
|
|
9
|
|
10 int stateLogicMain = 0;
|
|
11 int stateLogicSecondary = 0;
|
|
12 int stateNextGate = 0;
|
|
13 int stateEnter = 0;
|
|
14 int stateLed = 0;
|
|
15
|
|
16 int logicModeEnabled = 0;
|
|
17
|
|
18 #define GATES_SIZE 7
|
|
19 const char* gates[GATES_SIZE] = {"AND", "OR", "NOT", "NAND", "NOR", "XOR", "XNOR"};
|
|
20 int gateSelected = -1;
|
|
21
|
|
22 const int rs = 2, en = 3, d4 = 4, d5 = 5, d6 = 6, d7 = 7;
|
|
23 LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
|
|
24
|
|
25 void setup()
|
|
26 {
|
|
27 Serial.begin(9600);
|
|
28
|
|
29 pinMode(pinLogicMain, INPUT);
|
|
30 pinMode(pinLogicSecondary, INPUT);
|
|
31 pinMode(pinNextGate, INPUT);
|
|
32 pinMode(pinEnter, INPUT);
|
|
33 pinMode(pinLed, OUTPUT);
|
|
34
|
|
35 lcd.begin(16, 2);
|
|
36 lcd.print("Select gate");
|
|
37 }
|
|
38
|
|
39 void ledControl(int enabled)
|
|
40 {
|
|
41 if (enabled) {
|
|
42 digitalWrite(pinLed, HIGH);
|
|
43 } else {
|
|
44 digitalWrite(pinLed, LOW);
|
|
45 }
|
|
46 }
|
|
47
|
|
48 void loop()
|
|
49 {
|
|
50 stateLogicMain = digitalRead(pinLogicMain);
|
|
51 stateLogicSecondary = digitalRead(pinLogicSecondary);
|
|
52 stateNextGate = digitalRead(pinNextGate);
|
|
53 stateEnter = digitalRead(pinEnter);
|
|
54 stateLed = digitalRead(pinLed);
|
|
55
|
|
56 if (stateNextGate == HIGH) {
|
|
57 logicModeEnabled = 0;
|
|
58
|
|
59 if (gateSelected + 1 < GATES_SIZE) {
|
|
60 gateSelected++;
|
|
61 } else {
|
|
62 gateSelected = 0;
|
|
63 }
|
|
64
|
|
65 lcd.clear();
|
|
66
|
|
67 char msg[16];
|
|
68 sprintf(msg, "%i -> %s", gateSelected, gates[gateSelected]);
|
|
69 lcd.setCursor(0, 0);
|
|
70 lcd.print(msg);
|
|
71 delay(500);
|
|
72 }
|
|
73
|
|
74 if (stateEnter == HIGH && logicModeEnabled == 0) {
|
|
75 logicModeEnabled = 1;
|
|
76 }
|
|
77
|
|
78 if (logicModeEnabled == 1) {
|
|
79 lcd.setCursor(0, 1);
|
|
80 lcd.print("Enabled");
|
|
81 lcd.setCursor(0, 0);
|
|
82
|
|
83 switch (gateSelected) {
|
|
84 case 0:
|
|
85 ledControl(stateLogicMain && stateLogicSecondary);
|
|
86 break;
|
|
87 case 1:
|
|
88 ledControl(stateLogicMain || stateLogicSecondary);
|
|
89 break;
|
|
90 case 2:
|
|
91 ledControl(!stateLogicMain);
|
|
92 break;
|
|
93 case 3:
|
|
94 ledControl(!(stateLogicMain && stateLogicSecondary));
|
|
95 break;
|
|
96 case 4:
|
|
97 ledControl(!(stateLogicMain || stateLogicSecondary));
|
|
98 break;
|
|
99 case 5:
|
|
100 ledControl(stateLogicMain != stateLogicSecondary);
|
|
101 break;
|
|
102 case 6:
|
|
103 ledControl(stateLogicMain == stateLogicSecondary);
|
|
104 break;
|
|
105 }
|
|
106 } else {
|
|
107 digitalWrite(pinLed, LOW);
|
|
108 }
|
|
109 }
|