So I’ve wrapped up my final project of the summer. During the pandemic, I’ve been brushing up on my electronics and learning how to use the Unreal Engine to create video games. I wanted to see if I could tie those two ideas together. Watch the video below to see how it’s possible to create a video game that requires you to know what is going on in the physical world. In this case, the color of an LED connected to a microcontroller informs the gamer which colored sphere to shoot.
As I’ve done with my other UE4 tutorials, below are the blueprints in case you are interested in building your own project.
Below is the microcontroller code.
/*
* Project ue4-lights
* Description: Tutorial for UE4 communication
* Author: BoBthechemist
* Date: 8/16/2020
*/
int ledArray[] = { D2, D3, D4 };
int which;
int randomLED(String args) {
// Options for args are none, red, blue, green, black
if( args.equals("red") ) {which = 0; }
else if( args.equals("green") ) { which = 1; }
else if( args.equals("blue") ) { which = 2; }
else if( args.equals("black") ) {which = -1; }
else { which = random(3); }
// Turn off all LEDs
for(int i = 0; i < 3; i++) {
digitalWrite(ledArray[i], LOW);
}
// Now turn on the LED we want
if (which >= 0) {
digitalWrite(ledArray[which],HIGH);
}
return which;
}
void setup() {
// Set LED pins to output
for(int i = 0; i < 3; i++){
pinMode(ledArray[i], OUTPUT);
}
Particle.variable("led",which);
Particle.function("changeLED", randomLED);
which = randomLED("");
}
void loop() {
delay(25);
}
What kind of microcontroller did you use? Or does it not matter?
This was done with a particle Argon. I’ve moved away from that platform and am now using Adafruit with their Adafruit.IO service, as that is easy to use via CircuitPython or the Arduino IDE.