Hello I am new to this forum, I am working on a project and just wanted to make sure I had the code right
can anyone tell me of any mistakes or if it is understandable or is there any way to simplify it
void setup() {
Serial.begin(9600);
pinMode(1, OUTPUT); // pre stage white
pinMode(2, OUTPUT); // stage white
pinMode(4, OUTPUT); // Yellow one
pinMode(6, OUTPUT); // Yellow two
pinMode(8, OUTPUT); // Yellow three
pinMode(10, OUTPUT); // Green
pinMode(11, OUTPUT); // Red
}
void loop() {
int analogValue1 = analogRead(A0);
int analogValue2 = analogRead(A1);
Serial.print("Analog reading = ");
Serial.print(analogValue); // the raw analog reading
if (analogValue1 < 10) { // if laser is interupted turn on white led
digitalWrite (1, High)
}
if (analogValue2 < 10) {
digitalWrite(2, HIGH); // stage White Led on for 2 second
delay(2000);
digitalWrite(2, LOW); // stage White LED turns off for 1/2 second
delay(500);
digitalWrite(1, LOW); // pre stage White LED turns off for 1/2 second
delay(500)
}
if (analogValue2 < 10) {
digitalWrite(4, HIGH); // Yellow led on 1/2 second
delay(500)
}
else {
digitalWrite(11, HIGH)
} //Red Led on
if (analogValue2 < 10) {
digitalWrite(4, LOW); // Yellow LED turns off for 1/2 second
delay(500)
}
else {
digitalWrite(11, HIGH)
} //Red Led on
if (analogValue2 < 10) {
digitalWrite(6, HIGH); // Yellow Led on for 1/2 second
delay(500)
}
else {
digitalWrite(11, HIGH)
} //Red Led on
if (analogValue2 < 10) {
digitalWrite(6, LOW); // LED turns off for 1/2 second
delay(500)
}
else {
digitalWrite(11, HIGH)
} //Red Led on
if (analogValue2 < 10) {
digitalWrite(8, HIGH); // Yellow Led on for 1/2 sec
delay(500)
}
else {
digitalWrite(11, HIGH)
} //Red Led on
if (analogValue2 < 10) {
digitalWrite(8, LOW); // Yellow LED turns off for 1/2 second
delay (500)
}
else {
digitalWrite(11, HIGH)
} //Red Led on
if (analogValue2 < 10) {
digitalWrite(10, HIGH); //Green led turns on
}
else {
digitalWrite(11, HIGH)
} //Red Led on
}
void setup()
{ Serial.begin(9600); analogRead(A0); // this is the start laser
analogRead(A3); // this is the stop laser
Serial.println("");
} //Here you can change the message your stopwatch will display before any buttons are pressed. Put the instructions here for people who have never used your stopwatch to instantly know what to do.
void displayResult()
{ float h, m, s, ms; unsigned long over; elapsed = finished - start; h = int(elapsed / 3600000); over = elapsed % 3600000; m = int(over / 60000); over = over % 60000; s = int(over / 1000); ms = over % 1000; Serial.print("Milliseconds so far: "); //The tekst that will be displayed before the amount of milliseconds passed.
Serial.println(elapsed); Serial.print("Elapsed time: "); //The text that will be displayed before the amout of time elapsed.
Serial.print(h, 0); Serial.print("h "); Serial.print(m, 0); Serial.print("m "); Serial.print(s, 0); Serial.print("s "); Serial.print(ms, 0); Serial.println("ms"); Serial.println();
}
void loop()
{ if (analogRead(A0) < 10) {
start = millis(); delay(200); // for debounce Serial.println("Ready, set, go!"); } //Here you establish what happens when the first button is pressed and the message that it will display to the user
if (analogRead(A3) > 10) {
finished = millis(); delay(200); // for debounce displayResult(); } } // here you establish what happens when the second button is pressed and the message that will be displayed.