2013-11-25 2 views
0

이렇게 힘들지는 않을 것입니다. 큰 컨트롤 패널에서 "사진 찍기"버튼 인 버튼이 있습니다. 지금 LED가 10 초 동안 켜지고 뒤집습니다. 처음 5 초 동안 깜박이고 마지막 5 초 동안 계속 켜고 싶습니다. 그 일에 대해 확신 할 수 없다. 나는 추측을 시도했지만 아무 것도 시도하지 않았다. 내가 지금까지 무엇을 여기의 현재 길이 추한,이다 :처음 5 초 동안 깜박임 LED가 켜지고 버튼을 누를 때 마지막 5 초 동안 계속 켜져 있음 (Arduino)

// take a picture button 


const int shoot_pin = 5; 
const int shoot_led = 13; 

int shoot_state = 0; 
int last_shoot_state = 0; 


long shoot_timer; 
long lastDebounceTime = 0; // the last time the output pin was toggled 
long debounceDelay = 10; // the debounce time; increase if the output flickers 


void setup(){ 
    Serial.begin(9600); 
    pinMode(shoot_pin, INPUT); 
    pinMode(shoot_led, OUTPUT); 

} 

void loop() { 
    int shoot_reading = digitalRead(shoot_pin); 

    if (shoot_reading != last_shoot_state) { lastDebounceTime = millis(); } 

    if ((millis() - lastDebounceTime) > debounceDelay) { 

    if (shoot_reading != shoot_state) { 
     shoot_state = shoot_reading; 

     if (shoot_state == HIGH) { 
      digitalWrite(shoot_led, HIGH); 
      shoot_timer = millis(); 
      Serial.println("Counting down...5 seconds"); // for tracking 
      delay(5000); 
      Serial.println("Shooting Picture"); // for tracking - eventually will be a keypress 

     } // end of high 

    } // end of reading 

    }// end of that giant nested debaounce 

    last_shoot_state = shoot_reading; 

    // right now just stays lit for 10 seconds 
    if (millis() - shoot_timer >= 10000){ digitalWrite(shoot_led, LOW);} 

} // end of loop 

답변

0

(이 경우에, blinkLED)를 깜박 사용자 정의 함수를 호출하여 지연을 교체 한 후 10 초에서 시간에를 감소 5

// take a picture button 


const int shoot_pin = 5; 
const int shoot_led = 13; 

int shoot_state = 0; 
int last_shoot_state = 0; 


long shoot_timer; 
long lastDebounceTime = 0; // the last time the output pin was toggled 
long debounceDelay = 10; // the debounce time; increase if the output flickers 


void setup(){ 
    Serial.begin(9600); 
    pinMode(shoot_pin, INPUT); 
    pinMode(shoot_led, OUTPUT); 

} 

void loop() { 
    int shoot_reading = digitalRead(shoot_pin); 

    if (shoot_reading != last_shoot_state) { lastDebounceTime = millis(); } 

    if ((millis() - lastDebounceTime) > debounceDelay) { 

    if (shoot_reading != shoot_state) { 
     shoot_state = shoot_reading; 

     if (shoot_state == HIGH) { 
      digitalWrite(shoot_led, HIGH); 
      shoot_timer = millis(); 
      Serial.println("Counting down...5 seconds"); // for tracking 
      delay(5000); 
      blinkLED(13, 500, 500, 5); 
      Serial.println("Shooting Picture"); // for tracking - eventually will be a keypress 

     } // end of high 

    } // end of reading 

    }// end of that giant nested debounce 

    last_shoot_state = shoot_reading; 

    // turn on LED for 5 seconds 
    digitalWrite(shoot_led, LOW); 
    delay(5000); 
    digitalWrite(shoot_led, HIGH); 

} // end of loop 

void blinkLED(int pinNumber, int onLength, int offLength, int repetitions){ 
    for(int i=0; i < repetitions; i++){  
     digitalWrite(pinNumber, LOW); //on 
     delay(onLength); 
     digitalWrite(pinNumber, HIGH); //off 
     delay(offLength); 
    } 
} 
+0

에이 –

+0

. 'blinkLED'는 "변수 또는 필드 무효 오류를 저를 선언주고 내 컴파일러의 앞에 아닙니다, 내가 그것을 살펴 보자. – DrCord

+0

내가 가진 문제를 발견 한 것 같아요 내 사용자 정의 함수 및 코드를 업데이트, 나는 각 int, 그 언어의 무리에서 프로그램을 만들 때 무슨 일이 있었 사용 변수의 각 선언하지 않았습니다! : D – DrCord

관련 문제