Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 0218eabc34 | |||
| f413eae2fd | |||
| 9454fdc54e | |||
| 20a25ecf26 | |||
| dbff5cf2ac | |||
| 6ab58857c7 | |||
| 7539e3658a |
@@ -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
|
||||||
|
|||||||
@@ -28,13 +28,17 @@ struct ButtonInfo {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct arrow arrowTable[4];
|
struct arrow arrowTable[4];
|
||||||
struct arrow oldestArrow;
|
struct arrow oldestXArrow;
|
||||||
struct arrow newestArrow;
|
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){
|
||||||
@@ -63,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);
|
||||||
@@ -95,11 +99,17 @@ void setup()
|
|||||||
arrowTable[i].newer = NULL;
|
arrowTable[i].newer = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
oldestArrow.older = NULL;
|
oldestXArrow.older = NULL;
|
||||||
oldestArrow.newer = &newestArrow;
|
oldestXArrow.newer = &newestXArrow;
|
||||||
oldestArrow.arrowSymbol = Hat::CENTER;
|
oldestXArrow.arrowSymbol = Hat::CENTER;
|
||||||
newestArrow.older = &oldestArrow;
|
newestXArrow.older = &oldestXArrow;
|
||||||
newestArrow.newer = NULL;
|
newestXArrow.newer = NULL;
|
||||||
|
|
||||||
|
oldestYArrow.older = NULL;
|
||||||
|
oldestYArrow.newer = &newestYArrow;
|
||||||
|
oldestYArrow.arrowSymbol = Hat::CENTER;
|
||||||
|
newestYArrow.older = &oldestYArrow;
|
||||||
|
newestYArrow.newer = NULL;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -116,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);
|
||||||
@@ -136,24 +153,63 @@ 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;
|
if(arrowTable[1].current == 0){
|
||||||
arrowTable[i].newer = &newestArrow;
|
if(arrowTable[3].current == 0){
|
||||||
newestArrow.older->newer = &(arrowTable[i]);
|
if(arrowTable[0].current == 0){
|
||||||
newestArrow.older = &(arrowTable[i]);
|
moveHat(Hat::TOP);
|
||||||
}
|
}
|
||||||
else if (arrowTable[i].prev==0 && arrowTable[i].current==1){
|
else{
|
||||||
arrowTable[i].newer->older = arrowTable[i].older;
|
if(arrowTable[2].current == 0){
|
||||||
arrowTable[i].older->newer = arrowTable[i].newer;
|
moveHat(Hat::BOTTOM);
|
||||||
arrowTable[i].newer = NULL;
|
}
|
||||||
arrowTable[i].older = NULL;
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
arrowTable[i].prev = arrowTable[i].current;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
SwitchControlLibrary().MoveHat(static_cast<uint8_t>(newestArrow.older->arrowSymbol));
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user