programming for time trial

hello everyone :D

i need to record a time for an object to move from location A to Location B..
i got some hint that i have to use photosensor,controller and programming..

here is the problem...i have no idea about the programming...
anyone help can give me some guide?
1. You need to somehow integrate the photosensor so that you can access the value in your program. How you do this will depend on the sensor itself.

2. Your apparatus will dictate how easy this will be. I think it's easiest if you have a black object moving towards you with a white background. Point the photo-sensor towards the black object which is far away at location A. You'll get a number from the sensor. Let's say its 5236 for no real reason (it's an analogue value). Now move the object to location B which is very close. Lets say that the number now is -15467. The number has changed, because the black object has blocked a significant amount of light. You have also just calibrated your apparatus.

3. Write a little program:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <ctime>
#include <iostream>

short LightSensor; // Analogue value from light sensor, how you fill this value depends on your sensor.

int main()
{
    time_t start, end; // Create two times, the start and the end;

    while (LightSensor > 5236) { } // While the object is further than location A, do nothing
    
    time(&start); // Snap the time as it crosses location A
    
    while (LightSensor > -15467) { }// While the object is further than location B, do nothing
    
    time(&end); // capture the time as it crosses location B
    
    std::cout << "The amount of time it took to get from location A to location B was: "
              << difftime (end,start)
              << " seconds" << std::end;    
}
Last edited on
Topic archived. No new replies allowed.