Code Monkey home page Code Monkey logo

k15_nespad's Introduction

k15_nespad

Single Header library for interacting with a Nintendo Entertainment System controller using an Arduino microcontroller.

What problem is this library trying to solve? (ELI5)

This library can be used to get informations about what buttons are pressed on a connected NES controller pad. You can use this to control your Arduino projects using one or many NES controller.

How do I add this library to my project?

This library is a single header library which means that you just have to #include it into your project. However, you have to add the implementation of the functions used into one of your C/CPP/INO files. To do this you have to add #define K15_NESPAD_IMPLEMENTATION before the #include. e.g: #define K15_NESPAD_IMPLEMENTATION #include "K15_NESPad.h" in ONE of you C/CPP/INO files.

How does this library work?

This library uses 3 pins to interact with any given NES controller. 2 pins are used for output (latch and pulse) and 1 pin is used as input (data). I implemented this library following the great article from Tresi Avrizo about how the controller works. The article can be found using this link: http://www.mit.edu/~tarvizo/nes-controller.html

Basically the library sends several signals via the pulse pin to prompt the controller to send signals via the data pin which indicates whether a given button has been pressed or not. For any series of pulse signals, a latch signal has to be sent first.

What pins can I use on my Arduino?

The pins for the latch, data and pulse signal have to be digital pins.

Example Usage

  K15_NESPad nesPad;

  void setup()
  {
    //Setup the library.
    //pulePin, latchPin and dataPin are all digital pins.
    int pulsePin = 8;
    int latchPin = 7;
    int dataPin = 12;
    K15_NESInitPad(&nesPad, pulsePin, dataPin, latchPin);

    //Intial Serial Monitor so we can use Serial.println
    Serial.begin(9600);
  }

  void loop()
  {
    //Get the button state from the controller
    K15_NESPollButtons(&pad);

    //Check which buttons have been pressed
    if (K15_NESButtonPressed(&pad, K15_NESPadButton_A))
      Serial.println("A pressed!");
    if (K15_NESButtonPressed(&pad, K15_NESPadButton_B))
      Serial.println("B pressed!");
    if (K15_NESButtonPressed(&pad, K15_NESPadButton_Start))
      Serial.println("Start pressed!");
    if (K15_NESButtonPressed(&pad, K15_NESPadButton_Select))
      Serial.println("Select pressed!");
    if (K15_NESButtonPressed(&pad, K15_NESPadButton_Left))
      Serial.println("Left pressed!");
    if (K15_NESButtonPressed(&pad, K15_NESPadButton_Right))
      Serial.println("Right pressed!");
    if (K15_NESButtonPressed(&pad, K15_NESPadButton_Up))
      Serial.println("Up pressed!");
    if (K15_NESButtonPressed(&pad, K15_NESPadButton_Down))
      Serial.println("Down pressed!");
  }

License

This software is in the public domain. Where that dedication is not recognized, you are granted a perpetual, irrevocable license to copy and modify this file however you want.

k15_nespad's People

Contributors

felixk15 avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.