Compare commits
3 Commits
hitbox
...
c3f1842b86
| Author | SHA1 | Date | |
|---|---|---|---|
| c3f1842b86 | |||
| 8261199b9f | |||
| 5e431ffdea |
@@ -1,7 +1,4 @@
|
|||||||
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
|
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
int loopCount = 0;
|
int loopCount = 0;
|
||||||
int state = 0;
|
int state = 0;
|
||||||
int rapidFireTable[RapidFireTableSize];
|
int rapidFireTable[RapidFireTableSize];
|
||||||
|
bool rapidPressState = 0;
|
||||||
int index = 0;
|
int index = 0;
|
||||||
|
|
||||||
int val = 1;
|
int val = 1;
|
||||||
@@ -28,11 +29,8 @@ struct ButtonInfo {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct arrow arrowTable[4];
|
struct arrow arrowTable[4];
|
||||||
struct arrow oldestXArrow;
|
struct arrow oldestArrow;
|
||||||
struct arrow newestXArrow;
|
struct arrow newestArrow;
|
||||||
struct arrow oldestYArrow;
|
|
||||||
struct arrow newestYArrow;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#define ButtonInfoTableSize 9
|
#define ButtonInfoTableSize 9
|
||||||
@@ -44,9 +42,11 @@ void perms() {
|
|||||||
if(val == 0){
|
if(val == 0){
|
||||||
if (rapidFireTable[index] == 1){
|
if (rapidFireTable[index] == 1){
|
||||||
SwitchControlLibrary().PressButtonA();
|
SwitchControlLibrary().PressButtonA();
|
||||||
|
rapidPressState = true;
|
||||||
}
|
}
|
||||||
if (rapidFireTable[index] == 2){
|
if (rapidFireTable[index] == 2){
|
||||||
SwitchControlLibrary().ReleaseButtonA();
|
SwitchControlLibrary().ReleaseButtonA();
|
||||||
|
rapidPressState = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
index = (index + 1) % RapidFireTableSize;
|
index = (index + 1) % RapidFireTableSize;
|
||||||
@@ -67,8 +67,8 @@ void setup()
|
|||||||
rapidFireTable[RapidFireTableSize/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);
|
||||||
@@ -99,18 +99,11 @@ void setup()
|
|||||||
arrowTable[i].newer = NULL;
|
arrowTable[i].newer = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
oldestXArrow.older = NULL;
|
oldestArrow.older = NULL;
|
||||||
oldestXArrow.newer = &newestXArrow;
|
oldestArrow.newer = &newestArrow;
|
||||||
oldestXArrow.arrowSymbol = Hat::CENTER;
|
oldestArrow.arrowSymbol = Hat::CENTER;
|
||||||
newestXArrow.older = &oldestXArrow;
|
newestArrow.older = &oldestArrow;
|
||||||
newestXArrow.newer = NULL;
|
newestArrow.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){
|
||||||
@@ -126,22 +119,18 @@ 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);
|
||||||
if(prevVal == 1 && val == 0){
|
if(prevVal == 1 && val == 0){
|
||||||
SwitchControlLibrary().PressButtonA();
|
SwitchControlLibrary().PressButtonA();
|
||||||
|
rapidPressState = true;
|
||||||
index = 1;
|
index = 1;
|
||||||
}
|
}
|
||||||
else if(prevVal == 0 && val == 1){
|
else if(prevVal == 0 && val == 1){
|
||||||
SwitchControlLibrary().ReleaseButtonA();
|
if(rapidPressState){
|
||||||
|
SwitchControlLibrary().ReleaseButtonA();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
prevVal = val;
|
prevVal = val;
|
||||||
|
|
||||||
@@ -153,63 +142,26 @@ void loop()
|
|||||||
|
|
||||||
for (int i=0; i<4; i++){
|
for (int i=0; i<4; i++){
|
||||||
arrowTable[i].current = digitalRead(arrowTable[i].pinNumber);
|
arrowTable[i].current = digitalRead(arrowTable[i].pinNumber);
|
||||||
|
if(arrowTable[i].prev==1 && arrowTable[i].current==0){
|
||||||
|
// add arrow to the tail of linked list
|
||||||
|
arrowTable[i].older = newestArrow.older;
|
||||||
|
arrowTable[i].newer = &newestArrow;
|
||||||
|
newestArrow.older->newer = &(arrowTable[i]);
|
||||||
|
newestArrow.older = &(arrowTable[i]);
|
||||||
|
}
|
||||||
|
else if (arrowTable[i].prev==0 && arrowTable[i].current==1){
|
||||||
|
arrowTable[i].newer->older = arrowTable[i].older;
|
||||||
|
arrowTable[i].older->newer = arrowTable[i].newer;
|
||||||
|
arrowTable[i].newer = NULL;
|
||||||
|
arrowTable[i].older = NULL;
|
||||||
|
}
|
||||||
|
arrowTable[i].prev = arrowTable[i].current;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(arrowTable[1].current == 0){
|
if(newestArrow.older->arrowSymbol != last){
|
||||||
if(arrowTable[3].current == 0){
|
last = newestArrow.older->arrowSymbol;
|
||||||
if(arrowTable[0].current == 0){
|
SwitchControlLibrary().MoveHat(static_cast<uint8_t>(newestArrow.older->arrowSymbol));
|
||||||
moveHat(Hat::TOP);
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
BIN
panel/20200912.pdf
Normal file
BIN
panel/20200912.pdf
Normal file
Binary file not shown.
211
panel/20200912.svg
Normal file
211
panel/20200912.svg
Normal file
File diff suppressed because one or more lines are too long
|
After Width: | Height: | Size: 1.2 MiB |
BIN
panel/20201101.pdf
Normal file
BIN
panel/20201101.pdf
Normal file
Binary file not shown.
235
panel/20201101.svg
Normal file
235
panel/20201101.svg
Normal file
File diff suppressed because one or more lines are too long
|
After Width: | Height: | Size: 1.2 MiB |
Reference in New Issue
Block a user