03.05.2013Article


File

// set pin numbers:
const int buttonPin = PUSH2;     // the number of the pushbutton pin
int ledPin =  GREEN_LED;      // the number of the LED pin
int state=0;
// variables will change:
int buttonState = 0;         // variable for reading the pushbutton status
int change=0;
int last=HIGH;
long curMills=0;
long lastMills=0;
//kvuli nedomacknuti tlacitka rychle vickrat za sebou se berou jen zmacknuti po delsi dobe nez 50 milisekund
int tr=50;
void setup() {
  // initialize the LED pin as an output:
  pinMode(GREEN_LED, OUTPUT);
  pinMode(RED_LED, OUTPUT);
  // initialize the pushbutton pin as an input:
  pinMode(buttonPin, INPUT_PULLUP);
}

void loop(){
  // read the state of the pushbutton value:
  buttonState = digitalRead(buttonPin);
  curMills=millis();

  // check if the pushbutton is pressed.
  // if it is, the buttonState is HIGH:
  if(buttonState==last){
   // digitalWrite(GREEN_LED, HIGH);
    change=0;
  }else{
    if(curMills-lastMills<tr){
      change=0;
    }else{
      change=1;
      last=buttonState;
    }
    lastMills=curMills;
  }

  if (buttonState == HIGH) {
    // turn LED on:
    digitalWrite(ledPin, HIGH);
  }
  else {
    // turn LED off:
    digitalWrite(ledPin, LOW);
      if(state==0&&change==1){
        ledPin=GREEN_LED;
        state=1;
      }else{
        if(state==1&&change==1){
          ledPin=RED_LED;
          state=0;
        }
      }
  }
}


weehrfjhglker
ekrgerjer
erglhlerer
code();
jfoieru
function()
{
}


_TEXT_


comments powered by Disqus