ã€ã³ã¹ãã¬ãŒã·ã§ã³ã®æº
ã²ãŒã ã®å±ç€ºäŒã§ã Objects in Spaceã®éçºè ã¯ã巚倧ãªå®å®è¹ã®ã³ãã¯ãããã«ã³ã³ãããŒã©ãŒã眮ããŠã²ãŒã ã®ãã¢ãèŠããŸããã ç §æãã¿ã³ãã¢ããã°ããã€ã¹ãã¹ããŒã¿ã¹ã©ã€ãã€ã³ãžã±ãŒã¿ãŒãã¹ã€ãããªã©ãè¿œå ãããŸãããããã¯ãã²ãŒã ãžã®æ²¡å ¥ã«å€§ããªåœ±é¿ãäžããŸãã
ã²ãŒã ã®ãŠã§ããµã€ãã«ã¯ã Arduinoã®ãã¥ãŒããªã¢ã«ãšãã®ãããªã³ã³ãããŒã©ãŒã®éä¿¡ãããã³ã«ã®èª¬æããããŸã ã
ã²ãŒã ã«ãåããã®ãäœæããã
ãã®äŸã§ã¯ãçŽ40ãã«ãè²»ãããŠãã¬ãŒã·ã³ã°ã·ãã¥ã¬ãŒã¿ãŒã®ã³ãã¯ãããã«çŸããã倧ãããŠéãã¹ã€ãããè¿œå ããŸãã äž»ãªã³ã¹ãã¯ãããã®ã¹ã€ããã«é¢é£ããŠããŸã-åçŽãªã¹ã€ãã/ãã¿ã³ã䜿çšããå ŽåãäŸ¡æ Œã¯ååã«ãªããŸãïŒ ããã¯240ã¯ããã®é»åã«èããããšãã§ããå®éã®æ©åšã§ãããç§ã¯ããã®ãã¡çŽ0.03ã¯ããããåºåããŸããã
èŠåïŒãéãç¯çŽããããšã«ããã®ã§ãããŸããŸãªã³ã³ããŒãã³ã/ããŒã«ãè³Œå ¥ããå®äŸ¡ãªäžåœã®Webãµã€ããžã®ãªã³ã¯ãæ®ããŸãã å®äŸ¡ãªã³ã³ããŒãã³ããè³Œå ¥ããããšã®æ¬ ç¹ã®1ã€ã¯ãããã¥ã¡ã³ãããªãããšãå€ãããšã§ãããã®èšäºã§ã¯ããã®åé¡ã解決ããŸãã
äž»ãªã³ã³ããŒãã³ã
- Arduino Mega2560- $ 9
- ã€ã°ããã·ã§ã³ã¹ã€ããã¬ãŒã·ã³ã°ããã« -$ 26
- æ¥ç¶ã¯ã€ã€ã®æïŒ ããªã¹ãããªã¹ãžã ã ããªã¹ããã¡ã¹ãžããªã©ïŒ-$ 2
泚ç®ã®ããŒã«
- ã¯ãã ããŠïŒ è¯ããã®ãéžã¶äŸ¡å€ããããŸãããä»äºã«å¯ŸåŠããã®ãå®ãã§ã ïŒ
- ã¯ãã ä»ãïŒ ããžã³60/40ãäœ¿çš -ç°å¢ã«æ害ã§ãããäœæ¥ã¯ç°¡åã§ãïŒ
- ç±åçž®ãã¥ãŒã ïŒ ããã³å·¥æ¥çšãã¢ãã©ã€ã€ãŒããã¢ãã©ã€ã€ãŒãã©ã€ã¿ãŒ ïŒãŸãã¯é»æ°ããŒã
- æ¥çå€é ïŒ ããã³ããã ïŒããŸãã¯äœããã®ãšããã·
- ãã«ãã¡ãŒã¿
- ããªãããéãç¯çŽããå¿ èŠãããå Žåã¯ã ã¯ã€ã€ãŒãå¥ãããã®ããããŒ/ãã³ã ããŸãã¯ã¯ãã¿ã
ãœãããŠã§ã¢
- Arduinoããã»ããµãããã°ã©ãã³ã°ããããã®Arduino IDE
- å®éã®ããŒããŠã§ã¢USBã³ã³ãããŒã©ãŒ/ãžã§ã€ã¹ãã£ãã¯ãšããŠè¡šç€ºãããã³ã³ãããŒã©ãŒãäœæããã«ã¯ïŒ
- Arduino USBã³ã³ãããŒã©ãŒã§æ°ãããã¡ãŒã ãŠã§ã¢ããã©ãã·ã¥ããããã®FLIP
- githubã®Arduino-usbã©ã€ãã©ãª
- ã²ãŒã ãçŽæ¥éä¿¡ããïŒ ãŸãã¯ä»®æ³USBã³ã³ãããŒã©ãŒ/ãžã§ã€ã¹ãã£ãã¯ãšããŠè¡šç€ºãããïŒã³ã³ãããŒã©ãŒãäœæããã«ã¯
- GitHubã®ois_protocolã©ã€ãã©ãª
- ã³ã³ãããŒã©ãŒãä»®æ³USBã³ã³ãããŒã©ãŒ/ãžã§ã€ã¹ãã£ãã¯ãšããŠäœ¿çšããå Žåã¯ã VJoyãã©ã€ã㌠ã
- GitHubã®ois_protocolã©ã€ãã©ãª
èŠå
ç§ã¯é«æ ¡ã§é»åå·¥åŠãåŠã³ãã¯ãã ããŠã®äœ¿ãæ¹ãåŠã³ãèµ€ç·ãèµ€ã«æ¥ç¶ããé»ããé»ã«æ¥ç¶ããå¿ èŠãããããšãåŠã³ãŸãã...ãã«ããã¢ã³ãã¢ãæµæãããã³ããããæ¥ç¶ããæ¹çšåŒ-ããã¯ãã¹ãŠãé»åå·¥åŠã®ç§ã®æ£åŒãªèšç·Žãå°œããŸããã
ç§ã«ãšã£ãŠã¯ãã¬ãŒãã³ã°ãããžã§ã¯ãã ã£ãã®ã§ãæªãã¢ããã€ã¹ãééãããããããããŸããïŒ
ããŒã1.ã³ã³ãããŒã©ãŒãçµã¿ç«ãŠãïŒ
ããã¥ã¡ã³ããŒã·ã§ã³ãªãã§ã¹ã€ããã䜿çšããŠããŸã...
äžã§è¿°ã¹ãããã«ãç§ã¯äœããŒãžã³ã®å°å£²æ¥è ããå®ãéšåãè³Œå ¥ããã®ã§ãæåã«ããããšã¯ãããã®ã¹ã€ãã/ãã¿ã³ãã©ã®ããã«æ©èœããããææ¡ããããšã§ãã
ã·ã³ãã«ãªããã·ã¥ãã¿ã³/ã¹ã€ãã
ãã¿ã³ã¯ã·ã³ãã«ã§ã-LEDã¯ãªãã2ã€ã®æ¥ç¹ãããããŸããã ãã«ãã¡ãŒã¿ãŒãé£ç¶ã¢ãŒã/ãã€ã€ã«ã¢ãŒãã«åãæ¿ããŸãïŒ ïŒããã³ç°ãªãæ¥ç¹ã®ãããŒãã«è§ŠããŸã-OLïŒéã«ãŒããéåè·¯ïŒãç»é¢ã«è¡šç€ºãããŸãïŒããã¯ã2ã€ã®ãããŒãéã«æ¥ç¶ããªãããšãæå³ããŸãã 次ã«ããã¿ã³ãæŒããªãããæ¥è§ŠãããŒãã«è§ŠããŸã-0.1Ωã®ãããªãã®ãç»é¢ã«è¡šç€ºããããã«ãã¡ãŒã¿ãŒãããŒãé³ãçºããŸãïŒ ãããŒãéã«éåžžã«äœãæµæãããããšã瀺ããŸã-éåè·¯ ïŒã
ããã§ããã¿ã³ãæŒããšåè·¯ãéããæŒããšéãããšãããããŸããã å³ã§ã¯ãããã¯åçŽãªã¹ã€ãããšããŠèª¬æã§ããŸãã
ã¹ã€ãããArduinoã«æ¥ç¶ããŸã
ArduinoããŒãäžã®2ã€ã®ãã³ãèŠã€ããŸããGNDã©ãã«ãšã2ãã®ã©ãã«ïŒãŸãã¯ãã®ä»ã®ä»»æã®çªå·âãããã¯ãœãããŠã§ã¢ã§å¶åŸ¡ã§ããæ±çšI / Oãã³ã§ãïŒã
ãã®æ¹æ³ã§ã¹ã€ãããæ¥ç¶ããArduinoã«ãã³2ãINPUTãã³ãšããŠèšå®ããããã«åœä»€ãããšãå·ŠåŽã«ç€ºãåè·¯ãåŸãããŸãïŒäžå³ïŒã ãã¿ã³ãæŒããããšããã³2ã¯ã°ã©ã³ã/ 0Vã«çŽæ¥æ¥ç¶ãããæŒããããšããã³2ã¯äœã«ãæ¥ç¶ãããŸããã ãã®ç¶æ ïŒ äœã«ãæ¥ç¶ãããŠããªã ïŒã¯ããããŒãã£ã³ã°ãïŒé«ã€ã³ããŒãã³ã¹ç¶æ ïŒãšåŒã°ããæ®å¿µãªãããããã¯ç§ãã¡ã®ç®çã«ã¯ããŸãé©ããç¶æ ã§ã¯ãããŸããã ãœãããŠã§ã¢ã§é£çµ¡å ããããŒã¿ãèªã¿åããšãïŒ digitalReadïŒ2ïŒãäœ¿çš ïŒãé£çµ¡å ãæ¥å°ãããŠããå Žåã¯LOWã«ãªããé£çµ¡å ããããŒãã£ã³ã°ã®å Žåã¯äºæž¬ã§ããªãçµæïŒLOWãŸãã¯HIGHïŒã«ãªããŸãïŒ
ãããä¿®æ£ããã«ã¯ãæ¥ç¹ãINPUT_PULLUPã¢ãŒãã«èšå®ããŸãããã®ã¢ãŒãã§ã¯ãããã»ããµå ã®æµæåšã«æ¥ç¶ããå³åŽã«ç€ºãåè·¯ãäœæããŸãã ãã®åè·¯ã§ã¯ãã¹ã€ãããéããŠããããããã³2ã®ãã¹ã¯+ 5Vã§ãããããèªã¿åãããå Žåãçµæã¯åžžã«HIGHã«ãªããŸãã ã¹ã€ãããéããŠããæ¥ç¹ã«ã¯+ 5VãŸã§ã®æµæã®é«ãçµè·¯ãšãæ¥å°/ 0Vãžã®æµæã®ãªãçµè·¯ããããããããåã€ããããæ¥ç¹ãèªã¿åããšLOWã«ãªããŸãã
ãœãããŠã§ã¢éçºè ã«ãšã£ãŠã¯ãé åºãéã«ãªã£ãŠããããã«èŠããå ŽåããããŸãããã¿ã³ãã¯ãªãã¯ãããšfalse / LOWãšè¡šç€ºãããæŒãããå Žåã¯true / HIGHãšè¡šç€ºãããŸãã
å察ã®ããšãã§ããŸãããããã»ããµã«ã¯ãã«ã¢ããæµæãçµã¿èŸŒãŸããŠããã ãã§ããã«ããŠã³æµæã¯ãªãããããã®ã¢ãã«ã«åºå·ããŸãã
ã¹ã€ããã®ã¹ããŒã¿ã¹ãèªã¿åãããã®ã¹ããŒã¿ã¹ãPCã«äŒããArduinoã®æãåçŽãªããã°ã©ã ã¯ã次ã®ãããªãã®ã«ãªããŸãã Arduino IDEã®ããŠã³ããŒããã¿ã³ãã¯ãªãã¯ããïŒ[ããŒã«]ã¡ãã¥ãŒã®ïŒã·ãªã¢ã«ã¢ãã¿ãŒãéããŠçµæã確èªã§ããŸãã
void setup() { Serial.begin(9600); pinMode(2, INPUT_PULLUP); } void loop() { int state = digitalRead(pin); Serial.println( state == HIGH ? "Released" : "Pressed" ); delay(100);//artifically reduce the loop rate so the output is at a human readable rate... }
ããã¥ã¡ã³ããã»ãšãã©ãªãä»ã®ã¹ã€ãã...
3ãã³LEDã¹ã€ãã
幞ããªããšã«ãç§ã®ããã«ã®ã¡ã€ã³ã¹ã€ããã«ã¯ã3ã€ã®æ¥ç¹ã®ããŒã¯ããããŸãã
ã©ã®ããã«åäœããã®ãå®å šã«ã¯ããããªãã®ã§ããã«ãã¡ãŒã¿ãŒãé£ç¶ã¢ãŒãã«åãæ¿ããã¹ã€ããããªã³ãšãªãã®ãšãã«ãã¹ãŠã®æ¥ç¹ã«è§ŠããŸã...ãã ããä»åã¯ã[GND]ããã³[+]ãããŒãã«ãã¹ã€ãããªã³ïŒ ãã«ãã¡ãŒã¿ãŒãããŒãé³ã鳎ããïŒ æ¥ç¶ãæ€åºãã ïŒå¯äžã®æ§æã¯ãã¹ã€ãããããªã³ãã§ããããŒãããªã³[+]ããã³[ã©ã³ã]ã®å Žåã§ãã
ã¹ã€ããå ã®LEDã¯å°é枬å®ããããã¯ãããããäžèšã®ãã¹ããããLEDã¯[+]ããã³[ã©ã³ã]æ¥ç¹ã§ã¯ãªã[GND]ãã³ã«çŽæ¥æ¥ç¶ãããŠãããšæ³å®ã§ããŸãã 次ã«ããã«ãã¡ãŒã¿ããã€ãªãŒããã¹ãã¢ãŒãã«åãæ¿ããŸãïŒã·ã³ãã« ïŒæ¥ç¹ã®ãã¢ãå床確èªããŸãããä»åã¯æ¥µæ§ãéèŠã§ãïŒ èµ€ãšé»ã®ãããŒã ïŒã èµ€ããããŒãã[ã©ã³ã]ã«æ¥ç¶ããé»ããããŒãã[GND]ã«æ¥ç¶ãããšãLEDãç¹ç¯ãããã«ãã¡ãŒã¿ãŒã«2.25Vã衚瀺ãããŸãã ããã¯ããã€ãªãŒãã®çŽæµé»å§ããŸãã¯ãã€ãªãŒãããªã³ã«ããã®ã«å¿ èŠãªæå°é»å§ã§ãã ã¹ã€ããã®äœçœ®ã«é¢ä¿ãªãã[ã©ã³ã]ãã[GND]ãžã®2.25Vã§LEDãç¹ç¯ããŸãã èµ€ããããŒãã[+]ã«ãé»ã®ãããŒãã[GND]ã«æ¥ç¶ãããšãLEDã¯ã¹ã€ããããªã³ã®ãšãã®ã¿ç¹ç¯ããŸãã
ãããã®æž¬å®å€ããããã®ã¹ã€ããã®å éšã¯äžã®å³ã®ããã«èŠãããšæ³å®ã§ããŸãã
- [+]ãš[ã©ã³ã]ã¯ãã¹ã€ããããªã³/ã¯ããŒãºã®ãšãã«ç絡ããŸãã
- [ã©ã³ã]ãã[GND]ãžã®æ£é»å§ã¯åžžã«LEDãç¹ç¯ããŸãã
- [+]ãã[GND]ãžã®æ£ã®é»å§ã¯ãã¹ã€ããããªã³/ã¯ããŒãºã®ãšãã«ã®ã¿LEDãç¹ç¯ããŸãã
æ£çŽãªãšãããæµæã®ååšã«ã€ããŠã®ã¿æšæž¬ã§ããŸãã LED 㯠ãäŸçµŠãããé»æµãå¶éããããã«é©åãªæµæåšã«æ¥ç¶ããå¿ èŠããããŸããå¶éããªãå ŽåãLEDã¯ççŒããŸãã ç§ã®ãã®ã¯çãå°œããŸããã§ããããããŠãããã¯æ£ããåããŠããããã§ãã 売ãæã®ãŠã§ããµã€ããã©ãŒã©ã ã§ãæ倧12 VããµããŒãããã€ã³ã¹ããŒã«æžã¿ã®æµæåšã«é¢ããèšäºãèŠã€ããŸãããããã«ãããé©åãªæµæåšã®ãã§ãã¯/èšç®ã«ãããæéãç¯çŽã§ããŸããã
ã¹ã€ãããArduinoã«æ¥ç¶ããŸã
Arduinoã§ã¹ã€ããã䜿çšããæãç°¡åãªæ¹æ³ã¯ã[ã©ã³ã]ãã³ãç¡èŠããããšã§ããArduinoã§[GND]ãGNDã«æ¥ç¶ãã[+]ãçªå·ä»ãArduinoæ¥ç¹ã®1ã€ãããšãã°3ã«æ¥ç¶ããŸãã
ãã³3ãINPUT_PULLUPãšããŠèšå®ãããš ïŒ åã®ãã¿ã³ãšåã ïŒã次ã®çµæãåŸãããŸãã å·Šäžã¯ãArduinoã³ãŒãã§ãdigitalReadïŒ3ïŒããå®è¡ããŠåãåãå€ã瀺ããŠããŸãã
ã¹ã€ããããªã³/ã¯ããŒãºã«ãªããšãLOWãèªã¿åãããLEDãç¹ç¯ããŸãïŒ ãã®æ§æã§ãã®ãããªã¹ã€ããã䜿çšããã«ã¯ããã¿ã³ã®äŸãšåãArduinoã³ãŒãã䜿çšã§ããŸãã
ãã®è§£æ±ºçã®åé¡
Arduinoã«æ¥ç¶ãããšãå®å šãªåè·¯ã¯æ¬¡ã®ããã«ãªããŸãã
ãã ããããã§ã¯ãLEDã®åã«ããå°ããªé»æµå¶éæµæïŒæµæã100Ωã§ãããšä»®å®ïŒã«å ããŠãã¹ã€ãããéãããããšãã«ãLEDãæµããé»æµã®éãããã«æžãããã«ã¢ããæµæã20 kOhmããããšãããããŸãã ããã¯ãåè·¯ã¯æ©èœããŸãããLEDã¯ããã»ã©æãããªãããšãæå³ããŸãã
ãã®ã¹ããŒã ã®ãã1ã€ã®æ¬ ç¹ã¯ãLEDããœãããŠã§ã¢ã§å¶åŸ¡ã§ããªãããšã§ããã¹ã€ããããªã³ã«ãªããšãªã³ã«ãªããå察ã®å Žåã¯ç¡å¹ã«ãªããŸãã
[lamp]ãã³ã0VãŸãã¯+ 5Vã«æ¥ç¶ãããšã©ããªããããããŸãã
[ã©ã³ã]ã0Vã«æ¥ç¶ãããŠããå ŽåãLEDã¯åžžã«æ¶ç¯ãïŒ ã¹ã€ããã®äœçœ®ã«é¢ä¿ãªã ïŒãArduinoã®äœçœ®èªèã¯åŒãç¶ãå®è¡ãããŸãã ããã«ãããããã°ã©ã ã§LEDãç¡å¹ã«ããããšãã§ããŸãïŒ
[ã©ã³ã]ã+ 5Vã«æ¥ç¶ãããŠããå ŽåãLEDã¯åžžã«ç¹ç¯ããŠããŸãïŒ ã¹ã€ããã®äœçœ®ã«é¢ä¿ãªã ïŒããArduinoã®äœçœ®ã®èªèã¯å£ããŠããŸã-HIGHã¯åžžã«æ¥ç¹ããèªã¿åãããŸãã
ãã®ã¹ã€ãããArduinoã«æ£ããæ¥ç¶ããŸã
ããå€ãã®ã³ãŒããèšè¿°ããããšã§ãäžèšã®å¶éïŒ LEDã®äœé»æµ/èŒåºŠãšLEDã®ããã°ã©ã å¶åŸ¡ã®æ¬ åŠïŒãå æã§ããŸãïŒ LEDãå¶åŸ¡ããæ©èœãšãããã«ããç Žæããäœçœ®èªèãšã®éã®ç«¶åã解決ããããã«ã2ã€ã®ã¿ã¹ã¯ãæéçã«åé¢ããããšãã§ããŸããã€ãŸããã»ã³ãµãŒã³ã³ã¿ã¯ããèªã¿åããšãã«LEDãäžæçã«ãªãã«ããŸãïŒ3ïŒã
ãŸãã[ã©ã³ã]ãã³ãå¥ã®æ±çšArduinoãã³ïŒ4ãªã©ïŒã«æ¥ç¶ããŠãã©ã³ããå¶åŸ¡ã§ããããã«ããŸãã
ã¹ã€ããã®äœçœ®ãæ£ããèªã¿åããLEDãå¶åŸ¡ããïŒç¹æ» ãããïŒããã°ã©ã ãäœæããã«ã¯ãã¹ã€ããã®ç¶æ ãèªã¿åãåã«LEDããªãã«ããã ãã§ãã LEDã¯ãããæ°ããªç§ã§ãªãã«ãªããããã¡ãã€ãã¯ç®ç«ããªãã¯ãã§ãã
int pinSwitch = 3; int pinLed = 4; void setup() { //connect to the PC Serial.begin(9600); //connect our switch's [+] connector to a digital sensor, and to +5V through a large resistor pinMode(pinSwitch, INPUT_PULLUP); //connect our switch's [lamp] connector to 0V or +5V directly pinMode(pinLed, OUTPUT); } void loop() { int lampOn = (millis()>>8)&1;//make a variable that alternates between 0 and 1 over time digitalWrite(pinLed, LOW);//connect our [lamp] to +0V so the read is clean int state = digitalRead(pinSwitch); if( lampOn ) digitalWrite(pinLed, HIGH);//connect our [lamp] to +5V Serial.println(state);//report the switch state to the PC }
Arduino Megaã§ã¯ããã³2-13ããã³44-46ã¯analogWriteé¢æ°ã䜿çšã§ããŸãããã®é¢æ°ã¯å®éã«ã¯0Vãã+ 5Vã®é»å§ãçæãããæ¹åœ¢æ³¢ã䜿çšããŠè¿äŒŒããŸãã å¿ èŠã«å¿ããŠãLEDã®èŒåºŠãå¶åŸ¡ããããã«äœ¿çšã§ããŸãïŒ ãã®ã³ãŒãã¯ãã¡ãã€ãã ãã§ãªããå ãèåãããŸãã
void loop() { int lampState = (millis()>>1)&0xFF;//make a variable that alternates between 0 and 255 over time digitalWrite(pinLed, LOW);//connect our [lamp] to +0V so the read is clean int state = digitalRead(pinSwitch); if( lampState > 0 ) analogWrite(pinLed, lampState); }
çµã¿ç«ãŠã®ãã³ã
æçš¿ã¯æ¢ã«ããªã倧ããã®ã§ãã¯ãã ä»ãã®ãã¥ãŒããªã¢ã«ã¯è¿œå ããŸãããã°ãŒã°ã«ã§æ€çŽ¢ã§ããŸãïŒ
ãã ããæãåºæ¬çãªãã³ãã瀺ããŸãã
- 倧ããªéå±æ¥ç¹ã§ã¯ã€ã€ãæ¥ç¶ããå ŽåããŸãã¯ãã ããŠãç±ãããšã確èªããéå±æ¥ç¹ããã°ããå ç±ããŸãã ã¯ãã ä»ãã®æå³ã¯ãåéãäœæããŠæä¹
çãªæ¥ç¶ã圢æããããšã§ãããæ¥ç¶ã®äžéšã®ã¿ãç±ããªã£ãŠããå Žåãæ¥ç¶ã®ããã«èŠãããå®éã«ã¯æ¥ç¶ãããŠããªããã³ãŒã«ãæ¥ç¶ããç°¡åã«ååŸã§ããŸãã
- 2æ¬ã®ã¯ã€ã€ãæ¥ç¶ããå Žåã æåã«1æ¬ã®ç±åçž®ãã¥ãŒããè£
çããŸãããã¥ãŒããæ¥ç¶ããåŸãè£
çããããšã¯ã§ããŸããã åœããåã®ããã«æããŸãããç§ã¯åžžã«ãããå¿ããŠããããã¥ãŒãã®ä»£ããã«é»æ°ããŒãã䜿çšããå¿
èŠããããŸã...ç±åçž®ãã¥ãŒããæ¥ç¶ããåŒãé¢ããäºåã«ç±ããªããªãããã«ããŸãã ã¯ãã æ¥ç¶ã確èªããåŸããã¥ãŒãããã®äžã«ã¹ã©ã€ããããŠå ç±ããŸãã
- åé ã§è¿°ã¹ã现ãå°ããªæ¥ç¶ç·ã¯ãã¯ãã ä»ããããŠããªãæ¥ç¶ïŒArduinoã«æ¥ç¶ããå Žåãªã©ïŒã«é©ããŠããŸãããå£ããããã§ãã ã¯ãã ä»ãåŸãæ¥çå€éã䜿çšããŠããããåºå®ããæ¥ç¶èªäœãããã¹ãŠã®å¿åãåãé€ããŸãã ããšãã°ãäžã®åçã®èµ€ãç·ã¯ãåäœäžã«èª€ã£ãŠåŒã£åŒµãããå¯èœæ§ããããããã¯ãã ä»ãããåŸãç±ãæ¥çå€ã®æ»Žã§åºå®ããŸããïŒ
ããŒã2.ããã€ã¹ãã²ãŒã ã³ã³ãããŒã©ãŒã«å€ããŸãïŒ
OSãããã€ã¹ãUSBã²ãŒãã³ã°ã³ã³ãããŒã©ãŒãšããŠèªèããããã«ã¯ãããªãåçŽãªã³ãŒããå¿ èŠã§ãããæ®å¿µãªãããArduino USBããããã¡ãŒã ãŠã§ã¢ãå¥ã®ãã®ã«çœ®ãæããå¿ èŠããããŸããããã¯ã https ïŒ //github.com/harlequin-tech/arduino-usb ã
ãããããã®ãã¡ãŒã ãŠã§ã¢ãArduinoã«ã¢ããããŒããããšãããã€ã¹ã¯USBãžã§ã€ã¹ãã£ãã¯ã«ãªããArduinoã§ãªããªããŸãã ãããã£ãŠãåããã°ã©ãã³ã°ããã«ã¯ãå ã®Arduinoãã¡ãŒã ãŠã§ã¢ãåãã©ãã·ã¥ããå¿ èŠããããŸãã ãããã®å埩ã¯éåžžã«èŠçã§ã-Arduinoã³ãŒããããŒããããžã§ã€ã¹ãã£ãã¯ãã¡ãŒã ãŠã§ã¢ããã©ãã·ã¥ãããã¹ãããarduinoãã¡ãŒã ãŠã§ã¢ããã©ãã·ã¥ããç¹°ãè¿ããŸã...
ãã®ãã¡ãŒã ãŠã§ã¢ã§äœ¿çšã§ããArduinoã®ããã°ã©ã ã®äŸã以äžã«ç€ºããŸã-å ¥åãšããŠ3ã€ã®ãã¿ã³ãæ§æãããããã®å€ãèªã¿åããå€ããã®ãã¡ãŒã ãŠã§ã¢ãäºæããããŒã¿æ§é ã«ã³ããŒããŠãããããŒã¿ãéä¿¡ããŸãã æŽãæµããŠãç³é¹žã§ãç¹°ãè¿ããŸãã
// define DEBUG if you want to inspect the output in the Serial Monitor // don't define DEBUG if you're ready to use the custom firmware #define DEBUG //Say we've got three buttons, connected to GND and pins 2/3/4 int pinButton1 = 2; int pinButton2 = 3; int pinButton3 = 4; void setup() { //configure our button's pins properly pinMode(pinButton1, INPUT_PULLUP); pinMode(pinButton2, INPUT_PULLUP); pinMode(pinButton3, INPUT_PULLUP); #if defined DEBUG Serial.begin(9600); #else Serial.begin(115200);//The data rate expected by the custom USB firmware delay(200); #endif } //The structure expected by the custom USB firmware #define NUM_BUTTONS 40 #define NUM_AXES 8 // 8 axes, X, Y, Z, etc typedef struct joyReport_t { int16_t axis[NUM_AXES]; uint8_t button[(NUM_BUTTONS+7)/8]; // 8 buttons per byte } joyReport_t; void sendJoyReport(struct joyReport_t *report) { #ifndef DEBUG Serial.write((uint8_t *)report, sizeof(joyReport_t));//send our data to the custom USB firmware #else // dump human readable output for debugging for (uint8_t ind=0; ind<NUM_AXES; ind++) { Serial.print("axis["); Serial.print(ind); Serial.print("]= "); Serial.print(report->axis[ind]); Serial.print(" "); } Serial.println(); for (uint8_t ind=0; ind<NUM_BUTTONS/8; ind++) { Serial.print("button["); Serial.print(ind); Serial.print("]= "); Serial.print(report->button[ind], HEX); Serial.print(" "); } Serial.println(); #endif } joyReport_t joyReport = {}; void loop() { //check if our buttons are pressed: bool button1 = LOW == digitalRead( pinButton1 ); bool button2 = LOW == digitalRead( pinButton2 ); bool button3 = LOW == digitalRead( pinButton3 ); //write the data into the structure joyReport.button[0] = (button1?0x01:0) | (button2?0x02:0) | (button3?0x03:0); //send it to the firmware sendJoyReport(joyReport) }
ããŒã3.ããã€ã¹ãç¬èªã®ã²ãŒã ã«çµ±åããŸãïŒ
ããã€ã¹ã察話ããã²ãŒã ãå¶åŸ¡ã§ããå Žåã¯ã代æ¿æ段ãšããŠã³ã³ãããŒã©ãŒãšçŽæ¥éä¿¡ã§ããŸã-ãžã§ã€ã¹ãã£ãã¯ãšããŠOSã«è¡šç€ºããå¿ èŠã¯ãããŸããïŒ æçš¿ã®åé ã§ãObjects In Spaceã«ã€ããŠèšåããŸããã ããã¯ãéçºè ã䜿çšããã¢ãããŒãã§ãã 圌ãã¯ãã³ã³ãããŒã©ãŒãšã²ãŒã ãäºãã«éä¿¡ã§ããããã«ããåçŽãªASCIIéä¿¡ãããã³ã«ãäœæããŸããã ã·ã¹ãã ã®ã·ãªã¢ã«ããŒãïŒ Windowsã®COMããŒãã§ããã¡ãªã¿ã«ã Cã§èŠãç®ãã²ã©ãã§ãïŒããªã¹ããããArduinoããšããããã€ã¹ãæ¥ç¶ãããŠããããŒããèŠã€ãããã®ãªã³ã¯ããASCIIã®èªã¿åã/æžã蟌ã¿ãéå§ããã ãã§ååã§ãã
ArduinoåŽã§ã¯ãäžèšã®äŸã§äœ¿çšãããSerial.printé¢æ°ã䜿çšããŸãã
ãã®æçš¿ã®åé ã§ããã®åé¡ã解決ããããã®ã©ã€ãã©ãªhttps://github.com/hodgman/ois_protocolã«ã€ããŠãèšåããŸããã
ã²ãŒã ã«çµ±åããŠããµãŒããŒããšããŠäœ¿çšã§ããC ++ã³ãŒããšãã³ã³ãããŒã©ãŒã§å®è¡ããŠãã¯ã©ã€ã¢ã³ãããšããŠäœ¿çšã§ããArduinoã³ãŒããå«ãŸããŠããŸãã
Arduinoãã«ã¹ã¿ãã€ãºãã
example_hardware.hã§ã¯ãåã ã®ãã¿ã³/ã©ãžãªãã¿ã³ãæœè±¡åããã¯ã©ã¹ãäœæããŸããã ããšãã°ããSwitchãã¯æåã®äŸã®ã·ã³ãã«ãªãã¿ã³ã§ãããLedSwitch2Pinãã¯ã2çªç®ã®äŸã®LEDãå¶åŸ¡ãããã¹ã€ããã§ãã
ãã¿ã³ããŒã®ãµã³ãã«ã³ãŒãã¯example.inoã«ãããŸã ã
å°ããªäŸãšããŠãã²ãŒã ã«éä¿¡ããå¿ èŠã®ãããã¿ã³ã1ã€ãšãã²ãŒã ã«ãã£ãŠå¶åŸ¡ããã1ã€ã®LEDããããšä»®å®ããŸãã å¿ èŠãªArduinoã³ãŒãã¯æ¬¡ã®ããã«ãªããŸãã
#include "ois_protocol.h" //instantiate the library OisState ois; //inputs are values that the game will send to the controller struct { OisNumericInput myLedInput{"Lamp", Number}; } inputs; //outputs are values the controller will send to the game struct { OisNumericOutput myButtonOutput{"Button", Boolean}; } outputs; //commands are named events that the controller will send to the game struct { OisCommand quitCommand{"Quit"}; } commands; int pinButton = 2; int pinLed = 3; void setup() { ois_setup_structs(ois, "My Controller", 1337, 42, commands, inputs, outputs); pinMode(pinButton, INPUT_PULLUP); pinMode(pinLed, OUTPUT); } void loop() { //read our button, send it to the game: bool buttonPressed = LOW == digitalRead(pin); ois_set(ois, outputs.myButtonOutput, buttonPressed); //read the LED value from the game, write it to the LED pin: analogWrite(pinLed, inputs.myLedInput.value); //example command / event: if( millis() > 60 * 1000 )//if 60 seconds has passed, tell the game to quit ois_execute(ois, commands.quitCommand); //run the library code (communicates with the game) ois_loop(ois); }
ã²ãŒã ãã«ã¹ã¿ãã€ãºãã
ã²ãŒã ã³ãŒãã¯ãã·ã³ã°ã«ããããŒãã®ã¹ã¿ã€ã«ã§èšè¿°ãããŠããŸãã ã©ã€ãã©ãªãã€ã³ããŒãããã«ã¯ãã²ãŒã ã«oisdevice.hãå«ããŸãã
åäžã®CPPãã¡ã€ã«ã§ãïŒincludeããããŒãå®è¡ããåã«ãïŒdefine OIS_DEVICE_IMPLããã³#define OIS_SERIALPORT_IMPLãèšè¿°ããŸããããã«ãããã¯ã©ã¹ã®ãœãŒã¹ã³ãŒããCPPãã¡ã€ã«ã«è¿œå ãããŸãã ç¬èªã®ã¹ããŒãã¡ã³ãããã®ã³ã°ãæååããŸãã¯ãã¯ã¿ãŒãããå Žåããšã³ãžã³ã®æ©èœãå©çšããããã«ããããŒãã€ã³ããŒãããåã«å®çŸ©ã§ããä»ã®OIS_ *ãã¯ããããã€ããããŸãã
COMããŒãããªã¹ãããç¹å®ã®ããã€ã¹ãšã®æ¥ç¶ãäœæããã«ã¯ã次ã®ã³ãŒãã䜿çšã§ããŸãã
OIS_PORT_LIST portList; OIS_STRING_BUILDER sb; SerialPort::EnumerateSerialPorts(portList, sb, -1); for( auto it = portList.begin(); it != portList.end(); ++it ) { std::string label = it->name + '(' + it->path + ')'; if( /*device selection choice*/ ) { int gameVersion = 1; OisDevice* device = new OisDevice(it->id, it->path, it->name, gameVersion, "Game Title"); ... } }
OisDeviceã€ã³ã¹ã¿ã³ã¹ãåãåã£ããããã®Pollã¡ã³ããŒé¢æ°ãå®æçã«åŒã³åºãå¿ èŠããããŸãïŒããšãã°ãåãã¬ãŒã ã§ïŒãDeviceOutputsïŒïŒã䜿çšããŠã³ã³ãããŒã©ãŒåºåã®çŸåšã®ç¶æ ãååŸããPopEventsïŒïŒã䜿çšããŠããã€ã¹ã€ãã³ãã䜿çšããSetInputïŒïŒã䜿çšããŠããã€ã¹ã«å€ãéä¿¡ã§ããŸãã
ããããã¹ãŠå®è¡ããã¢ããªã±ãŒã·ã§ã³ã®äŸã¯ã example_ois2vjoy / main.cppã«ãããŸãã
ããŒã4.ããŒã2ãš3ãåæã«äœ¿çšããå Žåã¯ã©ããªããŸããïŒ
ã³ã³ãããŒã©ãä»ã®ã²ãŒã ïŒããŒã2ïŒã§åäœãããã«ã¯ãç¬èªã®ãã¡ãŒã ãŠã§ã¢ãš1ã€ã®Arduinoããã°ã©ã ãã€ã³ã¹ããŒã«ããå¿ èŠããããŸãããã²ãŒã ã§ã³ã³ãããŒã©ãå®å šã«ããã°ã©ã ããã«ã¯ãæšæºã®Arduinoãã¡ãŒã ãŠã§ã¢ãšå¥ã®Arduinoããã°ã©ã ã䜿çšããŸããã ããããäž¡æ¹ã®å¯èœæ§ãåæã«æã¡ããå Žåã¯ã©ãã§ããããïŒ
äžèšã®ãªã³ã¯ãæäŸãããµã³ãã«ã¢ããªã±ãŒã·ã§ã³ïŒ ois2vjoy ïŒã¯ããã®åé¡ã解決ããŸãã
ãã®ã¢ããªã±ãŒã·ã§ã³ã¯OISããã€ã¹ïŒããŒã3ã®ããã°ã©ã ïŒãšéä¿¡ããPCã§ãã®ããŒã¿ãéåžžã®ã³ã³ãããŒã©ãŒ/ãžã§ã€ã¹ãã£ãã¯ããŒã¿ã«å€æãã ä»®æ³ã³ã³ãããŒã©ãŒ/ãžã§ã€ã¹ãã£ãã¯ããã€ã¹ã«è»¢éããŸãã ããã¯ãã³ã³ãããŒã©ãŒãåžžã«OISã©ã€ãã©ãªã䜿çšã§ããããã«ããããšãæå³ããŸãïŒä»ã®ãã¡ãŒã ãŠã§ã¢ã¯å¿ èŠãããŸããïŒãéåžžã®ã³ã³ãããŒã©ãŒ/ãžã§ã€ã¹ãã£ãã¯ãšããŠäœ¿çšããå Žåã¯ãå€æãå®è¡ããPCã§ois2vjoyã¢ããªã±ãŒã·ã§ã³ãå®è¡ããã ãã§ãã
ããŒã5.å®äº
誰ãããã®èšäºã圹ã«ç«ã€ãé¢çœããšæã£ãããšãé¡ã£ãŠããŸãã æåŸãŸã§èªãã§ãããŠããããšãïŒ
èå³ãããã°ã ois_protocolã©ã€ãã©ãªã®éçºã«åå ããŠãã ããã ã²ãŒã å ã®ããããçš®é¡ã®èªå®¶è£œã³ã³ãããŒã©ãŒããµããŒãããåäžã®ãããã³ã«ãéçºããã²ãŒã ãèªå®¶è£œã³ã³ãããŒã©ãŒãçŽæ¥ãµããŒãããããšã奚å±ããããšã¯çŽ æŽãããããšã ãšæããŸãïŒ