-
-
Save MiguelAzores/3e9dc796e4960ef97ed9 to your computer and use it in GitHub Desktop.
Tarea: Generar numeros random
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// declaramos las variables... | |
int A = 0; | |
int B = 0; | |
int C = 0; | |
void setup() { | |
Serial.begin(9600); // inicializamos el Serial | |
// imprimimos los valores iniciales de A y B (0) | |
Serial.print("A = "); | |
Serial.print(A); | |
Serial.print(" B = "); | |
Serial.println(B); | |
delay (200); | |
Serial.println (" ***"); | |
delay (200); | |
randomSeed(analogRead(A0)); // elegimos una cadena de numeros aleatoria | |
} | |
void loop() { | |
// declaramos un valor aleatorio a cada variable | |
A = random(0,50); | |
B = random(0,50); | |
// imprimimos el valor de cada variable | |
Serial.print("A = "); | |
Serial.print(A); | |
Serial.print(" B = "); | |
Serial.println(B); | |
delay (200); | |
// invertimos los valores de A y B | |
C = A; | |
A = B; | |
B = C; | |
// imprimimos en el serial los nuevos valores de A y B | |
Serial.print("A = "); | |
Serial.print(A); | |
Serial.print(" B = "); | |
Serial.println(B); | |
delay (2000); | |
Serial.println(" *** "); | |
delay (2000); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment