Skip to content

Commit

Permalink
v0.11.0: Pong game added
Browse files Browse the repository at this point in the history
  • Loading branch information
TheDIYGuy999 committed Feb 21, 2023
1 parent 118b8c4 commit aeff6a7
Show file tree
Hide file tree
Showing 4 changed files with 342 additions and 7 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ forked from his GitHub: https://github.com/Ziege-One/Servotester_Deluxe

PCB, schematic and more details: https://www.pcbway.com/project/shareproject/Servotester_Deluxe_62a3f47c.html

## New in v0.11.0:
- Added a Pong game ;-)
- Ball speed is adjustable in settings

## New in v0.10.0:
- Added encoder acceleration in servo tester mode. Makes the operation very handy. If you want to make bigger servo movements, just rotate the encoder faster!
- Unstable Multiswitch issues because of incompatible espressif 32 board solved, see comments in src.ino
Expand Down
116 changes: 109 additions & 7 deletions src/src.ino
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
GPIO 22: SDL OLED
*/

char codeVersion[] = "0.10.0"; // Software revision.
char codeVersion[] = "0.11.0"; // Software revision.

//
// =======================================================================================================
Expand Down Expand Up @@ -89,7 +89,7 @@ ESP32AnalogRead 0.2.1
#include "src/languages.h" // Menu language ressources

// EEPROM
#define EEPROM_SIZE 40
#define EEPROM_SIZE 44

#define adr_eprom_WIFI_ON 0 // WIFI 1 = Ein 0 = Aus
#define adr_eprom_SERVO_STEPS 4 // SERVO Steps für Encoder im Servotester Modus
Expand All @@ -100,7 +100,8 @@ ESP32AnalogRead 0.2.1
#define adr_eprom_POWER_SCALE 24 // SERVO µs Mitte Wert im Servotester Modus
#define adr_eprom_SBUS_INVERTED 28 // SBUS inverted
#define adr_eprom_ENCODER_INVERTED 32 // Encoder inverted
#define adr_eprom_LANGUAGE 36 // SBUS inverted
#define adr_eprom_LANGUAGE 36 // Gewählte Sprache
#define adr_eprom_PONG_BALL_RATE 40 // Pong Ball Geschwindigkeit

// Speicher der Einstellungen
int WIFI_ON;
Expand All @@ -113,6 +114,7 @@ int POWER_SCALE;
int SBUS_INVERTED;
int ENCODER_INVERTED;
int LANGUAGE;
int PONG_BALL_RATE;

// Encoder + button
ESP32Encoder encoder;
Expand Down Expand Up @@ -173,15 +175,17 @@ enum
Multiswitch_lesen_Auswahl = 4,
SBUS_lesen_Auswahl = 5,
IBUS_lesen_Auswahl = 6,
Einstellung_Auswahl = 7,
Pong_Auswahl = 7,
Einstellung_Auswahl = 8,
//
Servotester_Menu = 10,
Automatik_Modus_Menu = 20,
Impuls_lesen_Menu = 30,
Multiswitch_lesen_Menu = 40,
SBUS_lesen_Menu = 50,
IBUS_lesen_Menu = 60,
Einstellung_Menu = 70
Pong_Menu = 70,
Einstellung_Menu = 80
};

//-Menu 20 Automatik Modus
Expand Down Expand Up @@ -214,6 +218,8 @@ SSD1306Wire display(0x3c, SDA, SCL); // Oled Hardware an SDA 21 und SCL 22
SH1106Wire display(0x3c, SDA, SCL); // Oled Hardware an SDA 21 und SCL 22
#endif

#include "src/pong.h" // A little pong game :-)

// Webserver auf Port 80
WiFiServer server(80);

Expand Down Expand Up @@ -688,6 +694,33 @@ void MenuUpdate()
}
break;

// Pong Auswahl *********************************************************
case Pong_Auswahl:
display.clear();
display.setTextAlignment(TEXT_ALIGN_CENTER);
display.setFont(ArialMT_Plain_24);
display.drawString(64, 0, "< Menu >");
display.setFont(ArialMT_Plain_16);
display.drawString(64, 25, "P O N G");
display.setFont(ArialMT_Plain_10);
display.drawString(64, 45, "TheDIYGuy999 Edition");
display.display();

if (encoderState == 1)
{
Menu--;
}
if (encoderState == 2)
{
Menu++;
}

if (buttonState == 2)
{
Menu = Pong_Menu;
}
break;

// Einstellung Auswahl *********************************************************
case Einstellung_Auswahl:
display.clear();
Expand Down Expand Up @@ -1154,6 +1187,52 @@ void MenuUpdate()
}
break;

