I am having trouble figuring this stuff out. This is my first day using any type of microcontroller so I apologize if I do not understand something.
I am trying to make a counter using an asynchronous set up on J/K FFs to count down from 9 to 0. When the counter counts to 15, it is cleared on bit 2 and 3 and also preset on bit 1 and 4 to repeat the count 9 to 0 again.
So in the code, I was trying to use the nonPWM pins to "digitalRead" all 4 bits and when all 4 bits = HIGH, a pin on the Arduino would output a 1 or a HIGH to preset the count back to 9.
The code compiles but when I put the Arduino to use, it may not be reading the 4 bits or my code may not be what I am wanting it to do. I'm not sure on the statements I should be making for this such as "while" or "if, else". Any help on the code would be much appreciated.
const int clockpin = 3;
const int bit1pin = 2;
const int bit2pin = 4;
const int bit4pin = 7;
const int bit8pin= 8;
const int clearpin = 5;
int updateclrpin;
void setup()
{
pinMode(clockpin, OUTPUT);
pinMode(bit1pin, INPUT);
pinMode(bit2pin, INPUT);
pinMode(bit4pin, INPUT);
pinMode(bit8pin, INPUT);
pinMode(clearpin, OUTPUT);
}
void loop() //clock loop
{
do{
digitalWrite(clockpin, HIGH);
delay(500);
digitalWrite(clockpin, LOW);
delay(500);
}
while(clockpin == HIGH);{
digitalRead (bit1pin);
digitalRead(bit2pin);
digitalRead(bit4pin);
digitalRead(bit8pin);
if(bit1pin == HIGH && bit2pin == HIGH && bit4pin == HIGH && bit8pin == HIGH)
{
digitalWrite(clearpin, HIGH);
delay(1000);
}
else
{
digitalWrite(clearpin, LOW);
}
}
}