| Line | |
|---|
| 1 | int triggerPin = 2;
|
|---|
| 2 | double uRandom;
|
|---|
| 3 | long expect = 40000; // expectation value of randomnumbers --> trigger delay in microsecs
|
|---|
| 4 | long trigger_delay;
|
|---|
| 5 |
|
|---|
| 6 | void setup() {
|
|---|
| 7 | pinMode(triggerPin, OUTPUT);
|
|---|
| 8 | randomSeed(1234);
|
|---|
| 9 | }
|
|---|
| 10 |
|
|---|
| 11 | void 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.