ユーザ用ツール

サイト用ツール


dsshieldauto

差分

このページの2つのバージョン間の差分を表示します。

この比較画面へのリンク

両方とも前のリビジョン前のリビジョン
次のリビジョン
前のリビジョン
次のリビジョン両方とも次のリビジョン
dsshieldauto [2018/01/21 10:06] yaasandsshieldauto [2018/01/27 07:49] – [アドレス3車両のファンクション操作] yaasan
行 130: 行 130:
 void user_program(void) void user_program(void)
 { {
- SerialDS.println("Power On");+ Serial.println("Power On");
  CMD_Power(1);  CMD_Power(1);
   
行 137: 行 137:
  CMD_Wait(500);  CMD_Wait(500);
   
- SerialDS.println("Loc 3, Func 10, On");+ Serial.println("Loc 3, Func 10, On");
  CMD_LocFunction(ADDR_DCC + 3, 10, 1);  CMD_LocFunction(ADDR_DCC + 3, 10, 1);
   
  CMD_Wait(500);  CMD_Wait(500);
   
- SerialDS.println("Loc 3, Func 11, On");+ Serial.println("Loc 3, Func 11, On");
  CMD_LocFunction(ADDR_DCC + 3, 11, 1);  CMD_LocFunction(ADDR_DCC + 3, 11, 1);
   
  CMD_Wait(500);  CMD_Wait(500);
   
- SerialDS.println("Loc 3, Func 9, On");+ Serial.println("Loc 3, Func 9, On");
  CMD_LocFunction(ADDR_DCC + 3, 9, 1);  CMD_LocFunction(ADDR_DCC + 3, 9, 1);
   
  CMD_Wait(500);  CMD_Wait(500);
   
- SerialDS.println("End...");+ Serial.println("End...");
  /* 永久ループ(終了) */  /* 永久ループ(終了) */
  while(1){}  while(1){}
行 217: 行 217:
 Youtube動画:\\  Youtube動画:\\ 
 {{youtube>JmZzkg3p--U?medium}} {{youtube>JmZzkg3p--U?medium}}
 +
 +
 +==== メルクリン車両の単純往復シャトル運転 ====
 +
 +メルクリン車両(Marklin Digital, Marklin Motorola 2)の往復シャトル運転です。
 +ファンクション操作や、ボタンでスタートをかけるなどの動きを実現しています。
 +
 +
 +<code>
 +/*****************************************************************/
 +/*  User Program Area                                            */
 +/*****************************************************************/
 +
 +void user_init(void)
 +{
 +
 + pinMode(8, INPUT);
 + pinMode(11, INPUT);
 + pinMode(12, INPUT);
 +
 + digitalWrite(8, HIGH);//内部プルアップON
 + digitalWrite(11, HIGH);//内部プルアップON
 + digitalWrite(12, HIGH);//内部プルアップON
 +
 + //F0 Light ON
 + CMD_LocFunction(ADDR_MM2 + 2, 0, 1);
 +
 + //SPEED 0
 + CMD_LocSpeed(ADDR_MM2 + 2, 0);
 +
 + //POWER ON
 + CMD_Power(1);
 + Serial.println("Power On");
 +}
 +
 +
 +void user_program(void)
 +{
 + static byte sButtonState = 1;
 +
 +
 + //ボタンが押されたとき、digitalReadは0を返す。押さないときは1を返す。
 +
 + if( digitalRead(8) == 0)
 + {
 + Serial.println("Button 1");
 +
 + sButtonState = 1;
 + CMD_Wait(100);
 +
 + /* 前進 */
 + //FWD
 + CMD_LocDirection(ADDR_MM2 + 2, 0);
 +
 + //警笛
 + CMD_LocFunction(ADDR_MM2 + 2, 2, 1);
 + CMD_Wait(2000);
 + CMD_LocFunction(ADDR_MM2 + 2, 2, 0);
 +
 + //急加速
 + CMD_LocSpeed(ADDR_MM2 + 2, 100);
 + }
 +
 + if( digitalRead(11) == 0)
 + {
 + Serial.println("Button 2");
 +
 + sButtonState = 2;
 + CMD_Wait(100);
 + //急停車
 + CMD_LocSpeed(ADDR_MM2 + 2, 100);
 + }
 +
 + if( digitalRead(12) == 0)
 + {
 + Serial.println("Button 3");
 +
 + sButtonState = 3;
 + CMD_Wait(100);
 + }
 +
 + /* S88のスキャン */
 + CMD_ScanS88();
 +
 +
 + if( CMD_GetS88(0) == 1)
 + {
 + Serial.println("S88 Detected");
 +
 + CMD_LocSpeed(ADDR_MM2 + 2, 100);
 + CMD_Wait(500);
 + CMD_LocSpeed(ADDR_MM2 + 2, 75);
 + CMD_Wait(500);
 + CMD_LocSpeed(ADDR_MM2 + 2, 50);
 + CMD_Wait(500);
 + CMD_LocSpeed(ADDR_MM2 + 2, 25);
 + CMD_Wait(500);
 + CMD_LocSpeed(ADDR_MM2 + 2, 0);
 + CMD_Wait(1000);
 +
 + //REV
 + CMD_LocDirection(ADDR_MM2 + 2, 1);
 + Serial.println("REV");
 +
 + //警笛
 + CMD_LocFunction(ADDR_MM2 + 2, 2, 1);
 + CMD_Wait(2000);
 + CMD_LocFunction(ADDR_MM2 + 2, 2, 0);
 +
 + /* 加速 */
 + CMD_LocSpeed(ADDR_MM2 + 2, 25);
 + CMD_Wait(1000);
 + CMD_LocSpeed(ADDR_MM2 + 2, 50);
 + CMD_Wait(1000);
 + CMD_LocSpeed(ADDR_MM2 + 2, 75);
 + CMD_Wait(1000);
 + CMD_LocSpeed(ADDR_MM2 + 2, 100);
 + CMD_Wait(3000);
 +
 + CMD_LocFunction(ADDR_MM2 + 2, 3, 1);
 + CMD_Wait(2000);
 + CMD_LocFunction(ADDR_MM2 + 2, 3, 0);
 +
 + /* 減速 */
 + CMD_LocSpeed(ADDR_MM2 + 2, 75);
 + CMD_Wait(1000);
 + CMD_LocSpeed(ADDR_MM2 + 2, 50);
 + CMD_Wait(1000);
 + CMD_LocSpeed(ADDR_MM2 + 2, 25);
 + CMD_Wait(1000);
 + CMD_LocSpeed(ADDR_MM2 + 2, 0);
 + CMD_Wait(2000);
 +
 + //FWD
 + CMD_LocDirection(ADDR_MM2 + 2, 0);
 + Serial.println("FWD");
 +
 + //Clear
 + CMD_ScanS88();
 +
 + //警笛
 + CMD_LocFunction(ADDR_MM2 + 2, 2, 1);
 + CMD_Wait(100);
 + CMD_LocFunction(ADDR_MM2 + 2, 2, 0);
 +
 + /* 加速 */
 + CMD_LocSpeed(ADDR_MM2 + 2, 25);
 + CMD_Wait(1000);
 + CMD_LocSpeed(ADDR_MM2 + 2, 50);
 + CMD_Wait(1000);
 + CMD_LocSpeed(ADDR_MM2 + 2, 75);
 + CMD_Wait(1000);
 + CMD_LocSpeed(ADDR_MM2 + 2, 100);
 + }
 +}
 +</code>
 +
 +Youtube動画:\\ 
 +{{youtube>mtIwlYd2Fds?medium}}
  
dsshieldauto.txt · 最終更新: 2018/01/27 08:44 by yaasan

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki