//ヘッドライト減光装置ーーーー2015/4/10 Yamasawa_Masahiro
//boolean Light_State = LOW;
boolean Loff_Flg = false;
const int Set_Time = 1500;//不感時間の
const int Delay_Time = 1000;//チェンジの無効時間
const int Light_Wait_Val = 20000;//ライト消灯までの時間
const int Light_Low_Val = 1;//減光時の明るさ
const int Delay_On_Time = 3;
const int Delay_Off_Time = 10;
const int N_State = 7 ;//ニュートラル表示用
const int State_Led = 8;//運転状態表示用Led
int Max_Val = 255;//明るさの最大値
int Min_Val = 0;//明るさの最小値
//===========================================
boolean Get_Stats(void) {
return digitalRead(N_In);
//return !digitalRead(N_In);
boolean Chk_Chg(boolean x, int val) {
if (In_State == Get_Stats()) {
//Serial.println("******");
void Led_Blink(int C, int P, int Dly) {
for (int s = 0; s < C; s++)
digitalWrite(State_Led, HIGH);
digitalWrite(State_Led, LOW);
// put your setup code here, to run once:
digitalWrite(pin10, LOW);
digitalWrite(pin11, LOW);
digitalWrite(pin12, LOW);
digitalWrite(pin13, LOW);
digitalWrite(pinA0, LOW);
digitalWrite(pinA1, LOW);
digitalWrite(pinA2, LOW);
digitalWrite(pinA3, LOW);
digitalWrite(pinA4, LOW);
digitalWrite(pinA5, LOW);
pinMode(N_In, INPUT_PULLUP);
pinMode(Led_Out, OUTPUT);
pinMode(N_State, OUTPUT);
pinMode(State_Led, OUTPUT);
digitalWrite(N_State, !In_State); //13番をニュートラル表示と同じに
analogWrite(Led_Out, 255);
Serial.println("SetUp—start!");
//===========================================
//===========================================
//===========================================
//===========================================
//==========================================
//Serial.println(LOFF_Flg);
// Led_Blink(3,400);//状態表示を3回表示
if (Time_Val + Light_Wait_Val < millis()) {
Serial.println("Light_OFF");
//記憶している状態と現在の状態が同じなら何もしない
if (In_State == Get_Stats()) {
Led_Blink(1, 10, 0); //状態表示を1回表示
Led_Blink(2, 10, 400); //状態表示を2回表示
Led_Blink(1, 500, 400); //状態表示をゆっくり回表示
//Serial.println("Event Start");
digitalWrite(N_State, !In_State);
for (int Led_Val = Min_Val; Led_Val <= 255; Led_Val++)
//Serial.println(Led_Val);
analogWrite(Led_Out, Led_Val);
if (Chk_Chg(false, Led_Val)) {
Serial.println("——————–End———————–");
for (int Led_Val = Max_Val; Led_Val >= Light_Low_Val; Led_Val–)
//Serial.println(Led_Val);
analogWrite(Led_Out, Led_Val);
//Serial.println(Led_Val);
if (Chk_Chg(true, Led_Val)) {
Serial.println("FFFFFFF");
//Serial.println("———————————-");