Help and advice for finish line sketch

hi everyone!

i’ve tried Ted Meyer’s Finish line code ,the code is work as finish line detector for hot wheels size car with two lane,if first car pass the finish line,the led turns on, and the other will not turn on when the car is passes,and it’s work like a charm, and now i wanna try to modified the code and want to know how the code is works, i have two question

  1. why the arduino not run the command on the “digitalWrite(ledPin2, status2);” if the “digitalWrite(ledPin1, status1);” is running first? ,and it happen in reverse too,that’s all work just like what i want,but i just want to know why.

  2. i try to change the led winner indicator to blink 3 times instead just 1 blink for 3 second,i try to figure it out with “if” function but how can i write 2 statements in 1 if function?,and how to “translate” my first question above to run properly, so far i just get the error message said " cant convert from void to boolean"

i have so many idea like adding timer using max7219 7 digit 8 segment led display and any other features, but lack of programming experience so i just start from the easy first,

any advice and help would be highly appreciated!
im sorry for my english and knowledge about arduino and programming

many thanks!

sketch_jul03b.ino (1.49 KB)

I cannot view the attachment on my mobile device. Someone with two posts should know to use the autoformat function (CTRL-T on a PC) of the Arduino IDE, and then copy and paste between code tags.

Starting small and making small changes is part of the way to learn programming.

Hotwheelsarena:
i’ve tried Ted Meyer’s Finish line code

A good starting point would be an explanation of whatever that is.

…R

vaj4088:
I cannot view the attachment on my mobile device. Someone with two posts should know to use the autoformat function (CTRL-T on a PC) of the Arduino IDE, and then copy and paste between code tags.

Starting small and making small changes is part of the way to learn programming.

okay here it is the code sorry

/*
  Finish Line Detector

  Lights up LED 1 or 2 or 3 or 4 depending on which sensor is tripped first

  Accuracy:
  As there are only a few lines of code in the loop
  (actually more instructions after it gets compiled) and considering
  that the arduino runs at 16Mhz (million cycles per second),
  we have an accuracy much better than a millisecond.
  With an oscilloscope, I determined that the code actually takes about
  20 microseconds to execute. Should be good enough.

*/

const int ledPin1 = 13;
const int ledPin2 = 12;
const int sensorPin1 = 2;
const int sensorPin2 = 3;
const int irledtx = 4;
const int irledtx2 = 5;
const int powerled = 6;
const int TIMEOUT = 2000; // milliseconds

// Setup runs once, at start
// Input and Output pins are set
void setup() {
  pinMode(sensorPin1, INPUT);
  pinMode(sensorPin2, INPUT);
  pinMode(ledPin1, OUTPUT);
  pinMode(ledPin2, OUTPUT);
  pinMode(irledtx, INPUT);
  pinMode(irledtx2, INPUT);
  pinMode(powerled, INPUT);
}

// Called repeatedly
void loop() {
  // turn on power led indicator and ir led tx
  int irledtx = HIGH;
  int irledtx2 = HIGH;
  int powerled = HIGH;
  // Get the Sensor status
  int status1 = digitalRead(sensorPin1);
  int status2 = digitalRead(sensorPin2);

  // Set the output LED to match the sensor
  digitalWrite(ledPin1, status1);
  digitalWrite(ledPin2, status2);

  if (status1 == HIGH || status2 == HIGH) {
    // A sensor was tripped, show the results until timeout
    delay(TIMEOUT); // Wait for timeout
  }

}

Robin2:
A good starting point would be an explanation of whatever that is.

...R

hi may i get any advice to learn programming in arduino?,any website or anything that i can learn from,thanks for replying!

Hotwheelsarena:
hi may i get any advice to learn programming in arduino?,any website or anything that i can learn from,thanks for replying!

I was hoping you would explain what you meant by "Ted Meyer's Finish line code"

As far as learning to program an Arduino is concerned, a lot depends on how you prefer to learn things. For example there are lots of simple example programs with the Arduino IDE if you like to learn by doing. But if you prefer a class-room style of learning then you should be able to find a suitable online tutorial. I'm afraid I can't suggest any particular one as I have never used them myself.

...R

may i get any advice to learn programming in arduino?

One of the first things that you need to know is that there is no such thing as programming in Arduino. You program an Arduino using C and C++. Learn C and C++and you will be better prepared to program an Arduino.

Robin2:
I was hoping you would explain what you meant by "Ted Meyer's Finish line code"

As far as learning to program an Arduino is concerned, a lot depends on how you prefer to learn things. For example there are lots of simple example programs with the Arduino IDE if you like to learn by doing. But if you prefer a class-room style of learning then you should be able to find a suitable online tutorial. I'm afraid I can't suggest any particular one as I have never used them myself.

...R

I already updated my first post how the thing is work,okay i will try to learn from the examples,i'm a tinker but sometimes the program gonna be little bit tricky to get a simple and "good looking"

Hotwheelsarena:
I already updated my first post how the thing is work

For the future please put new information in a new Reply. People rarely go back to re-read an earlier Post. Also changes to earlier Posts make nonsense of the subsequent comments when somebody new comes to read the Thread.

...R

Robin2:
For the future please put new information in a new Reply. People rarely go back to re-read an earlier Post. Also changes to earlier Posts make nonsense of the subsequent comments when somebody new comes to read the Thread.

...R

okay im sorry,im newbie on forum like this,thanks for your advice!