aboutsummaryrefslogtreecommitdiff
path: root/Kostyme.ino
blob: af3bbb1663e5959f630c8cb453578bfc481b44ed (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#define OUTPIN 1
#define DIMPIN 3

int CBrightness = 0;
int CDimDirection = 1;

void setup() {
  pinMode(OUTPIN, OUTPUT);
  pinMode(DIMPIN, INPUT);
}

void loop() {
  delay(1);
 
 if (digitalRead(DIMPIN) == HIGH) { dim(); }
 analogWrite(OUTPIN, CBrightness); 
}

void dim() {
  if (CDimDirection == 1) {
    CBrightness++;
  }
  if (CDimDirection == 0) {
    CBrightness--;
  }
  if (CBrightness >= 255) {
    CDimDirection = 0;
  }
  if (CBrightness <= 0) {
    CDimDirection = 1;
  }
}