Skip to content

Instantly share code, notes, and snippets.

@kylecorry31
Created October 10, 2020 16:25
Show Gist options
  • Save kylecorry31/939b19e91061dac800cdfccf2ea18083 to your computer and use it in GitHub Desktop.
Save kylecorry31/939b19e91061dac800cdfccf2ea18083 to your computer and use it in GitHub Desktop.
An Arduino powered Subnautica blood kelp
#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