So putting the binary value of x onto PORTC doesn't turn the pins on and off? I'm not sure how this works then, I thought that it would turn be like if x is 101 in binary, then A0 would be high, A1 would be low, and A2 would be high. Anyway, this is my entire code.
#include <LiquidCrystal.h>
#include <ST7565.h>
#include <SPI.h>
#define in 10
#define button 9
#define SW1 8
byte KMAP/*2][4]*/;
String BOOL = "";
String Old = "";
byte t;
ST7565 glcd(9, 8, 7, 6, 5);
String BL = ("A'B'C'","A'B'C","A'BC'","A'BC","AB'C'","AB'C","ABC'","ABC");
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
void setup()
/* This section sets up the intial conditions required to execute
/ all subsequent functions, mostly setting the pins as input
/ and output and intializing the LCD libraries.
*/
{
//pinMode(outC, OUTPUT); //Set these pins to output
//pinMode(outB, OUTPUT);
//pinMode(outA, OUTPUT);
pinMode(in, INPUT); //Set these pins to input
digitalWrite(in, HIGH);
pinMode(button, INPUT);
digitalWrite(button, HIGH); //Turn on internal pullup resistor
Serial.begin(9600); //Start serial communication
Serial.println("Serial begin."); //Print the test line
Serial.println(freeRam());
//glcd.begin(0x18);
lcd.begin(16, 2);
//glcd.st7565_init();
//glcd.st7565_command(CMD_DISPLAY_ON);
//glcd.st7565_command(CMD_SET_ALLPTS_NORMAL);
pinMode(A0, OUTPUT);
pinMode(A1, OUTPUT);
pinMode(A2, OUTPUT);
//lcd.print("Hello World");
}
void loop()
{
if (digitalRead(button) == LOW) {
digitalWrite(13, HIGH);
READ();
CONV();
}
else {
digitalWrite(13, LOW);
}
DISP();
//glcd.display();
}
/*digitalWrite(13, LOW);
if (digitalRead(SW1) == LOW) {
DISPT();
}
else if (digitalRead(SW1) == HIGH) {
DISPB();
}*/
void READ()
/* This section is the read and store section; it interacts with
/ the outside world via the designated output and input pins.
/ This section will write to each output, counting up in binary
/ with the MSB called A, and the LSB called C.
*/
{
byte KMAP = B00000000;
byte x;
for (x = 0; x < 8; x++) {
PORTC = x;
delay(2);
bitWrite(KMAP, x, digitalRead(in));
}
}
void CONV()
/* This is the Karnaugh mapping section, which checks for contiguous
/ sections of true outputs on a grid created in the array KMAP.
/ This simplifies the expression by eliminating variables whose level
/ is irrelevant because the output is true when it is true or false.
/ Simplified expressions are added to string BOOL.
*/
{
BOOL = "";
byte TEMP = KMAP;
if (KMAP == 255) {
BOOL = "All conditions are true.";
t = 1;
return;
}
if (KMAP == 0) {
BOOL = "All conditions are false.";
t = 1;
return;
}
if (TEMP & 90) {
BOOL += "C' + ";
TEMP &= 165;
if (TEMP == 0) {
return;
}
}
if (TEMP & 165) {
BOOL += "C + ";
TEMP &= 90;
if (TEMP == 0) {
return;
}
}
if (TEMP & 15) {
BOOL += "A' + ";
TEMP &= 240;
if (TEMP == 0) {
return;
}
}
if (TEMP & 240) {
BOOL += "A + ";
TEMP &= 15;
if (TEMP == 0) {
return;
}
}
if (TEMP & 51) {
BOOL += "B' + ";
TEMP &= 204;
if (TEMP == 0) {
return;
}
}
if (TEMP & 204) {
BOOL += "B + ";
TEMP &= 51;
if (TEMP == 0) {
return;
}
}
if (TEMP & 3) {
BOOL += "A'B' + ";
TEMP &= 252;
if (TEMP == 0) {
return;
}
}
if (TEMP & 12) {
BOOL += "A'B + ";
TEMP &= 243;
if (TEMP == 0) {
return;
}
}
if (TEMP & 48) {
BOOL += "AB' + ";
TEMP &= 207;
if (TEMP == 0) {
return;
}
}
if (TEMP & 192) {
BOOL += "AB + ";
TEMP &= 63;
if (TEMP == 0) {
return;
}
}
if (TEMP & 5) {
BOOL += "A'C' + ";
TEMP &= 250;
if (TEMP == 0) {
return;
}
}
if (TEMP & 10) {
BOOL += "A'C + ";
TEMP &= 245;
if (TEMP == 0) {
return;
}
}
if (TEMP & 80) {
BOOL += "AC' + ";
TEMP &= 175;
if (TEMP == 0) {
return;
}
}
if (TEMP & 160) {
BOOL += "AC + ";
TEMP &= 95;
if (TEMP == 0) {
return;
}
}
if (TEMP & 17) {
BOOL += "B'C' + ";
TEMP &= 238;
if (TEMP == 0) {
return;
}
}
if (TEMP & 34) {
BOOL += "B'C + ";
TEMP &= 221;
if (TEMP == 0) {
return;
}
}
if (TEMP & 68) {
BOOL += "BC' + ";
TEMP &= 187;
if (TEMP == 0) {
return;
}
}
if (TEMP & 136) {
BOOL += "BC + ";
TEMP &= 119;
if (TEMP == 0) {
return;
}
}
if (TEMP & 1) {
BOOL += "A'B'C' + ";
TEMP &= 254;
if (TEMP == 0) {
return;
}
}
if (TEMP & 2) {
BOOL += "A'B'C + ";
TEMP &= 253;
if (TEMP == 0) {
return;
}
}
if (TEMP & 4) {
BOOL += "A'BC' + ";
TEMP &= 251;
if (TEMP == 0) {
return;
}
}
if (TEMP & 8) {
BOOL += "A'BC + ";
TEMP &= 247;
if (TEMP == 0) {
return;
}
}
if (TEMP & 16) {
BOOL += "AB'C' + ";
TEMP &= 239;
if (TEMP == 0) {
return;
}
}
if (TEMP & 32) {
BOOL += "AB'C + ";
TEMP &= 223;
if (TEMP == 0) {
return;
}
}
if (TEMP & 64) {
BOOL += "ABC' + ";
TEMP &= 191;
if (TEMP == 0) {
return;
}
}
if (TEMP & 128) {
BOOL += "ABC + ";
TEMP &= 127;
}
}
void DISP()
{
if (!t) {
BOOL[BOOL.length() - 2] = NULL;
}
if (BOOL != Old) {
Serial.println(BOOL);
Old = BOOL;
lcd.println(BOOL);
Serial.println(KMAP);
}
}
//void DISPT() {
//
// // Displays the truth table for the logic circuit.
// //glcd.drawchar(
// for (byte x = 0; x < 8; x++) {
// glcd.drawstring(x, 0, (char*)BL[x]);
// }
// /*glcd.drawstring(1, 0, "A'B'C");
// glcd.drawstring(2, 0, "A'BC'");
// glcd.drawstring(3, 0, "A'BC");
// glcd.drawstring(4, 0, "AB'C'");
// glcd.drawstring(5, 0, "AB'C");
// glcd.drawstring(6, 0, "ABC'");
// glcd.drawstring(7, 0, "ABC");*/
//
// byte y;
// for (y = 0; y < 8; y++) {
// glcd.drawchar(y, 8, bitRead(KMAP, y));
// }
// /*
//
// byte x;
// byte y;
// for (x = 0; x < 2; x++) {
// for (y = 0; y < 3; y++) {
// glcd.drawchar(y, x, KMAP[x][y]);
// }
// glcd.drawchar(y, x, KMAP[x][y]);
// }*/
//}
//
//void DISPB() {
// // Displays the boolean expression for the logic cicuit.
// int L = BOOL.length() - 2;
// int l;
// byte m;
// for (l = 0; l < L; l++) {
// glcd.drawchar(m, 0, BOOL[l]);
// m++;
// Serial.print(BOOL[l]);
// Serial.print(" ");
// }
//}
int freeRam() {
extern int __bss_end;
extern int *__brkval;
int free_memory;
if((int)__brkval == 0) {
free_memory = ((int)&free_memory) - ((int)&__bss_end);
}
else {
free_memory = ((int)&free_memory) - ((int)__brkval);
}
return free_memory;
}