4 input using riasing age

 #include <Adafruit_SSD1306.h> // Include the OLED library

#define OLED_RESET 4 // Reset pin # (or -1 if sharing Arduino reset pin)

Adafruit_SSD1306 display(OLED_RESET); // Create an instance of the OLED display


const int inputPin1 = 2; // Input pin 1

const int inputPin2 = 3; // Input pin 2

const int inputPin3 = 4; // Input pin 3

const int inputPin4 = 5; // Input pin 4


volatile int count = 0; // Variable to hold the count value


void setup() {

  display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // Initialize the OLED display

  display.clearDisplay(); // Clear the display

  display.setTextSize(2); // Set the text size

  display.setTextColor(SSD1306_WHITE); // Set the text color

  display.setCursor(0, 0); // Set the cursor position


  // Set input pins as inputs

  pinMode(inputPin1, INPUT);

  pinMode(inputPin2, INPUT);

  pinMode(inputPin3, INPUT);

  pinMode(inputPin4, INPUT);


  // Enable interrupts on the input pins using rising edge trigger

  attachInterrupt(digitalPinToInterrupt(inputPin1), incrementCount, RISING);

  attachInterrupt(digitalPinToInterrupt(inputPin2), incrementCount, RISING);

  attachInterrupt(digitalPinToInterrupt(inputPin3), incrementCount, RISING);

  attachInterrupt(digitalPinToInterrupt(inputPin4), incrementCount, RISING);

}


void loop() {

  // Display the count on the OLED display

  display.clearDisplay();

  display.setCursor(0, 0);

  display.print("Count: ");

  display.println(count);

  display.display();


  // Add a delay to prevent flickering on the display

  delay(100);

}


void incrementCount() {

  count++; // Increment the count value

}


Comments

Popular Posts