3 Turns on an LED which represents head or tails. The LED
4 remains on for about 3 seconds and the cycle repeats.
6 Dr. Purdum, July 12, 2012
9 // define the pins to be used.
12 #define HEADIOPIN 13 // Which I/O pins are we using?
15 #define PAUSE 3000 // How long to delay?
20 long randomNumber = 0L;
22 // the setup routine runs once when you press reset:
24 // initialize each of the digital pins as an output.
25 pinMode(head, OUTPUT);
26 pinMode(tail, OUTPUT);
27 randomSeed(analogRead(0)); // This seeds the random number generator
30 // the loop routine runs over and over again forever:
33 randomNumber = generateRandomNumber();
34 digitalWrite(head, LOW); // Turn both LED's off
35 digitalWrite(tail, LOW);
36 delay(PAUSE - REST); // Let them see both are off for a time slice
37 if (randomNumber % 2 == 1) { // Treat odd numbers as a head
38 digitalWrite(head, HIGH);
40 digitalWrite(tail, HIGH); // Even numbers are a tail
42 delay(PAUSE); // Pause for 3 seconds
45 long generateRandomNumber()
47 return random(0, 1000000); // Generate random numbers between 0 and one million