Created
August 11, 2017 22:21
-
-
Save juusechec/58253ee7467bc6c0d77e18c1a84dd618 to your computer and use it in GitHub Desktop.
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
const int ledPin = 13; | |
const int botonPin = 7; | |
const int boton2Pin = 8; | |
int milisegundos = 500; | |
int val = 0; | |
long randNumber; | |
long randNumber2; | |
void setup() { | |
Serial.begin(9600); | |
randomSeed(analogRead(0)); | |
// put your setup code here, to run once: | |
pinMode(ledPin, OUTPUT); | |
pinMode(botonPin, INPUT); | |
pinMode(boton2Pin, INPUT); | |
randNumber = random(0, 11); // 0 a 10 | |
Serial.println("Tesoro:"); | |
Serial.println(randNumber); | |
randNumber2 = random(0, 11); // 0 a 10 | |
Serial.println("YO"); | |
Serial.println(randNumber2); | |
} | |
void loop() { | |
// put your main code here, to run repeatedly: | |
leerBoton(); | |
calcularTiempo(); | |
prenderApagar(); | |
} | |
void prenderApagar() { | |
digitalWrite(ledPin, HIGH); // turn the LED on (HIGH is the voltage level) | |
delay(milisegundos); // wait for a second | |
digitalWrite(ledPin, LOW); // turn the LED off by making the voltage LOW | |
delay(milisegundos); // wait for a second | |
} | |
void leerBoton() { | |
val = digitalRead(botonPin); // read the input pin | |
if (val == HIGH){ | |
randNumber2 = randNumber2 + 1; | |
} | |
val = digitalRead(boton2Pin); // read the input pin | |
if (val == HIGH){ | |
randNumber2 = randNumber2 - 1; | |
} | |
Serial.print("Cambie a:"); | |
Serial.println(randNumber2); | |
} | |
void calcularTiempo(){ | |
long dif = abs(randNumber - randNumber2); | |
if (dif > 7){ | |
milisegundos = 2000; | |
} else if (dif > 5){ | |
milisegundos = 1500; | |
} else if (dif > 3){ | |
milisegundos = 1000; | |
} else if (dif > 2){ | |
milisegundos = 500; | |
} else if (dif > 0){ | |
milisegundos = 200; | |
} else if (dif == 0){ | |
milisegundos = 50; | |
Serial.println("Encontre el tesoro."); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment