/* Logic Lab - see http://www.technoblogy.com/show?4FFY David Johnson-Davies - www.technoblogy.com - 18th May 2023 AVR128DA48 or ATmega4809 @ 4 MHz (internal oscillator; BOD disabled) CC BY 4.0 Licensed under a Creative Commons Attribution 4.0 International license: http://creativecommons.org/licenses/by/4.0/ */ // Gate definitions enum truthtable_t: uint8_t { AND = 0b1000, NAND = 0b0111, OR = 0b1110, NOR = 0b0001, XOR = 0b0110, NOT = 0b0011 }; typedef struct { int inputa; int inputb; int output; truthtable_t truthtable; } gate_t; gate_t gates[12] = { { PIN_PC1, PIN_PC0, PIN_PC5, AND }, { PIN_PB5, PIN_PB4, PIN_PC4, AND }, { PIN_PB1, PIN_PB0, PIN_PA3, NAND }, { PIN_PA6, PIN_PA7, PIN_PA2, NAND }, { PIN_PC7, PIN_PC6, PIN_PD2, OR }, { PIN_PC3, PIN_PC2, PIN_PD3, OR }, { PIN_PA5, PIN_PA4, PIN_PF2, NOR }, { PIN_PA1, PIN_PA0, PIN_PF3, NOR }, { PIN_PD4, PIN_PD5, PIN_PE0, XOR }, { PIN_PD6, PIN_PD7, PIN_PE1, XOR }, { PIN_PF0, PIN_PF0, PIN_PE2, NOT }, { PIN_PF1, PIN_PF1, PIN_PE3, NOT }, }; // Setup ********************************************** void setup () { // Set outputs for (int i=0; i<12; i++) { pinMode(gates[i].output, OUTPUT); } } void loop () { for (int i=0; i<12; i++) { gate_t gate = gates[i]; bool ina = digitalRead(gate.inputa); bool inb = digitalRead(gate.inputb); int val = ina << 1 | inb; bool out = (gate.truthtable >> val) & 1; digitalWrite(gate.output, out); } }