HOME PROJECTS YOUTUBE FEEDBACK
HAPPY DONUT GAME

HAPPY DONUT GAME

This project was me experimenting with a remote from an old TV set and an infrared sensor that I doctored out of a broken DVD player. It is not a very complicated game, and if you plan on using this code, you will need to change it for your remote. The reason for that is remotes have their own seperate codes, so that they only can be interpreted by the device that they are for. For the remote that I am using, the on button is FF629D, but for the TV set at home, it is FC295G. So my remote will be most likely different to yours at home, so you will need to change the program. You will need to upload to find the codes of your remote. Always remember to put a “0x” in front of your hexadecimal code in the program.
Another thing that you will have to do if you have a uno, or some other boards is edit the irremote.h library, or otherwise it produces and error that says:

tone.cpp.o (symbol from plugin): In function `timer0_pin_port':
(.text+0x0): multiple definition of `__vector_7'
/tmp/167378485/build/libraries/irremote_2_2_3/IRremote.cpp.o (symbol from plugin):(.text+0x0):
first defined here
collect2: error: ld returned 1 exit status
exit status 1

because of the irremote library. To fix that you will need to uncomment a line in the library that says "uncomment if using uno, ..."
The settings menu is currently under development, but the difficulty part of it works.

#include <IRremote.h> const int RECV_PIN = 7; IRrecv irrecv(RECV_PIN); decode_results results; void setup(){ Serial.begin(9600); irrecv.enableIRIn(); irrecv.blink13(true); } void loop(){ if (irrecv.decode(&results)){ Serial.println(results.value, HEX); irrecv.resume(); } }

