Загрузка данных


#define BUTTON 2
#define LED 9

int count = 0;

int buttonState = HIGH;
int lastButtonState = HIGH;

unsigned long lastTime = 0;
unsigned long debounce = 50;

void setup()
{
  pinMode(BUTTON, INPUT_PULLUP);
  pinMode(LED, OUTPUT);
}

void loop()
{
  int reading = digitalRead(BUTTON);

  if (reading != lastButtonState)
  {
    lastTime = millis();
  }

  if ((millis() - lastTime) > debounce)
  {
    if (reading != buttonState)
    {
      buttonState = reading;

      if (buttonState == LOW)
      {
        count++;

        if (count == 3)
        {
          for (int brightness = 0; brightness <= 255; brightness++)
          {
            analogWrite(LED, brightness);
            delay(12);
          }
        }

        if (count == 4)
        {
          analogWrite(LED, 0);
          count = 0;
        }
      }
    }
  }

  lastButtonState = reading;
}