Created
October 10, 2020 16:25
-
-
Save kylecorry31/939b19e91061dac800cdfccf2ea18083 to your computer and use it in GitHub Desktop.
An Arduino powered Subnautica blood kelp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define FADE 3 | |
int max_brightness = 255 - FADE; | |
int min_brightness = FADE; | |
int brightness[4] = {240, 230, 225, 200}; | |
int pins[4] = {5, 10, 6, 3}; | |
int fade[4] = {FADE, FADE, FADE, FADE}; | |
void setup() { | |
for (int i = 0; i < 4; i++){ | |
pinMode(pins[i], OUTPUT); | |
} | |
} | |
void loop() { | |
for (int i = 0; i < 4; i++){ | |
breathe(i); | |
} | |
delay(40); | |
} | |
void breathe(int idx){ | |
brightness[idx] += fade[idx]; | |
if (brightness[idx] >= max_brightness || brightness[idx] <= min_brightness){ | |
fade[idx] = -fade[idx]; | |
} | |
analogWrite(pins[idx], brightness[idx]); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment