Announcement

Collapse
No announcement yet.

Black Knight: Sword of Rage Pro - Animated LED ramp mod using Arduino and a sensor

Collapse

Discuss any pinball modifications here.

X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Black Knight: Sword of Rage Pro - Animated LED ramp mod using Arduino and a sensor

    Something that has been on my "TO DO" list for awhile now is to create an animated LED strip mod for the flail ramp on my Black Knight: Sword of Rage PRO pinball machine. On the Premium and LE models, the lightning bolt cutouts on the metal ramp are lit from below the playfield with 2 strips of addressable LED's. These are then animated by code in the game, allowing the programmers to play different patterns based on the active rules. The PRO model does not have these LED's and it's left black. I purchased a mod from Mezel Mods many months ago that adds 2 LED strips below the ramp BUT they are not animated. Instead all LED's can only be the same colour and the animation support is limited to fade, solid or blink. You're also limited to a selection of 15 or so colours. I want to make something much more interesting (and cheaper) so have decided to use an Arduino board to control 2 addressable LED strips so I can animate them. I won't be able to hook them up to the game code and animate them in the same way as on the Premium and LE games, but I can perhaps use the state of the flail to change the animation. I see this as a good exercise in exploring Arduino and how I may be able to use it in my Pinbot 2.0 project. First up, an Arduino Uno board and case were ordered.



    The case is very simple to put together and adds a nice protective barrier around the Arduino board.



    I purchased a 1 meter WS2812B LED strip which is fully addressable. This means I can control each individual LED on the strip, making it perfect for animation. The strip was cut down to the size required for the ramp and new pins were soldered to the 5V, ground and data wires from the strip. These pins will insert into the Arduino board.



    With the Arduino and LED strips ready, it was time to look at some coding. I don't expect many people here will be interested in the code side of it (except maybe for thegrunta666 ) but I'll include some details anyway. There is a great library for Arduino called FastLED which makes interfacing with a LED strip like this easy. The FastLED library can be found on GitHub here - https://github.com/FastLED/FastLED. Once this was downloaded, I imported it into the Arduino IDE. The Arduino IDE can be downloaded from here - https://www.arduino.cc/en/main/software

    I created a new project and began putting code together. First step was to set up my definitions to define the number of LED's I'll be using, data pins, the animation types and number of colours to use for animation. Putting these values in clearly defined variables makes tweaking the values easy and the code easier to read.



    Then I defined my global variables that will contain the colour data, animation type, and colour index.



    The setup() function is defined next, which initialises FastLED along with my colours for animation. Once I'm settled on the colour sequence, I'll move this into a data array. All LED's are set to off and then FastLED is updated (with the show() call) to push that data to the LED strip.



    The loop() function is the main update loop for the project. In here is where the animation will happen. Using a switch case statement, I call the update function based on the current animation type. Each update function will update the state of the leds array which tells FastLED what colours to render on each LED.



    I have two other functions to define. The first resets all LED's to off. This is called once at start up and then each time the animation type switches. The updateAnimationType() function will update the type of animation being rendered to the LED strips every 4 seconds. Once I had the sensor hooked up, this function will change to switch between the animation type based on the state of the flail (open, closed or moving).



    I spent a couple of hours playing around with the code and evolving it to the point where I have 4 different animation types, which cycle every 4 seconds. Each animation type has its own update function. I have plans to create at least two more and will eventually pick the 3 most suited to the states of the flail.









    The LED strips were hooked up to the Arduino board, which was then hooked up to my PC via USB cable. The code was deployed to the board for testing. After sorting out a few bugs, it was running smoothly.



    Here is a short video showing the project running by playing the 4 different animation types currently added. It's currently hooked up to my PC via USB. When installed within the pinball machine, I'll have it hooked up to the 12V port.



    I'm not happy with the large spaces between the LED on this strip. This strip has 30 LED's per meter. When lined up on the ramp, I think 60 per meter would work much better, so I will order a new LED strip to use.



    I've uploaded the code to GitHub and will continue to add to it over the coming weeks with some more animation types, proper transitions between animations and of course support for a sensor to detect the flail state. https://github.com/enteryourinitials/bksor-chaser. I'll also flesh out the GitHub repository with more information too.

    That's it for the first update. I've got the sensor and new LED strip ordered which should arrive sometime in the next week or so. Meanwhile, I'll refine my code more and add some improvements, ready to support the sensor. I had some ideas for additional animations to try out which I'll implement also. Another task for me to look at is how best to mount the sensor and Arduino under the playfield. I'm going to use the existing frame from the Mezel Mod version to mount my LED's on when ready. Still plenty to do

    Last edited by Jesder; 8 January 2020, 10:16 AM.
    Eschew the standard. Turn the paradigm upside down.

  • #2
    Featured.
    Great post...and use of the attachments.

    Comment


    • #3
      I've been working away on the code a bit more today and have added another two animation types to the list. I've only included the new animation types in the video. What I might do later tonight is a video of all 6 modes in action and replace the old video with a new one.



      I have a few more ideas but will hold off on them for the moment. I'm not 100% happy with the implementation of the new animation types and want to refactor them.

      There was another task I needed to look at in preparation for the sensor. How the update() function had been set up wasn't going to support the sensor very well. At the end of the loop() call, I would make a call to the delay() function. This essentially stops the Arduino there until the delay completes. This is fine for the animation, but while we're not animating the LED's, we want to be polling the sensor (once I get it hooked up). Thinking back to my game development days, we would have the update loop always running, with a delta time value passed in that allowed all the subsystems to update accordingly.

      Arduino has a function called millis() which returns the number of milliseconds it has been running for. I can calculate the time delta between update calls by recording the value returned by millis() and comparing it to the previous call. This requires 3 new variables to be defined.



      The update loop is now much more simplified. The deltaTime value is calculated and then passed into the subsystems. Right now there are two things that need to occur. The first is animating the LED strips and the second is switching between the animation types. When I'm ready with the sensor, there will be an update call to read the sensor and trigger changes in the animation when required.



      The deltaTime value can then be subtracted from delays or timer variables (depending on what the subsystem needs to do) and essentially delay like it did before but without holding up the rest of the project.



      My little sensor was put in the mail over the weekend, so with some luck I'll have it by Friday. I'm looking forward to hooking it up to the Arduino and advancing the updateAnimationType() function to switch between modes based on the sensor readings.
      Eschew the standard. Turn the paradigm upside down.

      Comment


      • #4
        A little more progress was made yesterday on my mod. The small sensor arrived and so I created a cable that will connect it to the Arduino board and also draw power from an old PC power supply. In the final version, all power will be coming from the machine, so no extra power supply will be required. For now though, this was the quickest way for me to get it up and running to play with.



        The sensor was hooked up to the Arduino board and the code updated. I initially started with just 2 modes - open and closed. The animation being rendered to the LED strip would change when the state of the sensor changed.



        I then added a third state to handle the case where the flail is moving. This was a little more complicated, but once I got my head around handling the 3 states, the code became a lot simpler. Some additional code was added to allow for some cool down before switching modes. I took a short video of it running, showing off the 3 modes in action. Apologies for the loud PC fan - it's an old one I picked up free from work and used for testing things like this.



        The dampening values and logic used to smooth out switching animation types will most likely need some tweaking once in the game. It holds together well on my desk when manually testing, but in the game with the real flail spinning it could be a different story. The flail itself can move at several different speeds and I may get some unexpected behavior on the slower speeds.

        Next up I'll be looking at how I want to mount the sensor in the game and also create a connector for it to draw power from the game. Then I can get some actual live testing of it and see it in action

        All the latest code changes have been pushed to the github repository too - https://github.com/enteryourinitials/bksor-chaser/
        Eschew the standard. Turn the paradigm upside down.

        Comment


        • #5
          Great write up
          definitely good to see the arduino code description as I have a project coming up that I need to get into programming.

          Comment


          • #6
            A few months back I was speaking with thegrunta666 at a pinball meet and he mentioned the cost of an Uno board being around $15. I was a little surprised as the one I had purchased was $40. I had a look at the place I purchased mine from and found a cheaper version. It's not an "Official" Arduino, but runs the same chipset and is only $12. The downside is it's not guaranteed to work with all libraries. I decided give it a try as $12 would be a much cheaper option if I decide to make more of these.





            Here are the links to the two boards:

            https://core-electronics.com.au/uno-r3.html

            https://core-electronics.com.au/arduino-uno-r3.html

            I hooked my LED strip up and deployed the code to the new board. I was happy to find the cheaper Uno board works just as well without any comparability issues I'll keep the Arduino Uno for another project - perhaps something to enhance my Pinbot 2.0 project.

            The new LED strip also arrived yesterday, which has twice as many LED's as the original. This will work so much better on the ramp. There will now be 14 LED's per strip instead of 7.



            I updated the code to work with 14 LED strips and also fixed a small bug with the chase animation (played when the flail is open). I'm just waiting on a couple of connectors to arrive so I can improve the wiring and then I'll look at how to best mount the sensor.
            Eschew the standard. Turn the paradigm upside down.

            Comment


            • #7
              These are a great little cheap option for Addressable LED control, for some spiffy lighting mods. Just doing a simple light chaser with one of these for Budgie . What i like is that its easy to change the LED Colour and brightness of the LEDS to get the effect you want. Cant wait to see the posited video of the final install Jesder . ( please note that the word easy means you have a good understanding of C++, which I dont, but i can still hack the code to my evil purposes )

              Comment

              Users Viewing Topic: 0 members and 1 (guests)
              Working...
              X