1 /* Exercise 2, with a WHILE loop
2 Test a random number agains a value
4 Light the other LED if a run of 255 test has gone
5 Log the results (if success) trough serialport
10 const byte GREEN = 13 ; // LED for found value
11 const byte RED = 12 ; // LEAD for restart
13 const int TARGET = 200 ;
14 long randomNumber = 0L;
17 const int WAIT = 1000 ;
20 const byte MAXRUN = 10 ;
25 pinMode(GREEN,OUTPUT);
28 Serial.println("Initializing random sequence, please wait for results.");
31 randomSeed(analogRead(0)); // Random initializer
35 void loop() { // put your main code here, to run repeatedly:
36 digitalWrite(GREEN, LOW);
37 digitalWrite(RED, LOW);
38 // Serial.println(count);
40 for (count == 0; count < 255; count++ , delay(REST)) {
41 randomNumber = random(0,255); //Randoom value generated
42 if (randomNumber == TARGET) { // When we catch the value
43 Serial.print("--> Match found! Counter was at: "); // serial message
44 Serial.println(count);
45 digitalWrite(GREEN, HIGH);
47 digitalWrite(GREEN, LOW);
52 Serial.println("Counter resetted."); // serial staff
53 digitalWrite(RED, HIGH);
57 if (totalRun == MAXRUN) {
58 Serial.println("10 runs done, exit program.");
59 digitalWrite(RED, HIGH);