0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Arduinoで各種コントローラを制御する。③ソフトウェア

Last updated at Posted at 2020-06-26

※自分用のメモも兼ねてます。随時更新予定。

Arduinoで各種コントローラを制御する。①検討 は こちら
Arduinoで各種コントローラを制御する。②ハードウェア は こちら
Arduinoで各種コントローラを制御する。③ソフトウェア は こちら

setup処理概要

シリアル通信開始

LED用のピンセットアップ
ps4コントローラーボタン用のピンセットアップ
Auto,Rec,Reset用のピンセットアップ(内部プルアップ抵抗使用)

Loop処理概要

ボードのボタン入力確認
if(Auto rec mode)コントローラのボタン入力確認
 
ピンの入力に応じてMode state更新
ピンの入力に応じてLED state更新

AutoMode用の割り込み信号作成
LED点滅用(遅)の割り込み信号作成
LED点滅用(早)の割り込み信号作成

if(AutoMode用の割り込み){
  if(Auto mode){
     信号の出力
  }else if(Auto rec mode){
     信号の入力
  }
}

LEDの出力更新

Future work

・SDカードを利用したデータの入出力
 記録したコマンドをPCで編集 + 編集したコマンドを実行
 

以下ソースコード

ps4_controller.c
//見やすくするためにfilename.cとしています。
//Arduinoで使用するときはfilename.inoとしてください

# include "IO_define.h"
# include "MODE_define.h"

typedef struct{
  char sw_state;
  unsigned long pressed_time;
  unsigned long released_time;
} button_c;
button_c sw[NUM_CONTOROLLER_BUTTON];

typedef struct{
  char sw_state;
  unsigned long pressed_time;
  unsigned long released_time;
} button_ext;
button_ext sw_ext[NUM_EXT_BUTTON];

bool auto_rec_data[NUM_REC_DATA][NUM_CONTOROLLER_BUTTON]; //this is toooo big
int  auto_rec_data_now = 0;
int  auto_rec_data_used_num = -1;

char auto_mode_state;
char auto_mode_flag; //TODO: change bool value

char led_board_state;
char led_green_state;
char led_red_state;
bool led_slow_flag = 0;
bool led_fast_flag = 0;

unsigned long now_time;
unsigned long before_time;
unsigned long before_slow_led_time;
unsigned long before_fast_led_time;

void setup() {
  int i;

  //シリアル通信開始
  Serial.begin(9600);
  Serial.println("Hello Arduino!");

  //LED用のピンセットアップ
  pinMode(LED_BOARD_PIN, OUTPUT);
  pinMode(LED_GREEN_PIN, OUTPUT);
  pinMode(LED_RED_PIN,   OUTPUT);

  //ps4コントローラーボタン用のピンセットアップ
  for(i=BUTTON_SQUARE_PIN; i<=BUTTON_R1_PIN; i++){
      pinMode(i,   INPUT);
  }
  for(i=BUTTON_SHARE_PIN; i<=BUTTON_OPTION_PIN; i++){
      pinMode(i,   INPUT);
  }
  for(i=BUTTON_L3_PIN; i<=BUTTON_LEFT_PIN; i++){
      pinMode(i,   INPUT);
  }

  //Auto,Rec,Reset用のピンセットアップ(内部プルアップ抵抗使用)
  for(i=BUTTON_AUTO_RESET_PIN; i<=BUTTON_AUTO_REC_PIN; i++){
      pinMode(i,   INPUT_PULLUP); //use pullup resistor at Arduino
  }

  Serial.println("IO set up end");
  digitalWrite(LED_BOARD_PIN, HIGH);
  
  delay(20); //delay for set INPUT_PULLUP
}

void loop() {
  int i;

    //ボードのボタン入力確認
    for(i=BUTTON_AUTO_RESET_PIN; i<= BUTTON_AUTO_REC_PIN; i++){
    if (digitalRead(i)==LOW) {
      switch(sw_ext[i-NUM_DIFF_PIN_ARRAY_LOCAL_SW].sw_state){
        case SW_STATE_UP:
          sw_ext[i-NUM_DIFF_PIN_ARRAY_LOCAL_SW].sw_state = SW_STATE_UP2DOWN;
          sw_ext[i-NUM_DIFF_PIN_ARRAY_LOCAL_SW].pressed_time = millis();
          break;
        case SW_STATE_UP2DOWN:
          if( millis() - sw_ext[i-NUM_DIFF_PIN_ARRAY_LOCAL_SW].pressed_time > TIME_SW_INTERVAL){
            sw_ext[i-NUM_DIFF_PIN_ARRAY_LOCAL_SW].sw_state = SW_STATE_DOWN;
            sw_ext[i-NUM_DIFF_PIN_ARRAY_LOCAL_SW].pressed_time = 0;
          }else{
            sw_ext[i-NUM_DIFF_PIN_ARRAY_LOCAL_SW].sw_state = SW_STATE_UP2DOWN;
          }
          break;
        case SW_STATE_DOWN:
          sw_ext[i-NUM_DIFF_PIN_ARRAY_LOCAL_SW].sw_state = SW_STATE_DOWN;
          break;
        case SW_STATE_DOWN2UP:
          sw_ext[i-NUM_DIFF_PIN_ARRAY_LOCAL_SW].sw_state = SW_STATE_DOWN; 
          break;
        }
      }else{ //digitalRead(i)==HIGH
        switch(sw_ext[i-NUM_DIFF_PIN_ARRAY_LOCAL_SW].sw_state){
        case SW_STATE_UP:
          sw_ext[i-NUM_DIFF_PIN_ARRAY_LOCAL_SW].sw_state = SW_STATE_UP;
          break;
        case SW_STATE_UP2DOWN:
          sw_ext[i-NUM_DIFF_PIN_ARRAY_LOCAL_SW].sw_state = SW_STATE_UP;
          break;
        case SW_STATE_DOWN:
          sw_ext[i-NUM_DIFF_PIN_ARRAY_LOCAL_SW].sw_state = SW_STATE_DOWN2UP;
          sw_ext[i-NUM_DIFF_PIN_ARRAY_LOCAL_SW].released_time = millis();
          break;
        case SW_STATE_DOWN2UP:
          if( millis() - sw_ext[i-NUM_DIFF_PIN_ARRAY_LOCAL_SW].released_time > TIME_SW_INTERVAL){
            sw_ext[i-NUM_DIFF_PIN_ARRAY_LOCAL_SW].sw_state = SW_STATE_UP;
            sw_ext[i-NUM_DIFF_PIN_ARRAY_LOCAL_SW].released_time = 0;
          }else{
            sw_ext[i-NUM_DIFF_PIN_ARRAY_LOCAL_SW].sw_state = SW_STATE_DOWN2UP;
          }
          break;
        }
      }
  }

  //コントローラのボタン入力確認
  if(auto_mode_state == AUTO_REC){    
  for(i=BUTTON_SQUARE_PIN; i<=BUTTON_R1_PIN; i++){
    if (digitalRead(i)==LOW) {
      switch(sw[i].sw_state){
        case SW_STATE_UP:
          sw[i].sw_state = SW_STATE_UP2DOWN;
          sw[i].pressed_time = millis();
          break;
        case SW_STATE_UP2DOWN:
          if( millis() - sw[i].pressed_time > TIME_SW_INTERVAL){
            sw[i].sw_state = SW_STATE_DOWN;
            sw[i].pressed_time = 0;
          }else{
            sw[i].sw_state = SW_STATE_UP2DOWN;
          }
          break;
        case SW_STATE_DOWN:
          sw[i].sw_state = SW_STATE_DOWN;
          break;
        case SW_STATE_DOWN2UP:
          sw[i].sw_state = SW_STATE_DOWN; 
          break;
      }
    }else{ //digitalRead(i)==HIGH
      switch(sw[i].sw_state){
        case SW_STATE_UP:
          sw[i].sw_state = SW_STATE_UP;
          break;
        case SW_STATE_UP2DOWN:
          sw[i].sw_state = SW_STATE_UP;
          break;
        case SW_STATE_DOWN:
          sw[i].sw_state = SW_STATE_DOWN2UP;
          sw[i].released_time = millis();
          break;
        case SW_STATE_DOWN2UP:
          if( millis() - sw[i].released_time > TIME_SW_INTERVAL){
            sw[i].sw_state = SW_STATE_UP;
            sw[i].released_time = 0;
          }else{
            sw[i].sw_state = SW_STATE_DOWN2UP;
          }
          break;
        }
      }
  }
    
    for(i=BUTTON_L2_PIN; i<=BUTTON_R2_PIN; i++){
    if (analogRead(i)>ANALOG_TH) {
      switch(sw[i-NUM_DIFF_PIN_ARRAY_L2R2].sw_state){
        case SW_STATE_UP:
          sw[i-NUM_DIFF_PIN_ARRAY_L2R2].sw_state = SW_STATE_UP2DOWN;
          sw[i-NUM_DIFF_PIN_ARRAY_L2R2].pressed_time = millis();
          break;
        case SW_STATE_UP2DOWN:
          if( millis() - sw[i-NUM_DIFF_PIN_ARRAY_L2R2].pressed_time > TIME_SW_INTERVAL){
            sw[i-NUM_DIFF_PIN_ARRAY_L2R2].sw_state = SW_STATE_DOWN;
            sw[i-NUM_DIFF_PIN_ARRAY_L2R2].pressed_time = 0;
          }else{
            sw[i-NUM_DIFF_PIN_ARRAY_L2R2].sw_state = SW_STATE_UP2DOWN;
          }
          break;
        case SW_STATE_DOWN:
          sw[i-NUM_DIFF_PIN_ARRAY_L2R2].sw_state = SW_STATE_DOWN;
          break;
        case SW_STATE_DOWN2UP:
          sw[i-NUM_DIFF_PIN_ARRAY_L2R2].sw_state = SW_STATE_DOWN; 
          break;
      }
    }else{ //digitalRead(i)==HIGH
      switch(sw[i-NUM_DIFF_PIN_ARRAY_L2R2].sw_state){
        case SW_STATE_UP:
          sw[i-NUM_DIFF_PIN_ARRAY_L2R2].sw_state = SW_STATE_UP;
          break;
        case SW_STATE_UP2DOWN:
          sw[i-NUM_DIFF_PIN_ARRAY_L2R2].sw_state = SW_STATE_UP;
          break;
        case SW_STATE_DOWN:
          sw[i-NUM_DIFF_PIN_ARRAY_L2R2].sw_state = SW_STATE_DOWN2UP;
          sw[i-NUM_DIFF_PIN_ARRAY_L2R2].released_time = millis();
          break;
        case SW_STATE_DOWN2UP:
          if( millis() - sw[i-NUM_DIFF_PIN_ARRAY_L2R2].released_time > TIME_SW_INTERVAL){
            sw[i-NUM_DIFF_PIN_ARRAY_L2R2].sw_state = SW_STATE_UP;
            sw[i-NUM_DIFF_PIN_ARRAY_L2R2].released_time = 0;
          }else{
            sw[i-NUM_DIFF_PIN_ARRAY_L2R2].sw_state = SW_STATE_DOWN2UP;
          }
          break;
        }
      }
  }
  
    for(i=BUTTON_SHARE_PIN; i<=BUTTON_OPTION_PIN; i++){
    if (digitalRead(i)==LOW) {
      switch(sw[i].sw_state){
        case SW_STATE_UP:
          sw[i].sw_state = SW_STATE_UP2DOWN;
          sw[i].pressed_time = millis();
          break;
        case SW_STATE_UP2DOWN:
          if( millis() - sw[i].pressed_time > TIME_SW_INTERVAL){
            sw[i].sw_state = SW_STATE_DOWN;
            sw[i].pressed_time = 0;
          }else{
            sw[i].sw_state = SW_STATE_UP2DOWN;
          }
          break;
        case SW_STATE_DOWN:
          sw[i].sw_state = SW_STATE_DOWN;
          break;
        case SW_STATE_DOWN2UP:
          sw[i].sw_state = SW_STATE_DOWN; 
          break;
      }
    }else{ //digitalRead(i)==HIGH
      switch(sw[i].sw_state){
        case SW_STATE_UP:
          sw[i].sw_state = SW_STATE_UP;
          break;
        case SW_STATE_UP2DOWN:
          sw[i].sw_state = SW_STATE_UP;
          break;
        case SW_STATE_DOWN:
          sw[i].sw_state = SW_STATE_DOWN2UP;
          sw[i].released_time = millis();
          break;
        case SW_STATE_DOWN2UP:
          if( millis() - sw[i].released_time > TIME_SW_INTERVAL){
            sw[i].sw_state = SW_STATE_UP;
            sw[i].released_time = 0;
          }else{
            sw[i].sw_state = SW_STATE_DOWN2UP;
          }
          break;
        }
      }
  }
  
  for(i=BUTTON_L3_PIN ; i<= BUTTON_LEFT_PIN; i++){
    if (digitalRead(i)==LOW) {
      switch(sw[i-NUM_DIFF_PIN_ARRAY_CONT].sw_state){
        case SW_STATE_UP:
          sw[i-NUM_DIFF_PIN_ARRAY_CONT].sw_state = SW_STATE_UP2DOWN;
          sw[i-NUM_DIFF_PIN_ARRAY_CONT].pressed_time = millis();
          break;
        case SW_STATE_UP2DOWN:
          if( millis() - sw[i-NUM_DIFF_PIN_ARRAY_CONT].pressed_time > TIME_SW_INTERVAL){
            sw[i-NUM_DIFF_PIN_ARRAY_CONT].sw_state = SW_STATE_DOWN;
            sw[i-NUM_DIFF_PIN_ARRAY_CONT].pressed_time = 0;
          }else{
            sw[i-NUM_DIFF_PIN_ARRAY_CONT].sw_state = SW_STATE_UP2DOWN;
          }
          break;
        case SW_STATE_DOWN:
          sw[i-NUM_DIFF_PIN_ARRAY_CONT].sw_state = SW_STATE_DOWN;
          break;
        case SW_STATE_DOWN2UP:
          sw[i-NUM_DIFF_PIN_ARRAY_CONT].sw_state = SW_STATE_DOWN; 
          break;
        }
      }else{ //digitalRead(i)==HIGH
        switch(sw[i-NUM_DIFF_PIN_ARRAY_CONT].sw_state){
        case SW_STATE_UP:
          sw[i-NUM_DIFF_PIN_ARRAY_CONT].sw_state = SW_STATE_UP;
          break;
        case SW_STATE_UP2DOWN:
          sw[i-NUM_DIFF_PIN_ARRAY_CONT].sw_state = SW_STATE_UP;
          break;
        case SW_STATE_DOWN:
          sw[i-NUM_DIFF_PIN_ARRAY_CONT].sw_state = SW_STATE_DOWN2UP;
          sw[i-NUM_DIFF_PIN_ARRAY_CONT].released_time = millis();
          break;
        case SW_STATE_DOWN2UP:
          if( millis() - sw[i-NUM_DIFF_PIN_ARRAY_CONT].released_time > TIME_SW_INTERVAL){
            sw[i-NUM_DIFF_PIN_ARRAY_CONT].sw_state = SW_STATE_UP;
            sw[i-NUM_DIFF_PIN_ARRAY_CONT].released_time = 0;
          }else{
            sw[i-NUM_DIFF_PIN_ARRAY_CONT].sw_state = SW_STATE_DOWN2UP;
          }
          break;
        }
      }
   }
  }


  //ピンの入力に応じてMode state更新
  //ピンの入力に応じてLED state更新
  if(sw_ext[BUTTON_AUTO_RESET_PIN-NUM_DIFF_PIN_ARRAY_LOCAL_SW].sw_state == SW_STATE_DOWN || sw_ext[BUTTON_AUTO_RESET_PIN-NUM_DIFF_PIN_ARRAY_LOCAL_SW].sw_state == SW_STATE_DOWN2UP){
    //AUTO reset button proc
    auto_rec_data_now = 0;
    auto_rec_data_used_num = -1;
    led_green_state = LED_STATE_FLASH_FAST;
    led_red_state = LED_STATE_FLASH_FAST;
    auto_mode_state = AUTO_OFF;
  }else if(sw_ext[BUTTON_AUTO_PIN-NUM_DIFF_PIN_ARRAY_LOCAL_SW].sw_state == SW_STATE_DOWN || sw_ext[BUTTON_AUTO_PIN-NUM_DIFF_PIN_ARRAY_LOCAL_SW].sw_state == SW_STATE_DOWN2UP){
    //AUTO button proc
    if(auto_rec_data_used_num < 0){
      led_green_state = LED_STATE_OFF;
      led_red_state = LED_STATE_FLASH_FAST;
    }else{
      auto_mode_state = AUTO_ON;
      led_green_state = LED_STATE_ON;
      led_red_state = LED_STATE_OFF;
    }
  }else if(sw_ext[BUTTON_AUTO_REC_PIN-NUM_DIFF_PIN_ARRAY_LOCAL_SW].sw_state == SW_STATE_DOWN || sw_ext[BUTTON_AUTO_REC_PIN-NUM_DIFF_PIN_ARRAY_LOCAL_SW].sw_state == SW_STATE_DOWN2UP){
    //AUTO rec button proc
    auto_mode_state = AUTO_REC;
    led_green_state = LED_STATE_OFF;
    led_red_state = LED_STATE_FLASH_SLOW;
  }else{
    auto_mode_state = AUTO_OFF;
    led_green_state = LED_STATE_OFF;
    led_red_state = LED_STATE_OFF;
  }

  
  
  now_time = millis();
  //AutoMode用の割り込み信号作成
  if(now_time - before_time > TIME_AUTO_MODE_INTERVAL){
    auto_mode_flag = 1;
    before_time = now_time;
  }else{
    auto_mode_flag = 0;
  }

  //LED点滅用(遅)の割り込み信号作成
  if(now_time - before_slow_led_time > TIME_LED_SLOW_FLASH_INTERVAL){
    led_slow_flag = !led_slow_flag;
    before_slow_led_time  = now_time;
  }
  
  //LED点滅用(早)の割り込み信号作成
  if(now_time - before_fast_led_time > TIME_LED_FAST_FLASH_INTERVAL){
    led_fast_flag = !led_fast_flag;
    before_fast_led_time  = now_time;
  }

  //update output/input auto mode value
  if(auto_mode_flag){       
    if(auto_mode_state == AUTO_ON){ //auto_mode_state = AUTO_ON
      //TODO:既にOUTPUTなら再度OUTPUTにする必要ない
      for(i=BUTTON_SQUARE_PIN; i<=BUTTON_R1_PIN; i++){
        pinMode(i,   OUTPUT);
        digitalWrite(i, auto_rec_data[auto_rec_data_now][i]); 
      }
      /* future work これを動かすと2回目以降入力を受け付けなくなる
      for(i=BUTTON_L2_PIN; i<=BUTTON_R2_PIN; i++){
        if(auto_rec_data[auto_rec_data_now][i-NUM_DIFF_PIN_ARRAY_L2R2] == HIGH){ //デジタルはHIGHの時OFF アナログはLOWの時OFF
          analogWrite(i, ANALOG_LOW);
        }else{
          analogWrite(i, ANALOG_HIGH);
        }
      }
      */
                
      for(i=BUTTON_SHARE_PIN; i<=BUTTON_OPTION_PIN; i++){
        pinMode(i,   OUTPUT);
        digitalWrite(i, auto_rec_data[auto_rec_data_now][i]); 
      }
      for(i=BUTTON_L3_PIN; i<=BUTTON_LEFT_PIN; i++){
        pinMode(i,   OUTPUT);
        digitalWrite(i, auto_rec_data[auto_rec_data_now][i-NUM_DIFF_PIN_ARRAY_CONT]); 
      } 
      auto_rec_data_now++;
      if(auto_rec_data_now>=auto_rec_data_used_num){
        auto_rec_data_now=0;
      }
//      Serial.print("auto_rec_data_now");
//      Serial.println(auto_rec_data_now); 
    }else if(auto_mode_state == AUTO_REC){ //auto_mode_state = AUTO_REC 
      for(i=0;i<NUM_CONTOROLLER_BUTTON;i++){
        if(sw[i].sw_state == SW_STATE_UP || sw[i].sw_state == SW_STATE_UP2DOWN){
           auto_rec_data[auto_rec_data_now][i] = HIGH;
        }else{
          auto_rec_data[auto_rec_data_now][i] = LOW;
        }
      }
      auto_rec_data_now++;
      if(auto_rec_data_now>=NUM_REC_DATA){
        auto_rec_data_now=0;
      }
      auto_rec_data_used_num = auto_rec_data_now;
//      Serial.print("auto_rec_data_used_num");
//      Serial.println(auto_rec_data_used_num);      
    }else{ //auto_mode_state = AUTO_OFF
      for(i=BUTTON_SQUARE_PIN; i<=BUTTON_R1_PIN; i++){
        pinMode(i,   INPUT);
      }
      for(i=BUTTON_L2_PIN; i<=BUTTON_R2_PIN; i++){
        analogRead(i); // Dummy Read
      }
      
      for(i=BUTTON_SHARE_PIN; i<=BUTTON_OPTION_PIN; i++){
        pinMode(i,   INPUT);
      }
      for(i=BUTTON_L3_PIN; i<=BUTTON_LEFT_PIN; i++){
        pinMode(i,   INPUT);
      }   
      auto_rec_data_now=0;
    }
  }else{
    //do nothing
  }  

  //LEDの出力更新
  switch(led_green_state){
    case LED_STATE_OFF:
      digitalWrite(LED_GREEN_PIN, LOW);
      break;
    case LED_STATE_ON:
      digitalWrite(LED_GREEN_PIN, HIGH);
      break;
    case LED_STATE_FLASH_FAST:
      digitalWrite(LED_GREEN_PIN, led_fast_flag);
      break;
    case LED_STATE_FLASH_SLOW:
      digitalWrite(LED_GREEN_PIN, led_slow_flag);
      break;
  } 
  switch(led_red_state){
    case LED_STATE_OFF:
      digitalWrite(LED_RED_PIN, LOW);
      break;
    case LED_STATE_ON:
      digitalWrite(LED_RED_PIN, HIGH);
      break;
    case LED_STATE_FLASH_FAST:
      digitalWrite(LED_RED_PIN, led_fast_flag);
      break;
    case LED_STATE_FLASH_SLOW:
      digitalWrite(LED_RED_PIN, led_slow_flag);
      break;
  }
  
  /* for test
  switch(led_red_state){
    case LED_STATE_OFF:
      digitalWrite(LED_BOARD_PIN, LOW);
      break;
    case LED_STATE_ON:
      digitalWrite(LED_BOARD_PIN, HIGH);
      break;
    case LED_STATE_FLASH_FAST:
      digitalWrite(LED_BOARD_PIN, led_fast_flag);
      break;
    case LED_STATE_FLASH_SLOW:
      digitalWrite(LED_BOARD_PIN, led_slow_flag);
      break;
  }
  */

  

  delay(10); //loop delay 1ms 
}
IO_define.h
/*  IO_define.h
*	This file defines LED/SW pins
*/
# ifndef IO_DEFINE_H
# define IO_DEFINE_H

/* define for local LED */
# define		LED_BOARD_PIN	  13
# define		LED_GREEN_PIN	  14		
# define		LED_RED_PIN		  15		

/* define for local SW */
# define   BUTTON_AUTO_RESET_PIN 10
# define   BUTTON_AUTO_PIN       11
# define   BUTTON_AUTO_REC_PIN   12
# define   NUM_EXT_BUTTON        3
# define   NUM_DIFF_PIN_ARRAY_LOCAL_SW    10

/* define for controller SW */
# define   BUTTON_SQUARE_PIN     0   //□
# define   BUTTON_CROSS_PIN      1   //✕
# define   BUTTON_CIRCLUE_PIN    2   //○
# define   BUTTON_TRIANGLE_PIN   3   //△

# define   BUTTON_L1_PIN         4   //L1
# define   BUTTON_R1_PIN         5   //R1
# define   BUTTON_L2_PIN         35  //L2 
# define   BUTTON_R2_PIN         36  //R2 

# define   BUTTON_SHARE_PIN      8   //Share
# define   BUTTON_OPTION_PIN     9   //Option

# define   BUTTON_L3_PIN         16  //L3
# define   BUTTON_R3_PIN         17  //R3
# define   BUTTON_PS_PIN         18  //PS button
# define   BUTTON_TOUCH_PIN      19  //Touch Pad

# define   BUTTON_UP_PIN         20   //↑
# define   BUTTON_RIGHT_PIN      21   //→
# define   BUTTON_DOWN_PIN       22   //↓
# define   BUTTON_LEFT_PIN       23   //←

# define   NUM_CONTOROLLER_BUTTON  18   
# define   NUM_DIFF_PIN_ARRAY_CONT 6   //Diffrence between Pin No. and Array i No.
# define   NUM_DIFF_PIN_ARRAY_L2R2 29  //Diffrence between Pin No. and Array i No. for L2 R2

# endif /*IO_DEFINE_H*/
MODE_define.h
/*  MODE_define.h
*	This file defines the values of each MODE
*/
# ifndef MODE_DEFINE_H
# define MODE_DEFINE_H

/* define for Rapid-Fire Mode */ 
/*
 * future work
# define RAPID_FIRE_OFF    0
# define RAPID_FIRE_ON     1
# define RAPID_FIRE_HOLD   2
*/
/* define for AUTO Mode */
# define AUTO_OFF    0
# define AUTO_ON     1
# define AUTO_REC    2

# define NUM_REC_DATA  13000

/* define for L2/R2 analog th value*/
# define ANALOG_TH     180
# define ANALOG_HIGH   360 //要調整
# define ANALOG_LOW    0

/* define for SW status */
# define SW_STATE_UP       0
# define SW_STATE_UP2DOWN  1
# define SW_STATE_DOWN     2
# define SW_STATE_DOWN2UP  3

/* define for LED status */
# define LED_STATE_OFF         0
# define LED_STATE_ON          1
# define LED_STATE_FLASH_FAST  2
# define LED_STATE_FLASH_SLOW  3

/* define for SW/LED interval time */
# define TIME_SW_INTERVAL              10 //10ms
# define TIME_SW_RAPID_FIRE_INTERVAL   30 //30ms
# define TIME_AUTO_MODE_INTERVAL       30 //30ms
# define TIME_LED_FAST_FLASH_INTERVAL  30 //30ms
# define TIME_LED_SLOW_FLASH_INTERVAL  200 //200ms


# endif /*MODE_DEFINE_H*/
0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?