From b7fbb9b1304f45e2611a2dfaa590545f877835e0 Mon Sep 17 00:00:00 2001 From: jakobst1n Date: Wed, 31 Oct 2018 08:52:51 +0100 Subject: Finish dimmer --- Kostyme.ino | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 Kostyme.ino (limited to 'Kostyme.ino') diff --git a/Kostyme.ino b/Kostyme.ino new file mode 100644 index 0000000..af3bbb1 --- /dev/null +++ b/Kostyme.ino @@ -0,0 +1,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; + } +} -- cgit v1.2.3