Industriële fabricage
Industrieel internet der dingen | Industriële materialen | Onderhoud en reparatie van apparatuur | Industriële programmering |
home  MfgRobots >> Industriële fabricage >  >> Manufacturing Technology >> Productieproces

Arduino LCD-videogame

Componenten en benodigdheden

Broodplank (algemeen)
× 1
Jumperdraden (algemeen)
× 1
Arduino UNO
× 1
USB-A naar B-kabel
× 1
Draaipotentiometer (algemeen)
× 1
Analoge joystick (algemeen)
× 1
Zoemer
× 1
Adafruit Standaard LCD - 16x2 Wit op Blauw
× 1

Apps en online services

Arduino IDE

Over dit project

Dit is een project dat is gebaseerd op een videogame die ik op internet heb gevonden. Dit project heeft veel functies, zoals een zoemer die piept wanneer je personage botst of over obstakels springt. Om het een videogamegevoel te geven, heeft het ook een joystick (moet een knop hebben) omdat je gewoon op de joystickknop drukt om te springen. Deze videogame gaat over je raadt het al! (Een man die over obstakels rent en springt en ze ontwijkt.) Het doel van dit spel is om zoveel mogelijk punten te behalen (één punt voor elke seconde dat je op de baan bent en de obstakels ontwijkt).

Code

  • De code
De codeArduino
#include #define PIN_BUTTON 2#define PIN_AUTOPLAY 1#define PIN_BUZZER 8#define PIN_READWRITE 10#define PIN_CONTRAST 12#define SPRITE_RUN1 1#define SPRITE_RUN2 2#define SPRITE_JUMP_JUMP 3#define SPRITE_JUMP_3#define // Gebruik de '.' karakter voor het hoofd#define SPRITE_JUMP_LOWER 4#define SPRITE_TERRAIN_EMPTY ' ' // Gebruiker het ' ' character#define SPRITE_TERRAIN_SOLID 5#define SPRITE_TERRAIN_SOLID_RIGHT 6#define SPRITE_TERRAIN_SOLID_LEFT 7#define HERO_HORIZONTAL_POSITION op scherm TERRAIN_EMPTY 0#define TERRAIN_LOWER_BLOCK 1#define TERRAIN_UPPER_BLOCK 2#define HERO_POSITION_OFF 0 // Held is onzichtbaar#define HERO_POSITION_RUN_LOWER_1 1 // Held loopt op de onderste rij (pose 1)#define HERO_POSITION_RUN_JUERO_2. / Een sprong starten#define HERO_POSITION_JUMP_2 4 // Halverwege omhoog#define HERO_POSITION_JUMP_3 5 // Sprong bevindt zich op de bovenste rij#define HERO_POSITION_JUMP_4 6 // Sprong bevindt zich op de bovenste rij#define HERO_POSITION_JUMP_5 7 // Sprong bevindt zich op de bovenste rij#define_ HERO_POSITION_ HERO_JUMP_4 8 // Sprong is op de bovenste rij#define HERO_POSITION_JUMP_7 9 // Halverwege#define HERO_POSITION_JUMP_8 10 // Gaat bijna landen#define HERO_POSITION_RUN_UPPER_1 11 // Hero draait op de bovenste rij (pose 1)#define HERO_POSITION_RUN_UPPER_2 12 // (pose 2)LiquidCrystal lcd(11, 9, 6, 5, 4, 3);static char terrainUpper[TERRAIN_WIDTH + 1];static char terrainLower [TERRAIN_WIDTH + 1];static bool buttonPushed =false;void initializeGraphics(){ static byte graphics[] ={ // Run positie 1 B01100, B01100, B00000, B01110, B11100, B01100, B11010, B10011, // Run positie 2 B01100, B01100, B00000, B01100, B01100, B01100, B01100, B01110, // Sprong B01100, B01100, B000000, B11110, B01101, B11111, B10000, B00000, // Onderste sprong B11110, B01101, B11111, B10000, B00000, B00000 , B00000, B00000, // Massa B11111, B11111, B11111, B11111, B11111, B11111, B11111, B11111, // Massa rechts B00011, B00011, B00011, B00011, B00011, B00011, B00011, B00011, // Massa links B11000, B11000, B11000, B11000, B11000, B11000, B11000, B11000, }; int ik; // Sla het gebruik van karakter 0 over, hierdoor kan lcd.print() worden gebruikt om // snel meerdere karakters te tekenen voor (i =0; i <7; ++i) { lcd.createChar(i + 1, &graphics[i * 8]); } for (i =0; i  9999) ? 5 :(score> 999) ? 4 :(score> 99) ? 3 :(score> 9) ? 2 :1; // Teken de scène terrainUpper[TERRAIN_WIDTH] ='\0'; terreinLower[TERRAIN_WIDTH] ='\0'; char temp =terrainUpper[16-cijfers]; terreinUpper[16-cijfers] ='\0'; lcd.setCursor(0,0); lcd.print(terrainUpper); terreinUpper[16-cijfers] =temp; lcd.setCursor(0,1); lcd.print(terreinLower); lcd.setCursor (16 - cijfers, 0); lcd.print(score); terreinUpper[HERO_HORIZONTAL_POSITION] =upperSave; terreinLower[HERO_HORIZONTAL_POSITION] =lagerOpslaan; return collide;}// Behandel de druk op de knop als een interruptvoid buttonPush() { buttonPushed =true;}void setup(){ pinMode(PIN_READWRITE, OUTPUT); digitalWrite (PIN_READWRITE, LAAG); pinMode (PIN_CONTRAST, UITGANG); digitalWrite (PIN_CONTRAST, LAAG); pinMode (PIN_BUTTON, INPUT); digitalWrite (PIN_BUTTON, HOOG); pinMode (PIN_AUTOPLAY, UITGANG); digitalWrite (PIN_AUTOPLAY, HOOG); pinMode (PIN_BUZZER,OUTPUT);//initialiseer de zoemerpin als een output digitalWrite (PIN_BUZZER, LOW); // Digitale pin 2-kaarten om 0 attachInterrupt (0/*PIN_BUTTON*/, buttonPush, FALLING) te onderbreken; initializeGraphics(); lcd.begin (16, 2);}void loop(){ statische byte heroPos =HERO_POSITION_RUN_LOWER_1; statische byte newTerrainType =TERRAIN_EMPTY; statische byte newTerrainDuration =1; statische bool spelen =false; statische bool blink =false; statische niet-ondertekende int afstand =0; if (!playing) { drawHero((blink) ? HERO_POSITION_OFF :heroPos, terrainUpper, terrainLower, distance>> 3); if (knipper) { lcd.setCursor(0,0); lcd.print("Druk op Start"); } vertraging (250); knipperen =!knipperen; if (buttonPushed) { initializeGraphics(); heroPos =HERO_POSITION_RUN_LOWER_1; spelen =waar; buttonPushed =onwaar; afstand =0; } opbrengst; } // Verplaats het terrein naar links AdvanceTerrain (terrainLower, newTerrainType ==TERRAIN_LOWER_BLOCK ? SPRITE_TERRAIN_SOLID:SPRITE_TERRAIN_EMPTY); AdvanceTerrain (terrainUpper, newTerrainType ==TERRAIN_UPPER_BLOCK? SPRITE_TERRAIN_SOLID:SPRITE_TERRAIN_EMPTY); // Maak een nieuw terrein om rechts in te voeren if (--newTerrainDuration ==0) { if (newTerrainType ==TERRAIN_EMPTY) { newTerrainType =(random(3) ==0) ? TERRAIN_UPPER_BLOCK:TERRAIN_LOWER_BLOCK; newTerrainDuration =2 + willekeurig (10); } else { newTerrainType =TERRAIN_EMPTY; newTerrainDuration =10 + willekeurig (10); } } if (buttonPushed) { if (heroPos <=HERO_POSITION_RUN_LOWER_2) heroPos =HERO_POSITION_JUMP_1; buttonPushed =onwaar; digitalWrite(PIN_BUZZER,HOOG); } if (drawHero(heroPos, terrainUpper, terrainLower, distance>> 3)) { playing =false; // De held is ergens tegenaan gebotst. Jammer. for (int i =0; i <=2; i++) {digitalWrite(PIN_BUZZER, HIGH); vertraging (100); digitalWrite (PIN_BUZZER, LAAG); vertraging (100); } } else { if (heroPos ==HERO_POSITION_RUN_LOWER_2 || heroPos ==HERO_POSITION_JUMP_8) { heroPos =HERO_POSITION_RUN_LOWER_1; } else if ((heroPos>=HERO_POSITION_JUMP_3 &&heroPos <=HERO_POSITION_JUMP_5) &&terrainLower[HERO_HORIZONTAL_POSITION] !=SPRITE_TERRAIN_EMPTY) { heroPos =HERO_POSITION_RUN_UPPER_1; } else if (heroPos>=HERO_POSITION_RUN_UPPER_1 &&terrainLower[HERO_HORIZONTAL_POSITION] ==SPRITE_TERRAIN_EMPTY) { heroPos =HERO_POSITION_JUMP_5; } else if (heroPos ==HERO_POSITION_RUN_UPPER_2) { heroPos =HERO_POSITION_RUN_UPPER_1; } else { ++heroPos; } ++afstand; digitalWrite (PIN_AUTOPLAY, terrainLower [HERO_HORIZONTAL_POSITION + 2] ==SPRITE_TERRAIN_EMPTY ? HOOG:LAAG); } vertraging(100); digitalWrite(PIN_BUZZER,LOW);}

Schema's

Hier ziet u hoe u alle onderdelen met elkaar verbindt, aangezien niet alle bedrading op de omslagafbeelding werd getoond.

Productieproces

  1. TinyML-taaldetector-gebaseerd op Edge Impulse &Arduino
  2. Arduino-gyroscoopspel met MPU-6050
  3. Arduino digitale dobbelstenen
  4. DIY 37 LED Roulette Game
  5. Arduino-gamecontroller
  6. Joystick-spel
  7. Vind mij
  8. Pixel Chaser-game
  9. DIY 10Hz-50kHz Oscilloscoop op 128x64 LCD-scherm
  10. Arduino Audio Reactive Desk Light
  11. NeoMatrix Arduino Pong