// Pong spielen *********************************************************
case Pong_Menu:

static bool paddleUp;
static bool paddleDown;
static bool reset;
pong(paddleUp, paddleDown, reset, encoderSpeed); // Run pong game

if (!SetupMenu)
{

SetupMenu = true;
}

if (encoderState == 1) // Paddle up
{
paddleUp = true;
paddleDown = false;
}
else if (encoderState == 2) // Paddle down
{
paddleDown = true;
paddleUp = false;
}
else // Paddle stop
{
paddleUp = false;
paddleDown = false;
}

if (buttonState == 1) // Back
{
Menu = Pong_Auswahl;
SetupMenu = false;
}

if (buttonState == 2) // Reset
{
reset = true;
}
else
{
reset = false;
}
break;

// Einstellung *********************************************************
case Einstellung_Menu:
display.clear();
Expand Down Expand Up @@ -1229,6 +1308,10 @@ void MenuUpdate()
display.drawString(64, 25, languageString[LANGUAGE]);
display.drawString(64, 45, languagesString[LANGUAGE]);
break;
case 10:
display.drawString(64, 25, pongBallRateString[LANGUAGE]);
display.drawString(64, 45, String(PONG_BALL_RATE));
break;
}
if (Edit)
{
Expand Down Expand Up @@ -1282,6 +1365,9 @@ void MenuUpdate()
case 9:
LANGUAGE--;
break;
case 10:
PONG_BALL_RATE--;
break;
}
}
}
Expand Down Expand Up @@ -1325,21 +1411,34 @@ void MenuUpdate()
case 9:
LANGUAGE++;
break;
case 10:
PONG_BALL_RATE++;
break;
}
}
}

// Menu range
if (Einstellung > 9)
if (Einstellung > 10)
{
Einstellung = 0;
}
else if (Einstellung < 0)
{
Einstellung = 9;
Einstellung = 10;
}

// Limits
if (PONG_BALL_RATE < 1)
{ // Pong ball rate nicht unter 1
PONG_BALL_RATE = 1;
}

if (PONG_BALL_RATE > 4)
{ // Pong ball rate nicht über 4
PONG_BALL_RATE = 4;
}

if (LANGUAGE < 0)
{ // Language nicht unter 0
LANGUAGE = 0;
Expand Down Expand Up @@ -1586,6 +1685,7 @@ void eepromInit()
SBUS_INVERTED = 1; // 1 = Standard signal!
ENCODER_INVERTED = 0;
LANGUAGE = 0;
PONG_BALL_RATE = 1;
Serial.println(eepromInitString[LANGUAGE]);
eepromWrite();
}
Expand All @@ -1604,6 +1704,7 @@ void eepromWrite()
EEPROM.writeInt(adr_eprom_SBUS_INVERTED, SBUS_INVERTED);
EEPROM.writeInt(adr_eprom_ENCODER_INVERTED, ENCODER_INVERTED);
EEPROM.writeInt(adr_eprom_LANGUAGE, LANGUAGE);
EEPROM.writeInt(adr_eprom_PONG_BALL_RATE, PONG_BALL_RATE);
EEPROM.commit();
Serial.println(eepromWrittenString[LANGUAGE]);
}
Expand All @@ -1621,6 +1722,7 @@ void eepromRead()
SBUS_INVERTED = EEPROM.readInt(adr_eprom_SBUS_INVERTED);
ENCODER_INVERTED = EEPROM.readInt(adr_eprom_ENCODER_INVERTED);
LANGUAGE = EEPROM.readInt(adr_eprom_LANGUAGE);
PONG_BALL_RATE = EEPROM.readInt(adr_eprom_PONG_BALL_RATE);
Serial.println(eepromReadString[LANGUAGE]);
Serial.println(WIFI_ON);
Serial.println(SERVO_STEPS);
Expand Down
1 change: 1 addition & 0 deletions src/src/languages.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ String inversedString[] {"Inversed", "Invertiert", "Inversé"};
String standardString[] {"Standard", "Standart", "Défaut"};
String encoderDirectionString[] {"Encoder direction", "Encoder Richtung", "Encodeur direct."};
String languageString[] {"Language", "Sprache", "Langue"};
String pongBallRateString[] {"Pong ball speed", "Pong Ball Gesch.", "Pong V. de balle"};

// Impuls lesen
String impulseString[] {"Impulse", "Impuls", "Impulsion"};
Expand Down
Loading

0 comments on commit aeff6a7

Please sign in to comment.