From 356fb4429c9422cdcb93c76b7633d5e8b90a642b Mon Sep 17 00:00:00 2001 From: Markus Wirth Date: Tue, 23 Mar 2021 13:54:01 +0100 Subject: [PATCH 1/6] cherry picked commits between 729da886 (21 Apr 2018) and 7a03ea0d (11 Oct 2020) to get a working copy based off 729da886, but with all the fixes and improvements made later. This master branch in raidlman's repo appears to be broken: Only reset button, but none of the player buttons are working. See https://github.com/raidlman/1d-pong/blob/7a03ea0de621e74a311400ab0a429472601f9a95/Pong.cpp#L28 for comparison. The restart button is the only one being defined there. --- Pong.cpp | 11 ++++++++--- Pong.h | 1 + README.md | 16 ++++++++++++++++ schematic/schematic.png | Bin 0 -> 19167 bytes 4 files changed, 25 insertions(+), 3 deletions(-) create mode 100644 schematic/schematic.png diff --git a/Pong.cpp b/Pong.cpp index e59aa43..0baa76b 100644 --- a/Pong.cpp +++ b/Pong.cpp @@ -34,6 +34,7 @@ Pong::Pong(uint8_t player_1_pin, uint8_t player_2_pin, uint8_t lifes, uint16_t b auto_serve_timeout = 2000; position_is_allowed = false; waiting_time = millis(); + isFirstRun = true; randomSeed(analogRead(random_seed_pin)); } @@ -48,7 +49,7 @@ void Pong::prepare_next_serve() { void Pong::choose_random_player() { // randomly select active player to serve the first ball active_player = random(0,2); - ball.set_position((active_player) ? -1 : 60); + ball.set_position((active_player) ? players[0]->hitbox_min -1 : players[1]->hitbox_max +1); ball.set_direction((active_player) ? 1 : -1); } @@ -73,14 +74,18 @@ void Pong::game_logic() { switch(state) { case WAITING: screen.show_score(player_1, player_2); - if (restart.is_pressed()) { + if (restart.is_pressed() || (isFirstRun && (millis() - waiting_time >= 5000))) { choose_random_player(); player_1.reset_lifes(); player_2.reset_lifes(); screen.reset(player_1, player_2); - state = SERVE; + if (isFirstRun) { + isFirstRun = false; + } + + state = SERVE; } if (millis() - waiting_time >= 30000) { state = IDLE; diff --git a/Pong.h b/Pong.h index bc5d308..982b708 100644 --- a/Pong.h +++ b/Pong.h @@ -54,6 +54,7 @@ class Pong { Player player_2; Screen screen; Ball ball; + bool isFirstRun; unsigned long autoserve_time; unsigned long autoserve_step_time; diff --git a/README.md b/README.md index bf38ecb..654174c 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,22 @@ Hardware build instructons & wiring schemes will be published soon! - 1x 65x50x35mm IP 65 https://www.boxexpert.de/epages/79711065.sf/de_DE/?ObjectPath=/Shops/79711065/Products/BXPBABS655035-E01 * 3x Sanwa OBSN-30 pushbutton +## Schematic + +![Schematic](/schematic/schematic.png?raw=true "Schematic") + +The wiring is pretty simple. + +All electronics are powered via the same 5V power supply. +Make sure to use a supply that can deliver 2A. + +There are three push buttons that pull the pin to high when beeing pressed. +Each button is connected to ground via a pull down resistor. + +The input pins of the LED strip are connected to the SPI interface of the arduino. +CI (clock in) is connected to SCK and DI (data in) is connected to MOSI. +The power lines are directly connected to the power source. + ## Feature Requests / Ideas from "Lange nacht der Computerspiele / HTWK Leipzig" * Allow hits one off (+-1 outside of hit box) diff --git a/schematic/schematic.png b/schematic/schematic.png new file mode 100644 index 0000000000000000000000000000000000000000..ae55aed4f2a44d2833447b3657294b9a71c72510 GIT binary patch literal 19167 zcmeIacT^NxurJ)8fPjEX5)lkY&LCMpR8UcpFpPitfl4OAyVUVa~ zP;ydokT@Vp9*~^g?m^G-+#gJ;Nl=!NlgiY-i16HPpK{ z(nifgca;7+~(AXk7atMP-!H^}&_lw@n z3%a(ayKYBZf=)llLpnW)Uc54xJ?xvMUV7U%p&IL$H0=AZ9FqH(NTT`(@;$jdNOhaBh0^%c zdNHHyEZqMi3Y9MZ-UZ7Httx%S*7z!D>n8_fz0=h{qgs4%14FX<*vBB5I09R`GFU%g ziY^(Nw2z{UN|y{r{0n5}>h=OwKRy2Jn~uzg1JLc5Id7xF!F8sb;&r=ha6@pB&#nl= zTuQ2GDvYbioB+agu773$d+QQ|ww0#p?5Ed=0}c5@i6nl93;CJTPeKnK5ji}HfFKb$ z1J`aFpNjwjw&K)Selw~Lv=<+q`O;{AG#P~SjKk*A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ln)lW<8G_*=fDA;<(bf7|2!&K*MhM_*E9IHi>zk@>@JTd-iC zhHZ8|_;jPha(Z-1kreopO#p?hs&C)|H&epm1=q(zFDkn-LOhGPNSXc@7}LDMZ2=5% zaOScm#d0%o>#ur0_73S#!+=qOV%$lJ(mUcmu6{(L}uo#`J8g5dX_h{-8nEdG@nWcvTA^C|)3 zv%AyVAn<|#p2BJzVTc~6&Vk)pV+x%8h3mt_-xr6mo>HJD1AJTsfl`{0L`HOI^%{i{L{A#shnzW(({}W-ie8F3kUe_f1Hffy<5RYkMTE+gtSea z|Epyzp%^EQg90vD*bST=MJO3+giB$FCcp0!*3VCzC59}VNFN|d3`CNaJncz+Br06%^`ep}*S!z59n(hrs&gwz)KIRB>a8=Ncdms z`(IQ4|6*t5SIK{9&l)n<2hBQ}^*} zlB%VkK{}N}o&p+(;kf9TAPd9qC!wdK21iv2&!4A*9Hqt21z9+KKLuU;GH^_V6B0ZK zNmw}4WS&oY4xPSMz!RiOegbT$u@1aR|9f8^x*ZAhP>L@BJ@9mF_R=fh89-5K&L{A) z*>njBvC=nz&kfxe@4I;|Ax1k*!D;@$GJx(X_jPjm{E#yn86szZ7QTJ5AOycz*V Date: Tue, 23 Mar 2021 14:26:40 +0100 Subject: [PATCH 2/6] Add documentation for isFirstRun feature to start playing immediately after bootup without pressing the reset button. --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index 654174c..0503238 100644 --- a/README.md +++ b/README.md @@ -35,6 +35,10 @@ The input pins of the LED strip are connected to the SPI interface of the arduin CI (clock in) is connected to SCK and DI (data in) is connected to MOSI. The power lines are directly connected to the power source. +## Features +* Game starts immediately after a few seconds + - You might not need a reset button, if you're willing to switch power off and on. + ## Feature Requests / Ideas from "Lange nacht der Computerspiele / HTWK Leipzig" * Allow hits one off (+-1 outside of hit box) From 91823bf7694b84c3afb245a2c9fa4acd5cd5d3b4 Mon Sep 17 00:00:00 2001 From: Markus Wirth Date: Tue, 23 Mar 2021 14:28:38 +0100 Subject: [PATCH 3/6] added low brightness and high speed mode --- Ball.cpp | 4 ++++ Ball.h | 1 + Pong.cpp | 6 ++++++ README.md | 3 +++ Screen.cpp | 5 +++++ Screen.h | 1 + 6 files changed, 20 insertions(+) diff --git a/Ball.cpp b/Ball.cpp index 95b331d..7999d90 100644 --- a/Ball.cpp +++ b/Ball.cpp @@ -93,6 +93,10 @@ void Ball::hit() { increase_speed(); } +void Ball::increase_initial_speed() { + this->initial_speed = 0.6; +} + void Ball::calc_speedup(Player &player) { speedup = distance_to_field_boundary(player)/10.0; } diff --git a/Ball.h b/Ball.h index e4b9bd0..4d01ef0 100644 --- a/Ball.h +++ b/Ball.h @@ -42,6 +42,7 @@ class Ball { void hit(); void advance(); + void increase_initial_speed(); void calc_speedup(Player &player); void reset_speedup(); void serve(Player player); diff --git a/Pong.cpp b/Pong.cpp index 0baa76b..9c2b0f9 100644 --- a/Pong.cpp +++ b/Pong.cpp @@ -83,6 +83,12 @@ void Pong::game_logic() { if (isFirstRun) { isFirstRun = false; + if (players[0]->button.is_pressed()) { + screen.lower_brightness(); + } + if (players[1]->button.is_pressed()) { + ball.increase_initial_speed(); + } } state = SERVE; diff --git a/README.md b/README.md index 0503238..602fbf0 100644 --- a/README.md +++ b/README.md @@ -38,6 +38,9 @@ The power lines are directly connected to the power source. ## Features * Game starts immediately after a few seconds - You might not need a reset button, if you're willing to switch power off and on. +* During first run: + - Press Player 1 button to enter low brightness mode for darker environments (late at night, living room, bar/club) + - Press Player 2 button to enable high speed mode. Every game starts with increased initial speed. ## Feature Requests / Ideas from "Lange nacht der Computerspiele / HTWK Leipzig" diff --git a/Screen.cpp b/Screen.cpp index a061558..782d2d0 100644 --- a/Screen.cpp +++ b/Screen.cpp @@ -55,6 +55,11 @@ void Screen::draw_player_score(Player p){ } } +void Screen::lower_brightness() { + FastLED.setBrightness( 5 ); + FastLED.show(); +} + Screen::Screen(uint8_t num_leds, uint8_t brightness) : leds(new CRGB[num_leds]) { //led_type = type; //led_color_order = order; diff --git a/Screen.h b/Screen.h index 4dd0483..5b2d7e3 100644 --- a/Screen.h +++ b/Screen.h @@ -36,6 +36,7 @@ class Screen { public: Screen(uint8_t num_leds, uint8_t brightness); + void lower_brightness(); void show_score(Player &p1, Player &p2); void advance_ball(Ball &b, Player &p1, Player &p2); void draw(Player &player_1, Player &player_2, Ball &ball); From c08b4c3de6fd6f34ee29f11093a4536c5e732e3a Mon Sep 17 00:00:00 2001 From: Markus Wirth Date: Tue, 23 Mar 2021 15:07:39 +0100 Subject: [PATCH 4/6] add gameplay documentation, more hardware instructions and comments --- Pong.cpp | 9 ++++++++- README.md | 14 +++++++++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/Pong.cpp b/Pong.cpp index 9c2b0f9..e3851f4 100644 --- a/Pong.cpp +++ b/Pong.cpp @@ -26,7 +26,7 @@ Pong::Pong(uint8_t player_1_pin, uint8_t player_2_pin, uint8_t lifes, uint16_t b player_2(lifes, num_leds-lifes, num_leds-1, player_2_pin, button_lock_time, CRGB::Blue, CRGB::Red), screen(num_leds, brightness), restart(restart_pin, restart_lock_time), - ball(0, 0, num_leds-1, 0.2, 1) + ball(0, 0, num_leds-1, 0.2, 1) // 0.2 is the inital speed. An option has been added in Ball.cpp to start with higher speed. { players[0] = &player_1; players[1] = &player_2; @@ -74,6 +74,11 @@ void Pong::game_logic() { switch(state) { case WAITING: screen.show_score(player_1, player_2); + /* the game shall start after a few seconds after bootup of the Arduino. + * This makes using the reset pin optional, + * thus enables the game to be played without a separate reset button. + * Drawback: A restart of the game requires a reboot of the Arduino (takes only a few seconds). + */ if (restart.is_pressed() || (isFirstRun && (millis() - waiting_time >= 5000))) { choose_random_player(); @@ -83,9 +88,11 @@ void Pong::game_logic() { if (isFirstRun) { isFirstRun = false; + // During first run one can lower the brightness to play in dark environments. if (players[0]->button.is_pressed()) { screen.lower_brightness(); } + // During first run one can setup a high speed mode with increased initial_speed. if (players[1]->button.is_pressed()) { ball.increase_initial_speed(); } diff --git a/README.md b/README.md index 602fbf0..94484b6 100644 --- a/README.md +++ b/README.md @@ -2,9 +2,19 @@ Pong-like game run on an Arduino MCU and a LED light strip. Inspired by a game seen on 34C3. +## Gameplay +Two players at each end of the strip send the ball back and forth by pressing their player button. Each player has an area of several LED's at each end of the strip. The ball is represented by a single white LED and can only be sent to the opposing player, when it hit within ones own area. +The base speed of the ball accelerates whenever the ball is hit by a player. +A goal is attributed once the ball is behind a player's area, which means behind the end of the LED strip. +The game is over once a player scores 8 goals. +Player 1 is represented by 8 green LED's, nearest to the LED connector socket. Player 2 is represented by 8 blue LED's, farther from LED connector socket. +Pro Tip for venturesome players: Hit the ball closer to your own goal to send it back to your opponent with much higher speed. + +After 30 seconds without activity the LED strip shows some colorful animations until the next game is being started. + ## Required Arduino Libraries -* FastLED (v3.1.6): http://fastled.io/ +* FastLED (tested with v3.1.6 and 3.4.0): http://fastled.io/ - In Arduino IDE: Sketch > Include Library > Manage Libraries ## Used Hardware @@ -12,6 +22,7 @@ Pong-like game run on an Arduino MCU and a LED light strip. Inspired by a game s Hardware build instructons & wiring schemes will be published soon! * 1x Arduino Pro Mini + - Adafruit Arduino Pro Mini 5V 16 MHz works, too, including USB power and data support. Separate power supply is not needed in that case. Separate FTDI programmer is not needed, too. The strip can be bus powered straight from the 'bus' pin, which supports 700 mA. This is enough to drive 60 LED's at 80% brightness. * 1x APA102-C LED light strip (1m) with 60 LEDs/m * 1x 5v power supply (max. 2A) * BOXEXPERT ABS casings @@ -30,6 +41,7 @@ Make sure to use a supply that can deliver 2A. There are three push buttons that pull the pin to high when beeing pressed. Each button is connected to ground via a pull down resistor. +Without the resistor each pin would be touch sensitive. Then the pin registers as being pressed, when any cable is attached to it or any finger or metal object touches it. For testing the pins in general, this is a quite useful behaviour. The input pins of the LED strip are connected to the SPI interface of the arduino. CI (clock in) is connected to SCK and DI (data in) is connected to MOSI. From 2ffb7699af5809f1336bd43250f47d741789279c Mon Sep 17 00:00:00 2001 From: Markus Wirth Date: Tue, 23 Mar 2021 15:29:29 +0100 Subject: [PATCH 5/6] Party colours will be displayed for a longer period of time during inactivity for a quieter visual perception and attention by the LED's. --- Screen.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Screen.cpp b/Screen.cpp index 782d2d0..e27db6e 100644 --- a/Screen.cpp +++ b/Screen.cpp @@ -142,8 +142,8 @@ void Screen::FillLEDsFromPaletteColors( uint8_t colorIndex) void Screen::ChangePalettePeriodically() { - uint8_t secondHand = (millis() / 1000) % 60; - static uint8_t lastSecond = 99; + uint8_t secondHand = (millis() / 1000) % 240; + static uint8_t lastSecond = 239; if( lastSecond != secondHand) { lastSecond = secondHand; @@ -156,8 +156,8 @@ void Screen::ChangePalettePeriodically() if( secondHand == 35) { SetupBlackAndWhiteStripedPalette(); currentBlending = LINEARBLEND; } if( secondHand == 40) { currentPalette = CloudColors_p; currentBlending = LINEARBLEND; } if( secondHand == 45) { currentPalette = PartyColors_p; currentBlending = LINEARBLEND; } - if( secondHand == 50) { currentPalette = myRedWhiteBluePalette_p; currentBlending = NOBLEND; } - if( secondHand == 55) { currentPalette = myRedWhiteBluePalette_p; currentBlending = LINEARBLEND; } + if( secondHand == 230) { currentPalette = myRedWhiteBluePalette_p; currentBlending = NOBLEND; } + if( secondHand == 235) { currentPalette = myRedWhiteBluePalette_p; currentBlending = LINEARBLEND; } } } From e3d0cb011e4862f7535cbfc976d7eaf0337d1d81 Mon Sep 17 00:00:00 2001 From: Markus Wirth Date: Tue, 23 Mar 2021 15:42:37 +0100 Subject: [PATCH 6/6] added documentation from https://github.com/raidlman/1d-pong/issues/4#issuecomment-787542522 --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 94484b6..3a17117 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ After 30 seconds without activity the LED strip shows some colorful animations u Hardware build instructons & wiring schemes will be published soon! * 1x Arduino Pro Mini - - Adafruit Arduino Pro Mini 5V 16 MHz works, too, including USB power and data support. Separate power supply is not needed in that case. Separate FTDI programmer is not needed, too. The strip can be bus powered straight from the 'bus' pin, which supports 700 mA. This is enough to drive 60 LED's at 80% brightness. + - Adafruit Pro Trinket 5V 16 MHz works, too, including USB support! Neither a separate power supply nor a Serial-to-USB-Adapter (FTDI programmer) are needed. The LED strip can be bus powered straight from the 'bus' pin, which supports 700 mA. This is enough to drive 60 LED's at 80% brightness. Beware, pin 7 is not available on this board, but Pins 3-6, Pin 8 and Pins A0-A5 are. * 1x APA102-C LED light strip (1m) with 60 LEDs/m * 1x 5v power supply (max. 2A) * BOXEXPERT ABS casings