TinyArcade
#include <stdlib.h>
#include <TinyScreen.h>
// Pin
static const int DIR_X_PIN = 42;
static const int DIR_Y_PIN = 1;
static const int DIR_UP_PIN = 42;
static const int DIR_DOWN_PIN = 19;
static const int DIR_LEFT_PIN = 25;
static const int DIR_RIGHT_PIN = 15;
static const int BUTTON_LEFT_PIN = 45;
static const int BUTTON_RIGHT_PIN = 44;
static const int DIR_THRESHOLD = 250;
TinyScreen tiny_screen = TinyScreen(TinyScreenPlus);
int version = 1;
void setup()
{
tiny_screen.begin();
tiny_screen.setBitDepth(TSBitDepth8);
tiny_screen.setBrightness(8);
tiny_screen.setFont(liberationSansNarrow_12ptFontInfo);
tiny_screen.fontColor(TS_8b_White, TS_8b_Black);
// コントローラー初期化
pinMode(4, INPUT_PULLUP);
if(!digitalRead(4))
{
version = 2;
pinMode(DIR_UP_PIN, INPUT_PULLUP);
pinMode(DIR_DOWN_PIN, INPUT_PULLUP);
pinMode(DIR_LEFT_PIN, INPUT_PULLUP);
pinMode(DIR_RIGHT_PIN, INPUT_PULLUP);
}
pinMode(BUTTON_LEFT_PIN, INPUT_PULLUP);
pinMode(BUTTON_RIGHT_PIN, INPUT_PULLUP);
}
void loop()
{
char text[128];
strcpy(text, "PUSH ");
if(version == 1)
{
int dir_x = analogRead(DIR_X_PIN) - 512;
if(dir_x < -DIR_THRESHOLD)
{
strcat(text, "R ");
}
else if(dir_x > DIR_THRESHOLD)
{
strcat(text, "L ");
}
int dir_y = analogRead(DIR_Y_PIN) - 512;
if(dir_y < -DIR_THRESHOLD)
{
strcat(text, "U ");
}
else if(dir_y > DIR_THRESHOLD)
{
strcat(text, "D ");
}
}
else
{
if(!digitalRead(DIR_UP_PIN))
{
strcat(text, "U ");
}
if(!digitalRead(DIR_DOWN_PIN))
{
strcat(text, "D ");
}
if(!digitalRead(DIR_LEFT_PIN))
{
strcat(text, "L ");
}
if(!digitalRead(DIR_RIGHT_PIN))
{
strcat(text, "R ");
}
}
if(!digitalRead(BUTTON_LEFT_PIN))
{
strcat(text, "1 ");
}
if(!digitalRead(BUTTON_RIGHT_PIN))
{
strcat(text, "2 ");
}
tiny_screen.clearScreen();
tiny_screen.setCursor(0,0);
tiny_screen.print(text);
}