aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjakobst1n <jakob.stendahl@outlook.com>2018-10-31 08:52:51 +0100
committerjakobst1n <jakob.stendahl@outlook.com>2018-10-31 08:52:51 +0100
commitb7fbb9b1304f45e2611a2dfaa590545f877835e0 (patch)
treeafd6a55965936e6b2ee121cc9a32391e1db9b447
downloadStickman-Costume-b7fbb9b1304f45e2611a2dfaa590545f877835e0.tar.gz
Stickman-Costume-b7fbb9b1304f45e2611a2dfaa590545f877835e0.zip
Finish dimmer
-rw-r--r--Kostyme.ino32
1 files changed, 32 insertions, 0 deletions
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;
+ }
+}