Hello today I'm going to show you how to get Tetris running on your LED matrix
and how you can also control it via bluetooth from your phone
this leads on from a project I started a couple of months back now using an ESP32 and if you haven't seen that video I'll leave a link in the description and
if I can I'll put a little card up above here as well. So now you've seen what it
looks like and how bad I am at Tetris let's get started. I'm going talk you
through now how to install the software to make this work if you want
to replicate what I've done here. If you've never used the ESP32 board before
in the arduino IDE, I recommend this tutorial from randomnerdtutorials.com, there's a link to this in the description below and this will show
you how to quickly and easily get the ESP32 setup in the Arduino IDE
Now the tetris software is very heavily based on an
example by this chap, Aaran Liddiment and again there's a link to his github
in the description below, and he's created a series of libraries for FastLED. So you got LEDText, LEDMatrix and LEDSprites are the ones that we're
going to actually use so we're going to download each one of those so just go
into each one, the LEDMatrix here for example we can click on download.
You download it as a zip file and you want to do the same for LEDText and LEDSprites
and then you want to put them in your normal Arduino libraries folder.
The next thing you're gonna want to do is download the .ino file now as I say this
was originally written by Aaron Liddiment but I've altered it quite
a bit so instead of working on button presses it actually works over bluetooth
instead and I'll show you how to set that up in a minute. So you should have
the ino file, it looks something like this now the thing is if we've got our
libraries installed, the three different libraries, and we've got the tetris ino
file here if I hit compile on this you'll notice that it will actually
throw up a few errors so let's give this a few minutes to sort
itself out and the errors are related to the fact that the max and min functions
in the ESP32 library have actually changed. So previously you could put into these
functions, you could mix types so in some of this code you get ints and uint8_ts
mixed together in min/max code and what happens there is it
throws some errors. So let's have a look at the error log or the output log down
here and we'll scroll through to here, okay so it says M frame equals
max M number frames minus 1 frame and the issue is it says there's no matching
function for call to max(int, uint8_t) so to fix that problem all we need to
do is go to your libraries folder and where you've got
LEDSprites master, go into there and we load up the LEDSprites.cpp. If we
search for max and you can see there there's a function max
open brackets blah blah or whatever's inside that, now we need to change that instead
of using the ESP32 version of this we need to use the original Arduino version
of this instead so what we're gonna do is we're gonna replace that with
underscore max open brackets everywhere we find that in LEDSprites.cpp.
Do a replace all on that and it says three occurrences were replaced and it's exactly
the same with min as well so we look for min, replace all, and two of
those occurrences were replaced so we're gonna save the file, go back to our Arduino
file and if we try and compile this time hopefully it should compile without any errors
That took a few seconds but you can see there that it has compiled happily.
With the Bluetooth control you have two different options, I have
linked the apk file in below so you can simply download that and side-load it
onto your Android device. If you don't want to do that I've also included the
aia file which is an MIT App Inventor file so if you want to have a look at
how this works or if you want to change how this works that's easy to do.
You go to MIT App Inventor and sign in or sign up for a new account, projects
import .aia from my computer, and it should appear here. Then you can muck about
with it from here you can change whatever you like, you can
change the code you can change the pictures that appear on here.
It's a little bit beyond the scope of this video so this is something you'd like to
do there are plenty of App Inventor tutorials online you can do that.
Once you're happy with it you can click on build and you can click app and you can
simply save the apk to your computer and then you can side-load it onto your
Android device as before. So I think that's everything software wise, all we have to
do now is upload the sketch to our ESP32 find the apk on your phone and connect
to the Bluetooth. The first time you do this you'll have to pair your phone with the
Bluetooth module in the ESP32, we're gonna press scan here, what we're
looking for as is ESP32Tetris, I just scroll down here there it is, ESP32Tetris
it says pairing, and it's done. OK, at this point we're then gonna open up the
Bluetooth app that we side-loaded earlier, it looks something like this, let's press
scan and again we're looking for ESP32Tetris which is this one just here.
Now we should be connected so let's set up this camera properly and we'll
have a play. Let's have a little play with this and you can watch and see
how terrible I am at playing Tetris
Yeah I think the phrase is more practice is required. That's all I've got for
you today, if you have any questions or comments please leave them below.
Thank you very much, and I'll see you next time.