26 November 2024

Final Project Team 20: Minesweeper Controller

 


Minesweeper Controller

Conceptually, our controller is meant to mimic the precise and tedious hand movements of disarming a bomb, as well as physically placing objects in an environment. The cursor is operated with two dials. The left dial controls the horizontal movement, and the right dial controls the vertical movement. Flagging and detonating are operated with a series of pucks which are placed on a metal contact base. The "dig" puck, modeled after a shovel, has a metal contact running horizontally which activates a left click, while the "flag" puck, modeled after a flag, has one running vertically to activate a right click. Using these four inputs, any given game of Minesweeper could be fully completed. The main body of the controller is white and rectangular to resemble the tiles seen through the game. The shape also reminiscent of old-fashioned controllers from the 80's and 90's, the era of when Minesweeper was released. There is an additional tray attached to the side of the controller body to hold the pucks when they are not in use. The shape of the base of the pucks signifies that they can only be placed onto the contact base in a specific direction. Some limitations of this are that only one puck can be used at a time, and it is difficult to move cursor while simultaneously using a puck. 

What are some other solutions we could have explored for cursor control?

Contributions

Andrew Swanstrom: programming
Jackson Sommer: modeling and 3D printing
Collaborative: construction and testing

Schematic


Code

#include <Adafruit_CircuitPlayground.h>
#include <Adafruit_Circuit_Playground.h>
#include <Mouse.h>

bool leftOnce = true;
bool rightOnce = true;

void setup() {
  // put your setup code here, to run once:
  //CPE library
  CircuitPlayground.begin();
  //Mouse library
  Mouse.begin();
  Serial.begin(9600);

  pinMode(A0, INPUT_PULLUP); //declare two switches for left and right clicking/placing pucks
  pinMode(A3, INPUT_PULLUP);

  pinMode(CPLAY_SLIDESWITCHPIN, INPUT_PULLUP); //failsafe switch
}

void loop() {
  // put your main code here, to run repeatedly:

  if (CPLAY_SLIDESWITCHPIN){ //failsafe
    //Prints the potentiometer values
    Serial.println(analogRead(A1));
    Serial.println(analogRead(A2));

    //assigns variables
    int potX = analogRead(A1);
    int potY = analogRead(A2);

    //move mouse left and right with the left knob input
    if(potX < 341){
      Mouse.move(-1, 0, 0);
    }

    if(potX > 682){
      Mouse.move(1, 0, 0);
    }

    //move mouse up and down with the right knob input
    if(potY < 341){
      Mouse.move(0, 1, 0);
    }

    if(potY > 682){
      Mouse.move(0, -1, 0);
    }

    //place the flag puck on the coper tape contact to set the switch to true, and then press right click once
    if (digitalRead(A0)){
      if (rightOnce){
      Mouse.press(MOUSE_RIGHT);
      rightOnce = false;
      delay(50);
      Mouse.release(MOUSE_RIGHT);
      }
    } else {
      rightOnce = true;
      // if (!rightOnce){
      //   Mouse.release(MOUSE_RIGHT);
      //   rightOnce = true;
      //   delay(100);
      // }
    }

    //place the dig puck on the coper tape contact to set the switch to true, and then press left click once
    if (digitalRead(A3)){
      if (leftOnce){
      Mouse.press(MOUSE_LEFT);
      leftOnce = false;
      delay(50);
      Mouse.release(MOUSE_LEFT);
      }
    } else {
      leftOnce = true;
      // if (!leftOnce){
      //   Mouse.release(MOUSE_LEFT);
      //   leftOnce = true;
      //   delay(100);
      // }
    }
  }
}

Video



No comments:

Post a Comment

Note: Only a member of this blog may post a comment.