18 April 2022

Final Project: Pokémon Master

 


#include <Keyboard.h>
#include <KeyboardLayout.h>
#include <Adafruit_CircuitPlayground.h>
#include <Adafruit_Circuit_Playground.h>
//Code by Kobe Newland

  // Varaibles

const int debounce = 0;
const int thresh = 500;
int light; 

int leftbutton = 200;
int upbutton = 450;
int downbutton = 600;
int rightbutton = 750;

void setup() {
  CircuitPlayground.begin();
  pinMode(leftbutton, INPUT);
  pinMode(upbutton, INPUT);
  pinMode(downbutton, INPUT);
  pinMode(rightbutton, INPUT);
    Serial.begin(9600);
    pinMode(CPLAY_SLIDESWITCHPIN, INPUT_PULLUP);
    Keyboard.begin();

}

void loop() {
  // put your main code here, to run repeatedly:
  //int pot = analog read a2
  // if pot > 0 && pot < 200
  // if pot > 201 && pot < 500
  // if pot > 501 && pot < 800
  // if pot > 801 && pot < 1023

  //Potentiometer
  //If light = true, select once

  //If turned to the north, move north (270-45)

  //If turned to the west, move west

  //If turned to the south, move south

  //If turned to the east, move east
    int potRead  = analogRead(2);

{
    if (potRead >= 0 && potRead <= leftbutton)
  {
    Keyboard.write('a');
  }

  if (potRead > leftbutton && potRead <= upbutton)
  {
    Keyboard.write('w');
  }

  if (potRead > upbutton && potRead <= rightbutton)
  {
    Keyboard.write('s');
  }

  if (potRead > rightbutton && potRead <= downbutton)
  {
    Keyboard.write('d');
  }
}
  float light = CircuitPlayground.lightSensor();

 if(light >= 50 ){            // if there is light
    Keyboard.press('z');     // press the z key to select
    delay(debounce);
  }  else {                  // if there is no light
    Keyboard.release('z');   // release z to stop
  }

    delay(100);

My project consists of a shoebox painted purple and white with red detailing to imitate the master ball in Pokemon. The goal of this project was to make a controller that allows one to consistently head in one direction while playing pokemon to make things like egg hatching and other menial walking based tasks easier. It consists of a circuit board express, potentiometer, and usb cable primarily. Unfortunately I ran into an issue during development where none of my usbs would work and I lacked access to another computer with Arduino, so unfortunately I lack video evidence, but it did work for a time. 

It is made clear that one has to use the knob attached to the front of the device, although exactly how might not be immediately appearent to everyone. Directions are controlled by moving the knob certain degrees, causing the character to walk infinitely in one direction. A light sensor has also been incorporated into the design. By removing the circle at the top of the box marked with an M, the sensor will detect the light in the room one is playing in, causing it to function as if you pressed a. This means that you can actually play the game and select items in battle as opposed to it being purely a novelty controller which you can only move around in. I am quite proud that I did manage to get it to work for a brief period.

Do you have any solutions for my USB issue?

}

No comments:

Post a Comment

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