We used digital pin 7 (D7) to read the output of the AND gate/open-drain (OD). Please ensure that your OD gate output is connected to 5V through an external pull-up resistor, and that this pin is connected to the D7 pin of the Arduino UNO. In this way, when the OD gate outputs a low level, the D7 pin of the Arduino UNO will read a low level (0), and when the OD gate outputs a high level, the internal pull-up resistor will pull the D7 pin high to a high level (1).
Description
#include <LiquidCrystal.h>
// Initialize the LCD library, setting the Arduino pins connected to the LCD
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
// Define the pin connections for the buttons
const int sw1 = 8; // The first button is connected to D2
const int sw2 = 9; // The second button is connected to D3
// Define the pin connection for the LED
const int ledPin = 0; // The LED is connected to D13
// Define the pin connection for the AND gate/open-drain output
const int andODOutputPin = 7; // Assuming the AND gate/open-drain output is connected to D7
void setup() {
pinMode(sw1, INPUT_PULLUP);
pinMode(sw2, INPUT_PULLUP);
pinMode(ledPin, OUTPUT);
pinMode(andODOutputPin, INPUT); // Set as input mode
lcd.begin(16, 2); // Initialize the LCD for 16 columns and 2 rows
lcd.clear(); // Clear the screen
}
void loop() {
int input1 = digitalRead(sw1);
int input2 = digitalRead(sw2);
int andODResult = digitalRead(andODOutputPin); // Read the output of the AND gate/open-drain
int xorResult = input1 ^ input2; // Calculate the XOR result
digitalWrite(ledPin, xorResult); // Control the LED
// Display the results
lcd.clear(); // Clear the screen at the start of each loop
lcd.print("SW1: ");
lcd.print(input1);
lcd.print(" SW2: ");
lcd.print(input2);
lcd.setCursor(0, 1); // Set the cursor position to the second line
lcd.print("OD: ");
lcd.print(andODResult);
lcd.print(" XOR: ");
lcd.print(xorResult);
delay(500); // Wait for 500ms before measuring again
}
Comments
Please log in or sign up to comment.