Paso 2:
Este programa crea un gráfico de los números rodados en los dos dados. Copiar/pegar el código en el IDE de Arduino, subirlo a tu Arduino, abra al serial monitor y ajustar la velocidad de baudio a 115200.
Cada asterisco representa cinco rollos del número.
******************************************************************** * Filename: DiceGraph.ino * * This program creates a graph of the numbers rolled on two dice. * Copy/Paste the code into the Arduino IDE, upload it to your * Arduino, open the serial monitor and set the baud rate to 115200. * Each astrisk represents five rolls of the number. ******************************************************************** / Accumulators to count the number // of times each number occures. int accum[13]{0,0,0,0,0,0,0,0,0,0,0,0,0}; int firsttime=1; // Set first time flag. void setup() { Serial.begin(115200); } void loop() { if(firsttime==1) // If first time through loop. { Serial.println("Enter any character and press Enter to start:"); char choice = ' '; // Unused character. while(Serial.available() == 0); choice = Serial.read(); // Get character, just to start program. randomSeed(millis()); // Seed random number generator, firsttime=0; // and clear first time flag. } int d1=random(1,7); // Roll dice. int d2=random(1,7); int dice=d1+d2; accum[dice]++; // Increment the accumulator. for(int i=2;i<13;i++) { if(i<10) // Print the numbers. { Serial.print(" "); // Space to keep columns aligned. Serial.print(i); } else { Serial.print(i); } Serial.print(" - "); if(accum[i]>4) // Print one * for every 5 times munber occures. { for(int j=1; j<=accum[i]/5; j++) { Serial.print("*"); } Serial.println(""); } else Serial.println(""); } delay(100); Serial.println(""); Serial.println(""); Serial.println(""); Serial.println(""); }