This program uses a NUCLEO-F401RE to control an SNES console by sending the button states. (1 = Unpressed, 0 = Pressed) Data, Clock and Latch from the SNES must be connected to the appropriate pins. The NUCLEO is powered by the SNES through E5V. The power jumper should be moved to E5V configuration when powered by SNES.

Dependencies:   mbed

main.cpp

Committer:
kyancey
Date:
2017-10-05
Revision:
0:2af5c09cf1ee
Child:
1:2a346daf070f

File content as of revision 0:2af5c09cf1ee:

#include "mbed.h"


DigitalOut Data(D2);
DigitalIn Latch(D3);
DigitalIn Clock(D4);

void waitUntilHigh(DigitalIn x)
{
    while(x != 1) {};
}

void waitUntilLow(DigitalIn x)
{
    while(x == 1) {};
}

void sendButton(int button)
{
    Data = button;
    waitUntilLow(Clock);
    waitUntilHigh(Clock);
}

void sendButtonsPressed(int b, int y, int select, int start,
                        int up, int down, int left, int right,
                        int a, int x, int l1, int r1)
{
    Data = 1;
    waitUntilHigh(Latch);
    waitUntilLow(Latch);

    sendButton(b);
    sendButton(y);
    sendButton(select);
    sendButton(start);
    sendButton(up);
    sendButton(down);
    sendButton(left);
    sendButton(right);
    sendButton(a);
    sendButton(x);
    sendButton(l1);
    sendButton(r1);
}

int main()
{
    while(1) {
        sendButtonsPressed(1, 1, 1, 1,      //b,y,select,start
                           1, 1, 1, 1,     //up,down,left,right
                           0, 1, 1, 1);    //a,x,l1,r1

        sendButtonsPressed(1, 1, 1, 1,      //b,y,select,start
                           1, 1, 1, 1,     //up,down,left,right
                           1, 1, 1, 1);    //a,x,l1,r1
    }
}