3 Turns on an LED which represents head or tails. The LED
4 remains on for about 3 seconds and the cycle repeats.
5 Dr. Purdum, July 12, 2012
8 // define the pins to be used.
9 #define SENDMESSAGEAFTERTHISMANYTOSSES 100
10 #define TESTSTORUN 50000
16 long randomNumber = 0L;
20 // the setup routine runs once when you press reset:
22 // initialize each of the digital pins as an output.
24 pinMode(head, OUTPUT);
25 pinMode(tail, OUTPUT);
26 randomSeed(analogRead(0)); // This seeds the random number generator
29 // the loop routine runs over and over again forever:
31 randomNumber = generateRandomNumber();
32 digitalWrite(head, LOW); // Turn both LEDs off
33 digitalWrite(tail, LOW);
35 if (randomNumber % 2 == 1) { // Treat odd numbers as a head
36 digitalWrite(head, HIGH);
39 digitalWrite(tail, HIGH); // Even numbers are a tail
43 if ( (headCount + tailCount) % SENDMESSAGEAFTERTHISMANYTOSSES == 0) {
44 Serial.print("Heads = ");
45 Serial.print(headCount);
46 Serial.print(" tails = ");
47 Serial.println(tailCount);
49 if (headCount + tailCount > TESTSTORUN) {
55 long generateRandomNumber()
57 return random(0, 1000000); // Generate random numbers between 0 and one million