/* Happy Donut Game v1.3.0 (latest stable version) * Created by Nathan Carter * Hardware: * - lcd 16x2 shield * - ir reviever * - arduino uno * - Olin PD-7700 remote * * wiring for pins: * - IR in goes to D12 * - GND to Ir * - 5v to Ir reciever * - RST - A0 to LCD * - D3 - D9 to LCD * * Happy Donut Game * Copyright 2019 Plefunga Programming */ #include <IRremote.h> #include <LiquidCrystal.h> const int RECV_PIN = 12; LiquidCrystal lcd(8, 9, 4, 5, 6, 7); IRrecv irrecv(RECV_PIN); decode_results results; unsigned long key_value = 0; int sec = 0; int BLpin = 3; #define BLOFF() digitalWrite(BLpin, LOW); #define BLON() digitalWrite(BLpin, HIGH); float number = 0; int loopno = 0; int screens = 0; /* * Screens variable: * 0 = logo screen * 1 = press play to start * 2 = game * 3 = paused * 4 = settings * 5 = you lose * 6 = you win */ int difficulty = 0; byte plefunga_left[8] = { B00111, B01011, B01010, B00111, B00010, B01010, B00110, B00011, }; byte plefunga_right[8] = { B11000, B10100, B01010, B10010, B00010, B00010, B00100, B11000, }; byte happy[8] = { B00000, B00000, B01010, B00000, B10001, B01110, B00000, B00000, }; byte happyUp[8] = { B00000, B01010, B00000, B10001, B01110, B00000, B00000, B00000, }; byte donut[8] = { B00000, B00000, B01110, B11111, B11011, B11111, B01110, B00000, }; byte donutUp[8] = { B00000, B01110, B11111, B11011, B11111, B01110, B00000, B00000, }; byte sad[8] = { B00000, B00000, B01010, B00000, B01110, B10001, B00000, B00000, }; int col = 0; int row = 0; int x = 0; bool goneAbove3 = false; int winScore = 20; String WinScore = "20"; int loseScore = 0; int donutcol = random(0, 14); int donutrow = 0; int score = 0; int level = 1000; int piezo = 13; bool sound = true; void setup(){ pinMode(piezo, OUTPUT); Serial.begin(9600); irrecv.enableIRIn(); lcd.begin(16, 2); pinMode(BLpin, OUTPUT); BLOFF(); lcd.noDisplay(); lcd.createChar(0, happy); lcd.createChar(1, happyUp); lcd.createChar(2, donut); lcd.createChar(3, donutUp); lcd.createChar(4, sad); lcd.createChar(5, plefunga_left); lcd.createChar(6, plefunga_right); lcd.setCursor(col, row); lcd.write(byte(0)); lcd.setCursor(donutcol, donutrow); lcd.write(byte(2)); lcd.setCursor(col, row); } int a = random(0, 3); int b = random(0, 2); void loop(){ if (col >= 14) { row = 0; } if (donutcol >= 14){ donutrow = 0; } if (score >= 3){ goneAbove3 = true; } switch(screens){ case 0: lcd.setCursor(0, 0); lcd.print(" PLEFUNGA "); lcd.setCursor(7, 1); lcd.write(byte(5)); lcd.setCursor(8, 1); lcd.write(byte(6)); break; case 1: lcd.setCursor(0, 0); lcd.print("Happy Donut Game"); lcd.setCursor(0, 1); lcd.print(" PRESS PLAY "); break; case 2: break; case 3: lcd.setCursor(0, 0); lcd.print("Happy Donut Game"); lcd.setCursor(0, 1); lcd.print(" PAUSED "); break; case 4: lcd.setCursor(0, 0); lcd.print(" DIFFICULTY "); lcd.setCursor(0, 1); if(difficulty == 0) { lcd.print("As Easy As Pie"); } if(difficulty == 2){ lcd.print("A Piece of Cake"); } if(difficulty == 4){ lcd.print("DONUT OVERLOAD"); } if(difficulty == 8){ lcd.print("DONUT HYPERDRIVE"); } break; case 5: lcd.setCursor(4, 0); lcd.print("YOU LOSE"); lcd.setCursor(6, 1); lcd.write(byte(4)); lcd.setCursor(9, 1); lcd.write(byte(2)); break; case 6: lcd.clear(); lcd.setCursor(3, 0); lcd.print("YOU'VE WON"); lcd.setCursor(14, 1); lcd.print(winScore); lcd.setCursor(9, 1); lcd.write(byte(2)); lcd.setCursor(6, 1); lcd.write(byte(0)); lcd.setCursor(3, 0); lcd.print("YOU'VE WON"); lcd.setCursor(14, 1); lcd.print(winScore); delay(250); lcd.clear(); lcd.setCursor(3, 0); lcd.print("YOU'VE WON"); lcd.setCursor(14, 1); lcd.print(winScore); lcd.setCursor(9, 1); lcd.write(byte(3)); lcd.setCursor(6, 1); lcd.write(byte(1)); delay(250); lcd.clear(); break; } a = random(0, 3); b = random(0, 2); if ((score < loseScore) or (results.value == 0xFF4AB5)) { if( x == 0){ lcd.clear(); } screens = 5; x++; } if ((score >= winScore) or (results.value == 0xFFCA35)) { lcd.clear(); screens = 6; } if (irrecv.decode(&results)){ if ((results.value == 0xFFFFFFFF) and (key_value != 0xFFD827)) results.value = key_value; lcd.setCursor(col, row); lcd.clear(); switch(results.value){ case 0xFF629D: // ON/OFF x = 0; if (digitalRead(BLpin) == HIGH){ lcd.clear(); screens = 0; lcd.setCursor(0, 0); lcd.print(" PLEFUNGA "); lcd.setCursor(7, 1); lcd.write(byte(5)); lcd.setCursor(8, 1); lcd.write(byte(6)); tone(piezo, 440, 150); delay(150); tone(piezo, 330, 150); delay(150); tone(piezo, 277, 150); delay(150); tone(piezo, 330, 150); delay(150); tone(piezo, 220, 150); delay(150); sound = false; BLOFF(); score = 0; lcd.noDisplay(); x = 0; level = 1000; loopno = 0; goneAbove3 = false; difficulty = 0; } else{ BLON(); lcd.display(); lcd.clear(); screens = 0; sound = true; lcd.setCursor(0, 0); lcd.print(" PLEFUNGA "); lcd.setCursor(7, 1); lcd.write(byte(5)); lcd.setCursor(8, 1); lcd.write(byte(6)); tone(piezo, 440, 150); delay(150); tone(piezo, 330, 150); delay(150); tone(piezo, 277, 150); delay(150); tone(piezo, 330, 150); delay(150); tone(piezo, 440, 150); delay(1000); lcd.clear(); screens = 1; } break ; case 0xFFB04F: // >|| if (sound == true){ tone(piezo, 277, 150); delay(150); tone(piezo, 330, 150); delay(150); tone(piezo, 440, 150); } delay(150); x = 0; lcd.clear(); if((screens == 3) or(screens == 1)){ screens = 2; lcd.setCursor(col, row); lcd.write(byte(0)); lcd.setCursor(donutcol, donutrow); lcd.write(byte(2)); if(loopno = 0){ score = 0; } lcd.setCursor( 14, 1 ); if( score <= 9 ) lcd.print( " " ); lcd.print( score, DEC ); lcd.setCursor(col, row); } else{ screens = 3; } break ; case 0xFFB847: //UP if (screens == 2){ x = 0; row = 0; lcd.clear(); lcd.setCursor(col, row); lcd.write(byte(0)); lcd.setCursor(donutcol, donutrow); lcd.write(byte(2)); lcd.setCursor( 14, 1 ); if( score <= 9 ) lcd.print( " " ); lcd.print( score, DEC ); lcd.setCursor(col, row); if (sound == true){ tone(piezo, 440, 75); } delay(75); } break ; case 0xFF9867: //LEFT if (screens == 2){ if (col > 0){ col = col - 1; } lcd.setCursor(col, row); lcd.write(byte(0)); lcd.setCursor(donutcol, donutrow); lcd.write(byte(2)); lcd.setCursor( 14, 1 ); if( score <= 9 ) lcd.print( " " ); lcd.print( score, DEC ); lcd.setCursor(col, row); if (sound == true){ tone(piezo, 440, 75); } delay(75); } break ; case 0xFFD827: //ENTER if (screens == 2){ x = 0; lcd.setCursor(col, row); delay(100); lcd.clear(); lcd.setCursor(col, row); lcd.write(byte(1)); delay(250); lcd.clear(); lcd.setCursor(col, row); lcd.write(byte(0)); delay(250); lcd.clear(); lcd.setCursor(col, row); lcd.write(byte(1)); delay(250); lcd.clear(); lcd.setCursor(col, row); lcd.write(byte(0)); if (col == donutcol){ donutcol = random(0, 14); donutrow = random(0, 2); lcd.setCursor(donutcol, donutrow); lcd.write(byte(2)); score = score + 1; score = ( (score) % 100 ); lcd.setCursor( 14, 1 ); if( score <= 9 ) lcd.print( " " ); lcd.print( score, DEC ); lcd.setCursor(col, row); if (sound == true){ tone(piezo, 277, 150); delay(150); tone(piezo, 330, 150); delay(150); tone(piezo, 440, 150); } delay(150); } else { lcd.setCursor(donutcol, donutrow); lcd.write(byte(2)); lcd.setCursor( 14, 1 ); if (goneAbove3 == true){ score = score - 1; } if( score <= 9 ) lcd.print( " " ); lcd.print( score, DEC ); lcd.setCursor(col, row); if (sound == true){ tone(piezo, 262, 80); delay(100); tone(piezo, 262, 150); } delay(150); } lcd.setCursor(col, row); x = 0; } break ; case 0xFF8877: //RIGHT if (screens == 2) { if (col < 15){ col = col + 1; } lcd.setCursor(col, row); lcd.write(byte(0)); lcd.setCursor(donutcol, donutrow); lcd.write(byte(2)); lcd.setCursor( 14, 1 ); if( score <= 9 ) lcd.print( " " ); lcd.print( score, DEC ); lcd.setCursor(col, row); if (sound == true){ tone(piezo, 440, 75); } delay(75); x = 0; } break ; case 0xFF48B7: //DOWN if (screens == 2) { lcd.clear(); row = 1; lcd.setCursor(col, row); lcd.write(byte(0)); lcd.setCursor(donutcol, donutrow); lcd.write(byte(2)); lcd.setCursor( 14, 1 ); if( score <= 9) lcd.print( " " ); lcd.print( score, DEC ); lcd.setCursor(col, row); if (sound == true){ tone(piezo, 440, 75); } delay(75); } break ; case 0xFF609F: //5 if(screens == 2){ x = 0; score = score + 5; lcd.setCursor(col, row); lcd.write(byte(0)); lcd.setCursor(donutcol, donutrow); lcd.write(byte(2)); lcd.setCursor( 14, 1 ); if( score <= 9 ) lcd.print( " " ); lcd.print( score, DEC ); lcd.setCursor(col, row); delay(50); } break ; case 0xFFE817: //mute sound = !sound; if (sound == true){ tone(piezo, 440, 75); } if (sound == false){ tone(piezo, 262, 75); } delay(100); break; //settings case 0xFF906F: //menu if(screens == 4){ screens = 2; } else{ screens = 4; } if (sound == true){ tone(piezo, 440, 75); } delay(75); break; case 0xFF0AF5: //1 if(screens == 4){ difficulty = 0; } break ; case 0xFFAA55: //2 if(screens == 4){ difficulty = 2; } break ; case 0xFF12ED: //3 if(screens == 4){ difficulty = 4; } break ; case 0xFF7A85: //4 if(screens == 4){ difficulty = 8; } break ; case 0xFF02FD: //9 lcd.clear(); screens = 0; break ; //settings } key_value = results.value; irrecv.resume(); } number = score; //Serial.println(sec); if(score > 4){ number = 1 - number/(winScore*2); level = (1000-difficulty*100)*number; //Serial.println(level); } sec = ( millis() % level ); if((score >= loseScore) and (score < winScore)){ if((sec == 0) and (screens == 2)){ if((a == 1) and (donutcol <= 14)){ donutcol++; } if((a == 0) and (donutcol >= 1)) { donutcol--; } if(a == 2){ donutrow = b; } lcd.clear(); lcd.setCursor(col, row); lcd.write(byte(0)); lcd.setCursor(donutcol, donutrow); lcd.write(byte(2)); lcd.setCursor( 14, 1 ); if( score <= 9 ) lcd.print( " " ); lcd.print( score, DEC ); lcd.setCursor(col, row); } } loopno = 1; }

FEEDBACK
Free Web Hosting