// Program done on 02/02/2024 AMALJITH A
// Implementing JK flip-flop with inputs as J AND K, outputs as Q and Q_Not;
const int switchJ = 2; // Connect J switch to digital pin 2
const int switchK = 3; // Connect K switch to digital pin 3
const int ledQ = 4; // Connect Q LED to digital pin 4
const int ledNotQ = 5; // Connect Q' LED to digital pin 5
// Variables to store current (Q) and next state(QNext) of the flip-flop
bool Q = 0;
bool QNext = 0;
bool J ,K; //variable to store J and K states
void setup() {
// Set slide switch pins as inputs
pinMode(switchJ, INPUT);
pinMode(switchK, INPUT);
// Set LED pins as outputs
pinMode(ledQ, OUTPUT);
pinMode(ledNotQ, OUTPUT);
// Initialize LEDs
digitalWrite(ledQ, Q);
digitalWrite(ledNotQ, !Q);
}
void loop() {
// Read the state of the J and K switches
J = digitalRead(switchJ);
K = digitalRead(switchK);
// Implement JK flip-flop characteristic equation
QNext = (J * !Q) + (!K * Q);
// Update the LEDs based on the flip-flop state
digitalWrite(ledQ, QNext);
digitalWrite(ledNotQ, !QNext);
// Update current state for the next iteration
Q = QNext;
delay(300);
}