Compare commits
9 Commits
ee5ef7a696
...
hitbox
| Author | SHA1 | Date | |
|---|---|---|---|
| 0218eabc34 | |||
| f413eae2fd | |||
| 9454fdc54e | |||
| 20a25ecf26 | |||
| dbff5cf2ac | |||
| 6ab58857c7 | |||
| 7539e3658a | |||
| 3645548cdf | |||
| ff5aee7c39 |
@@ -1,4 +1,7 @@
|
|||||||
Arduino Pro Micro でコントローラー自作するときのスケッチ
|
Arduino Pro Micro でコントローラー自作するときのスケッチ
|
||||||
=======================================================
|
=======================================================
|
||||||
|
|
||||||
[SwitchControlLibrary](https://github.com/celclow/SwitchControlLibrary) を利用している。
|
## 依存ライブラリ
|
||||||
|
- [SwitchControlLibrary](https://github.com/celclow/SwitchControlLibrary) をフォークし[一部改変したもの](https://git.sirrow.work/sirrow/SwitchControlLibrary)
|
||||||
|
- ArduinoSTL
|
||||||
|
- MsTimer2
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
#include <MsTimer2.h>
|
#include <MsTimer2.h>
|
||||||
#include <SwitchControlLibrary.h>
|
#include <SwitchControlLibrary.h>
|
||||||
|
|
||||||
#define tableSize 40
|
#define RapidFireTableSize 40
|
||||||
|
|
||||||
int loopCount = 0;
|
int loopCount = 0;
|
||||||
int state = 0;
|
int state = 0;
|
||||||
int table[tableSize];
|
int rapidFireTable[RapidFireTableSize];
|
||||||
int index = 0;
|
int index = 0;
|
||||||
|
|
||||||
int val = 1;
|
int val = 1;
|
||||||
@@ -13,7 +13,11 @@ int prevVal = 1;
|
|||||||
|
|
||||||
struct arrow {
|
struct arrow {
|
||||||
int pinNumber;
|
int pinNumber;
|
||||||
int state;
|
int current;
|
||||||
|
int prev;
|
||||||
|
struct arrow *older;
|
||||||
|
struct arrow *newer;
|
||||||
|
Hat arrowSymbol;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ButtonInfo {
|
struct ButtonInfo {
|
||||||
@@ -24,20 +28,28 @@ struct ButtonInfo {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct arrow arrowTable[4];
|
struct arrow arrowTable[4];
|
||||||
|
struct arrow oldestXArrow;
|
||||||
|
struct arrow newestXArrow;
|
||||||
|
struct arrow oldestYArrow;
|
||||||
|
struct arrow newestYArrow;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#define ButtonInfoTableSize 9
|
#define ButtonInfoTableSize 9
|
||||||
struct ButtonInfo buttonInfoTable[ButtonInfoTableSize];
|
struct ButtonInfo buttonInfoTable[ButtonInfoTableSize];
|
||||||
|
|
||||||
|
Hat last = Hat::CENTER;
|
||||||
|
|
||||||
void perms() {
|
void perms() {
|
||||||
if(val == 0){
|
if(val == 0){
|
||||||
if (table[index] == 1){
|
if (rapidFireTable[index] == 1){
|
||||||
SwitchControlLibrary().PressButtonA();
|
SwitchControlLibrary().PressButtonA();
|
||||||
}
|
}
|
||||||
if (table[index] == 2){
|
if (rapidFireTable[index] == 2){
|
||||||
SwitchControlLibrary().ReleaseButtonA();
|
SwitchControlLibrary().ReleaseButtonA();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
index = (index + 1) % 40;
|
index = (index + 1) % RapidFireTableSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -51,12 +63,12 @@ void setupButton(ButtonInfo *but, int pinNumber, Button buttonSymbol) {
|
|||||||
|
|
||||||
void setup()
|
void setup()
|
||||||
{
|
{
|
||||||
table[0] = 1;
|
rapidFireTable[0] = 1;
|
||||||
table[tableSize/2] = 2;
|
rapidFireTable[RapidFireTableSize/2] = 2;
|
||||||
SwitchControlLibrary();
|
SwitchControlLibrary();
|
||||||
|
|
||||||
MsTimer2::set(1, perms);
|
//MsTimer2::set(1, perms);
|
||||||
MsTimer2::start();
|
//MsTimer2::start();
|
||||||
|
|
||||||
setupButton(&(buttonInfoTable[0]), 3, Button::B);
|
setupButton(&(buttonInfoTable[0]), 3, Button::B);
|
||||||
setupButton(&(buttonInfoTable[1]), 4, Button::X);
|
setupButton(&(buttonInfoTable[1]), 4, Button::X);
|
||||||
@@ -71,15 +83,34 @@ void setup()
|
|||||||
pinMode(2, INPUT_PULLUP);
|
pinMode(2, INPUT_PULLUP);
|
||||||
|
|
||||||
arrowTable[0].pinNumber = 6;
|
arrowTable[0].pinNumber = 6;
|
||||||
|
arrowTable[0].arrowSymbol = Hat::TOP;
|
||||||
arrowTable[1].pinNumber = 7;
|
arrowTable[1].pinNumber = 7;
|
||||||
|
arrowTable[1].arrowSymbol = Hat::LEFT;
|
||||||
arrowTable[2].pinNumber = 8;
|
arrowTable[2].pinNumber = 8;
|
||||||
|
arrowTable[2].arrowSymbol = Hat::BOTTOM;
|
||||||
arrowTable[3].pinNumber = 9;
|
arrowTable[3].pinNumber = 9;
|
||||||
|
arrowTable[3].arrowSymbol = Hat::RIGHT;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
for (int i=0; i<4; i++){
|
for (int i=0; i<4; i++){
|
||||||
pinMode(arrowTable[i].pinNumber, INPUT_PULLUP);
|
pinMode(arrowTable[i].pinNumber, INPUT_PULLUP);
|
||||||
arrowTable[i].state = 1;
|
arrowTable[i].older = NULL;
|
||||||
|
arrowTable[i].newer = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
oldestXArrow.older = NULL;
|
||||||
|
oldestXArrow.newer = &newestXArrow;
|
||||||
|
oldestXArrow.arrowSymbol = Hat::CENTER;
|
||||||
|
newestXArrow.older = &oldestXArrow;
|
||||||
|
newestXArrow.newer = NULL;
|
||||||
|
|
||||||
|
oldestYArrow.older = NULL;
|
||||||
|
oldestYArrow.newer = &newestYArrow;
|
||||||
|
oldestYArrow.arrowSymbol = Hat::CENTER;
|
||||||
|
newestYArrow.older = &oldestYArrow;
|
||||||
|
newestYArrow.newer = NULL;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void handleButtonInput(ButtonInfo *but){
|
void handleButtonInput(ButtonInfo *but){
|
||||||
@@ -95,6 +126,13 @@ void handleButtonInput(ButtonInfo *but){
|
|||||||
but->prev = but->current;
|
but->prev = but->current;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void moveHat(Hat dir){
|
||||||
|
if(last != dir){
|
||||||
|
SwitchControlLibrary().MoveHat(static_cast<uint8_t>(dir));
|
||||||
|
last = dir;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void loop()
|
void loop()
|
||||||
{
|
{
|
||||||
val = digitalRead(2);
|
val = digitalRead(2);
|
||||||
@@ -114,23 +152,64 @@ void loop()
|
|||||||
|
|
||||||
|
|
||||||
for (int i=0; i<4; i++){
|
for (int i=0; i<4; i++){
|
||||||
arrowTable[i].state = digitalRead(arrowTable[i].pinNumber);
|
arrowTable[i].current = digitalRead(arrowTable[i].pinNumber);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(arrowTable[0].state == 0){
|
if(arrowTable[1].current == 0){
|
||||||
SwitchControlLibrary().MoveHat(static_cast<uint8_t>(Hat::TOP));
|
if(arrowTable[3].current == 0){
|
||||||
}
|
if(arrowTable[0].current == 0){
|
||||||
else if(arrowTable[2].state == 0){
|
moveHat(Hat::TOP);
|
||||||
SwitchControlLibrary().MoveHat(static_cast<uint8_t>(Hat::BOTTOM));
|
|
||||||
}
|
|
||||||
else if(arrowTable[1].state == 0){
|
|
||||||
SwitchControlLibrary().MoveHat(static_cast<uint8_t>(Hat::LEFT));
|
|
||||||
}
|
|
||||||
else if(arrowTable[3].state == 0){
|
|
||||||
SwitchControlLibrary().MoveHat(static_cast<uint8_t>(Hat::RIGHT));
|
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
SwitchControlLibrary().MoveHat(static_cast<uint8_t>(Hat::CENTER));
|
if(arrowTable[2].current == 0){
|
||||||
|
moveHat(Hat::BOTTOM);
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
moveHat(Hat::CENTER);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
if(arrowTable[0].current == 0){
|
||||||
|
moveHat(Hat::TOP_LEFT);
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
if(arrowTable[2].current == 0){
|
||||||
|
moveHat(Hat::BOTTOM_LEFT);
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
moveHat(Hat::LEFT);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
if(arrowTable[3].current == 0){
|
||||||
|
if(arrowTable[0].current == 0){
|
||||||
|
moveHat(Hat::TOP_RIGHT);
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
if(arrowTable[2].current == 0){
|
||||||
|
moveHat(Hat::BOTTOM_RIGHT);
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
moveHat(Hat::RIGHT);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
if(arrowTable[0].current == 0){
|
||||||
|
moveHat(Hat::TOP);
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
if(arrowTable[2].current == 0){
|
||||||
|
moveHat(Hat::BOTTOM);
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
moveHat(Hat::CENTER);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user