Arduino2014. 8. 8. 17:24

//아래 두 코드는 원하는 결과가 나오지 않는다.

// 엣지 풀? 업 , 엣지 풀?다운 을 생각해 코딩한다.


boolean LedState;

int preButton;


void setup()

{

  pinMode(8, OUTPUT);

  pinMode(9, INPUT_PULLUP);

  

  LedState = LOW;

  preButton = digitalRead(9);

}


void loop()

{

  int curButton = digitalRead(9);

  if(curButton == LOW && preButton == HIGH)

  {

    if(LedState == HIGH)  LedState = LOW;

    else LedState = HIGH;

  }

  

  preButton = curButton;

  digitalWrite(8, LedState);  

}



---------------------------------



unsigned long time;

int LedState;


void setup()

{

  pinMode(8, OUTPUT);

  pinMode(9, OUTPUT);//

  time = millis();

  LedState = LOW;

}


void loop()

{

  unsigned long time2 = millis();

  

  if(time2 - time >= 1000)

  {

    if(LedState == HIGH)

      {LedState = LOW; digitalWrite(9, !LedState); }

    else

      LedState = HIGH;

      

    //digitalWrite(9, LedState);  

    time = time2;

  }

  

  digitalWrite(8, LedState);

}

Posted by 코드버무려