Skip to content

Commit dd7a702

Browse files
Merge pull request #24 from codewithher/22-feature-migrate_color_wheel
22 Migrate Color Wheel Activity #22
2 parents 17490f4 + 7fa40f6 commit dd7a702

File tree

2 files changed

+32
-54
lines changed

2 files changed

+32
-54
lines changed

examples/act3-functions/act3-functions.ino

Lines changed: 31 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -12,71 +12,49 @@ void setup() {
1212

1313
void loop() {
1414
// try hovering over these functions to see the comments!
15-
gradientRed(1.5, 10);
16-
blinkingPatterns(2, 2, 10);
17-
fadeInAndOut(1.5, 1.5);
15+
rainbow(20);
16+
// Other functions to try after rainbow()
17+
// blinkingPatterns(2, 2, 10);
18+
// fadeInAndOut(1.5, 1.5);
1819
}
1920

2021
/**
2122
* Parameters:
22-
* - "seconds": a number that describes how long you want each "iteration" to be
23-
* - "numSteps": a number that describes how many times you want the red color to change
23+
* - "seconds": a number that describes how long you want the rainbow gradient to be
2424
* ---
25-
* Function Description: This function sets your LED to white (aka all RGB values to 255) and decreases
26-
* the red RGB value by 10 a "numSteps" amount of times. It will decrease the value every "seconds" seconds.
25+
* Function Description: This function rotates your LED through the RGB colors (from red to green to blue) by
26+
* decreasing each pixel by a value of 1. It will go through the entire rainbow of colors is "seconds" seconds.
2727
* ---
28-
* Example Function Call: `gradientRed(2,4)` --> this decreases the red RBG value every 2 seconds, for 4 times
28+
* Example Function Call: `rainbowStep(30)` --> creates a rainbow that lasts 30 seconds.
2929
*/
30-
void gradientRed(float seconds, int numSteps) {
31-
int Red = 250;
32-
int Green = 250;
33-
int Blue = 250;
34-
35-
for (int step = 0; step < numSteps; step++) {
36-
Red -= 50;
37-
lantern.setColor(seconds, lantern.color(Red, Green, Blue));
30+
void rainbow(float seconds) {
31+
int red = 0;
32+
int green = 0;
33+
int blue = 0;
34+
35+
// Set default value of 0.25 if an invalid number is given
36+
if (seconds <= 0) {
37+
seconds = 0.25;
3838
}
39-
}
4039

41-
/*
42-
* Parameters:
43-
* - "seconds": a number that describes how long you want each "iteration" to be
44-
* - "numSteps": a number that describes how many times you want the green color to change
45-
* ---
46-
* Function Description: This function sets your LED to white (aka all RGB values to 255) and decreases
47-
* the green RGB value by 10 a "numSteps" amount of times. It will decrease the value every "seconds" seconds.
48-
* ---
49-
* Example Function Call: `gradientGreen(2,4)` --> this decreases the green RBG value every 2 seconds, for 4 times
50-
*/
51-
void gradientGreen(float seconds, int numSteps) {
52-
int Red = 250;
53-
int Green = 250;
54-
int Blue = 250;
40+
const int steps = 255; // Number of steps for each color in the LED
41+
const int num_led = 3; // Number of colors per LED (RGB)
42+
const int total_steps = steps * num_led; // Total steps in the gradient
43+
const float time_per_color = seconds / total_steps; // Time for each color step
5544

56-
for (int step = 0; step < numSteps; step++) {
57-
Green -= 50;
58-
lantern.setColor(seconds, lantern.color(Red, Green, Blue));
45+
for (red = 255; red > 0; red --) {
46+
green += 1;
47+
lantern.setColor(time_per_color, lantern.color(red, green, blue));
5948
}
60-
}
6149

62-
/*
63-
* Parameters:
64-
* - "seconds": a number that describes how long you want each "iteration" to be
65-
* - "numSteps": a number that describes how many times you want the blue color to change
66-
* ---
67-
* Function Description: This function sets your LED to white (aka all RGB values to 255) and decreases
68-
* the blue RGB value by 10 a "numSteps" amount of times. It will decrease the value every "seconds" seconds.
69-
* ---
70-
* Example Function Call: `gradientBlue(2,4)` --> this decreases the blue RBG value every 2 seconds, for 4 times
71-
*/
72-
void gradientBlue(float seconds, int numSteps) {
73-
int Red = 250;
74-
int Green = 250;
75-
int Blue = 250;
50+
for (green = 255; green > 0; green --) {
51+
blue += 1;
52+
lantern.setColor(time_per_color, lantern.color(red, green, blue));
53+
}
7654

77-
for (int step = 0; step < numSteps; step++) {
78-
Blue -= 50;
79-
lantern.setColor(seconds, lantern.color(Red, Green, Blue));
55+
for (blue = 255; blue > 0; blue --) {
56+
red += 1;
57+
lantern.setColor(time_per_color, lantern.color(red, green, blue));
8058
}
8159
}
8260

@@ -194,4 +172,4 @@ void pulsatingEffect(int seconds, int numPulses) {
194172
lantern.setColor(seconds, lantern.color(Red, Green, Blue));
195173
}
196174
}
197-
}
175+
}

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=CC-Lantern
2-
version=1.0.1
2+
version=1.1.0
33
author=Code With Her
44
maintainer=Ryan <[email protected]>
55
sentence=Arduino library for controlling single-wire-based LED pixels and strip.

0 commit comments

Comments
 (0)