Yifan’s Final Project Ideas

Concept 1: Doggie

An ultrasonic sensor will record the activities and upload them to your phone.

If the user interacts less than 10 times, they will receive a warning message.

Concept 2: Desk game

Use the phone to control the soccer ball.

Concept 3: Kick this button

Record the laptop or the phone’s click times and send them to Ax. Ax will “kill” the control button.

11.14 Process

Javascript game combine with physical game

Create a mobile game:

  1. Choose a Game Development Platform:
    • Select a game development platform that suits your skill level and requirements. For example, Unity is a popular and powerful game development engine that supports cross-platform development.
  2. Learn Game Development Basics:
    • Acquire knowledge about basic concepts such as game design, scene creation, and character control.
  3. Create Game Scene:
    • Utilize game development tools to create a simple game scene and implement functionalities for controlling the character.
  4. Design User Interface (UI):
    • Add a virtual joystick, buttons, or other UI elements for control, which will be used for communication with the ESP8266.
  5. Write Game Logic:
    • Develop game logic, including the part that involves communication with the ESP8266. Here, you’ll need to define control commands and their corresponding actions.
  6. Export the Game:
    • Export the game as an application suitable for your target platform (iOS, Android, etc.).

ESP8266 Communication:

  1. Connect ESP8266 to WiFi network:
    • Use the WiFi library of ESP8266 to connect it to a WiFi network. You will need to provide the WiFi SSID and password.
  2. Create WebSocket Server:
    • Utilize the WebSocket library of ESP8266 to create a WebSocket server that listens for control signals from the mobile game.
  3. Write Code to Handle Control Signals:
    • Write code on ESP8266 to handle control signals received from the WebSocket. These signals will instruct the ESP8266 on how to move servos or perform other actions.
  4. Communicate with Mobile Game:
    • In the mobile game, use a WebSocket library or other network libraries to send control signals to the WebSocket server on ESP8266.
  5. Test:
    • Test the entire system, ensuring that control commands from the mobile game are correctly sent to ESP8266, and ESP8266 can accurately interpret and execute the corresponding actions.
  6. Debug and Optimize:
    • If there are any delays or communication issues, debug and perform necessary optimizations.

JavaScript

ESP8266 code

const char *ssid = “WiFiSSID”;
const char *password = “WiFiPassword”;
const int webSocketPort = 81;
const int buttonPin = 2;
const int servoPin = 5;

Servo myServo;
WebSocketsServer webSocketServer = WebSocketsServer(webSocketPort);

void handleWebSocketMessage(uint8_t num, uint8_t *data, size_t length) {
if (length > 0) {
int angle = data[0];
myServo.write(angle);
}
}

void setup() {
Serial.begin(115200);

pinMode(buttonPin, INPUT);
myServo.attach(servoPin);

WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.println(“Connecting to WiFi…”);
}
Serial.println(“Connected to WiFi”);

webSocketServer.begin();
webSocketServer.onEvent(handleWebSocketMessage);
}

void loop() {
webSocketServer.loop();

if (digitalRead(buttonPin) == HIGH) {
myServo.write(90);
delay(1000);
} else {
myServo.write(0);
}
}

%d