Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void setup() {
- Serial.begin(9600);
- Serial.println("Hello, what is your name?");
- while (Serial.available() == 0) { // stops program from continuing until Serial.available is 0, or the user inputs something.
- //wait for user to input data
- }
- String usersName = Serial.readString();
- Serial.println("Nice to meet you, " + usersName);
- //ageFunFact(usersName);
- coinFlip(usersName);
- Serial.println("Thanks for playing!");
- }
- void loop() {
- }
- void coinFlip(String yourName){
- Serial.print("Lets play a game, " + yourName);
- Serial.println("I'm going to flip a coin. Input '1' for heads, or '0' for tails.");
- randomSeed(analogRead(0));
- int coinflip = random(2); // 0 for tails, 1 for heads.
- String result;
- if (coinflip == 0) {
- result = "Tails";
- }
- else {
- result = "Heads";
- }
- while (Serial.available() == 0) {
- //Serial.available is 0, or the user inputs something.
- //wait for user to input data
- //Serial.println("DEGBUG GOT HERE");
- }
- int guess = Serial.parseInt();
- if (guess == coinflip) {
- Serial.println("Nice Job! Your guess of " + result + " was correct!");
- }
- else {
- Serial.println("Darn! Your guess was incorrect. The correct answer was "+ result + ".");
- }
- }
- void ageFunFact(String yourName){
- Serial.print("Time for a fun fact, " + yourName);
- Serial.println("How old are you right now?");
- while (Serial.available() == 0) {
- // Serial.available is 0, or the user inputs something.
- // wait for user to input data
- }
- int usersAge = Serial.parseInt();
- int usersAgePlusTen = usersAge+10;
- Serial.println("Wow! Did you know that in 10 years, you will be exactly " + String(usersAgePlusTen) + " years old?");
- Serial.println("");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement