hi all only got into arduino about a week ago and have already got a fair bit done just stuck on a pice of code at the min for the dna check im trying to pause the code while blue led is lit until red led is lit then continue the code iv tried to use the while code but just locks everything up including the button to unlock as it was
any help and advice would be much appreciated
thanks in advance
int buttonState = 0; // variable for reading the pushbutton status
int button2State = 0;
int button3State = 0;
int count = 0; // Count the button presses
int buttonPressCount = 0;
int button2PressCount = 0;
int button3PushCounter = 0;
int lastButton3State = 0; // previous state of the button
int numberOfLED = 8;
const int buttonPin = 2; // the number of the pushbutton pin
const int button2Pin = 9; // reload button
const int button3Pin = 10; // dna check
const int ledPin1 = 3; // the number of the LED pin
const int ledPin2 = 4; // the number of the LED pin
const int ledPin3 = 5; // the number of the LED pin
const int ledPin4 = 6; // the number of the LED pin
const int ledPin5 = 7; // the number of the LED pin
const int ledPin6 = 8; // the number of the LED pin
const int ledPin7 = 11; // blue led dna check
const int ledPin8 = 12; // red led dna check
// variables will change:
void setup() {
// initialize the LED pin as an output:
pinMode(ledPin1, OUTPUT);
pinMode(ledPin2, OUTPUT);
pinMode(ledPin3, OUTPUT);
pinMode(ledPin4, OUTPUT);
pinMode(ledPin5, OUTPUT);
pinMode(ledPin6, OUTPUT);
pinMode(ledPin7, OUTPUT);
pinMode(ledPin8, OUTPUT);
// initialize the pushbutton pins as an input:
pinMode(buttonPin, INPUT);
pinMode(button2Pin, INPUT);
pinMode(button3Pin, INPUT);
Serial.begin(9600);
}
void loop() {
// read the pushbutton input pin:
button3State = digitalRead(button3Pin);
// compare the buttonState to its previous state
if (button3State != lastButton3State) {
// if the state has changed, increment the counter
if (button3State == HIGH) {
// if the current state is HIGH then the button
// went from off to on:
button3PushCounter++;
Serial.println("on");
Serial.print("number of button pushes: ");
Serial.println(button3PushCounter);
} else {
// if the current state is LOW then the button
// went from on to off:
Serial.println("off");
}
// Delay a little bit to avoid bouncing
delay(50);
}
// save the current state as the last state,
//for next time through the loop
lastButton3State = button3State;
if (button3PushCounter % 2 == 0) {
digitalWrite(11, HIGH);
digitalWrite(12, LOW);
} else {
digitalWrite(12, HIGH);
digitalWrite(11, LOW);
}
if (count <= 0)
{
digitalWrite(7, HIGH);
delay(80);
digitalWrite(6, HIGH);
delay(80);
digitalWrite(5, HIGH);
delay(80);
digitalWrite(4, HIGH);
delay(80);
digitalWrite(3, HIGH);
}
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);
{
Serial.println(buttonState);
delay(1); // delay in between reads for stability
}
button2State = digitalRead(button2Pin);
if (button2State == HIGH)
(count = 0)
// check if the pushbutton is pressed.
// if it is, the buttonState is HIGH:
; if (buttonState == HIGH)
if (count <= 40)
{
digitalWrite(8, HIGH);
delay(20);
digitalWrite(8, LOW);
count ++;
// add 1 to the count
if (count >= 8)
// turn LED off
digitalWrite(ledPin1, LOW);
}
{
if (count >= 16)
// turn LED off
digitalWrite(ledPin2, LOW);
}
{
if (count >= 24)
// turn LED off
digitalWrite(ledPin3, LOW);
}
{
if (count >= 32)
// turn LED off
digitalWrite(ledPin4, LOW);
}
{
if (count >= 40)
// turn LED off
digitalWrite(ledPin5, LOW);
}
// turn LED off
buttonPressCount++;
delay(100);
}
lawgiver_light_rail_with_reload.ino (3.52 KB)