1 // define the pins to be used.
4 #define TARGETVALUE 2500L
7 #define FOUNDITIOPIN 13
8 #define RECYCLEIOPIN 12
12 int foundIt = FOUNDITIOPIN;
13 int recycle = RECYCLEIOPIN;
14 long targetValue = TARGETVALUE;
16 int recycleCounter = 0;
19 // the setup routine runs once when you press reset:
21 // initialize each of the digital pins as an output.
23 pinMode(foundIt, OUTPUT);
24 pinMode(recycle, OUTPUT);
25 randomSeed(analogRead(0)); // This seeds the random number generator
29 // the loop routine runs over and over again forever:
32 while (counter != -1) { // Check for negative values
33 randomNumber = generateRandomNumber();
34 if (randomNumber == TARGETVALUE) {
35 Serial.print("Counter = ");
36 Serial.print(counter, DEC);
37 Serial.print(" recycleCounter = ");
38 Serial.println(recycleCounter, DEC);
39 digitalWrite(foundIt, HIGH);
41 digitalWrite(foundIt, LOW);
44 if (counter < 0) { // We've overflowed an int
47 Serial.print("recycleCounter = ");
48 Serial.println(recycleCounter, DEC);
49 digitalWrite(recycle, HIGH);
51 digitalWrite(recycle, LOW);
54 if (recycleCounter > MAXRECYCLES)
55 exit(0); // End program
59 long generateRandomNumber()
61 return random(MIN, MAX); // Generate random numbers between 0 and one million