// program done on 31/01/2024 by AMALJITH A
// implement a D flip flop with input D (slide switch) and outputs as Q and Q_Not
const int D_pin = 2; // D input connected to digital pin 2 (slide switch)
const int Q_ledpin = 4; // Q output connected to LED, digital pin 4
const int Q_Notledpin = 5; // ~Q output connected to LED, digital pin 5
bool D = 0; // Initial value for D
bool QNext = 0; // setting ~Qnext state is initially low
void setup() { // assigning the inputs and outputs to the selected pins
pinMode(D_pin, INPUT);
pinMode(Q_ledpin, OUTPUT);
pinMode(Q_Notledpin, OUTPUT);
}
void loop() {
//read input of switch state
D = digitalRead(D_pin);
// Output conditions based on D flipflop characteristic equation Qn+1 =D
QNext = D;
// Update output LEDs
digitalWrite(Q_ledpin, QNext);
digitalWrite(Q_Notledpin, !QNext);
delay(100);
}