source: fact/FPG/FPG1/FPG1.pde@ 17536

Last change on this file since 17536 was 12574, checked in by neise, 13 years ago
comment
File size: 874 bytes
Line 
1int triggerPin = 2;
2double uRandom;
3long expect = 40000; // expectation value of randomnumbers --> trigger delay in microsecs
4long trigger_delay;
5
6void setup() {
7 pinMode(triggerPin, OUTPUT);
8 randomSeed(1234);
9}
10
11void loop() {
12
13 // comment out the following line
14 // to stop trigger production
15 digitalWrite(triggerPin, LOW);
16 digitalWrite(triggerPin, HIGH);
17
18
19 // the next two lines take around 250us....
20 uRandom = 2147483647. / random(2147483647L) ;
21 trigger_delay = (long)(expect * log(uRandom));
22
23 // ... here these 250us are substracted...
24 if (trigger_delay > 250)
25 trigger_delay -= 250;
26 else
27 trigger_delay = 1;
28
29
30 while (trigger_delay > 0){
31 if (trigger_delay > 16383) {
32 delayMicroseconds(16383);
33 trigger_delay -= 16383;
34 }
35 else
36 {
37 delayMicroseconds((unsigned int)trigger_delay);
38 trigger_delay = 0;
39 }
40 }
41}
Note: See TracBrowser for help on using the repository browser.