Team 4 - Angry Birds Controller
Description
For this project, we created an alternative controller for the computer game Angry Birds Rio. The goal was to design a controller that allows the player to simulate the slingshot mechanic of the game without relying on traditional mouse or keyboard inputs. Using the Circuit Playground Express (CPE) microcontroller, we employed several built-in sensors, including the accelerometer, light sensor, and an external potentiometer, to create a unique interaction model.
The conceptual model for the controller revolves around replicating the feeling of pulling back a slingshot to launch the birds. The potentiometer controls the horizontal slingshot motion, simulating the tension in the slingshot by adjusting the angle, while the accelerometer senses the vertical motion, representing the amount of force with which the slingshot is pulled back. The light sensor is used to detect when the player is ready to fire the bird, mimicking the moment of release when the player is prepared to launch. The input-to-output mapping for the controller uses the potentiometer to adjust the horizontal movement of the slingshot ( mouse movement). The accelerometer (motionY), controls the vertical movement (Y-axis) of the slingshot. Lastly, the light sensor triggers the mouse click to simulate the release of the slingshot when the light value passes a certain threshold.
The feedback provided by the system connects directly to the game's theme of precision and control in slingshot aiming. The controller’s physical movement (using the potentiometer and accelerometer) directly translates to the slingshot’s movement in the game, providing a more immersive experience. The light sensor feedback (mouse click) gives the player immediate tactile confirmation when the slingshot is released.
Feedback Question:
What other sensor would've been a bit smoother to control the angle of the slingshot?
Video Demonstration
Schematic
Code
#include <Mouse.h>#include <Adafruit_CircuitPlayground.h>void setup() {CircuitPlayground.begin();Mouse.begin();Serial.begin(9600);pinMode(CPLAY_SLIDESWITCHPIN, INPUT_PULLUP);pinMode(A2, INPUT);pinMode(A5, INPUT);}void loop() {// Check if the slide switch is ON (allows enabling/disabling mouse functionality)if (digitalRead(CPLAY_SLIDESWITCHPIN) == LOW) {// Read sensor valuesfloat y = CircuitPlayground.motionY(); // Y-axis acceleration from accelerometerint knobValue = analogRead(A5); // Read from potentiometer (0-1023)int lightValue = analogRead(A2
); // Read light sensor (0-1023)Serial.print("Light Value: ");Serial.println(lightValue);Serial.print("Knob Value: ");Serial.println(knobValue);// Map knob value to mouse movement on X-axis (inverted movement)int mouseX = map(knobValue, 0, 1023, -10, 10); // Adjust range as needed// Map motionY() to mouse movement on Y-axisint mouseY = map(y, -10, 10, -20, 20);// Threshold to filter out small movements (dead zone)if (mouseY > 1 || mouseY < -1) {Mouse.move(0, mouseY, 0); // Move only on Y-axis}if (mouseX > 3 || mouseX < -3) {Mouse.move(mouseX, 0, 0); // Move only on X-axis}// Click and hold when the light sensor detects high valuesif (lightValue < 250) { // Adjust threshold as neededMouse.press(MOUSE_LEFT);} else {Mouse.release(MOUSE_LEFT);}// Pull back the slingshot using the knob (additional functionality)if (knobValue > 512) { // Adjust this threshold as necessary// You could add visual feedback or other code for slingshot pullbackSerial.println("Slingshot pulled back!");}delay(50); // Adjust delay for responsiveness} else {// Release the mouse buttons and stop mouse movement when the switch is OFFMouse.release(MOUSE_LEFT);}}
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.