// Pins for the push buttons and LED
const int button1Pin = 6; // Connect button 1 to pin 2
const int button2Pin = 7; // Connect button 2 to pin 3
const int ledPin = 8; // Connect LED to pin 13
// Perceptron weights and bias
float weights[] = {0.5, 0.5}; // Adjust these weights accordingly
float bias = -1.0; // Adjust the bias accordingly
void setup() {
Serial.begin(9600);
pinMode(button1Pin, INPUT_PULLUP);
pinMode(button2Pin, INPUT_PULLUP);
pinMode(ledPin, OUTPUT);
}
void loop() {
// Read button states
int button1State = digitalRead(button1Pin);
int button2State = digitalRead(button2Pin);
// Calculate the perceptron output
float sum = button1State * weights[0] + button2State * weights[1] + bias;
int perceptronOutput = sum > 0 ? 1 : 0;
// Display perceptron output on the serial monitor
Serial.print("Button 1: ");
Serial.print(button1State);
Serial.print(", Button 2: ");
Serial.print(button2State);
Serial.print(" | Perceptron Output: ");
Serial.println(perceptronOutput);
// Turn on or off the LED based on the perceptron output
digitalWrite(ledPin,perceptronOutput);
delay(500); // Delay for better readability
}