Skip to content

Commit

Permalink
reduce brightness, remove old rainbow function
Browse files Browse the repository at this point in the history
  • Loading branch information
jasperp92 committed Oct 11, 2023
1 parent 103cd32 commit 4b99f0a
Showing 1 changed file with 1 addition and 75 deletions.
76 changes: 1 addition & 75 deletions source/samples/Utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ void shakeEvent(MicroBitEvent)
}

// LED functions
int brightness = 32;
int brightness = 20;
const int strip_length = 3;
uint16_t pause = 300;

Expand Down Expand Up @@ -350,80 +350,6 @@ void rainbow(void){
uBit.display.setBrightness(100); // restore brightness
}

void rainbow2()
{
// Cycle a single RGB led using the sine fade technique
// For common cathode led

ManagedBuffer b(strip_length * 3);
int delay = 1; // ms
int start_brightness = 0;
int cycle_length = 360;
int max_display_brightness = 100;
int display_brightness = 0;

const uint8_t sins[360] = {
0, 0, 0, 0, 0, 1, 1, 2, 2, 3, 4, 5, 6, 7, 8, 9, 11, 12,
13, 15, 17, 18, 20, 22, 24, 26, 28, 30, 32, 35, 37, 39, 42, 44, 47, 49,
52, 55, 58, 60, 63, 66, 69, 72, 75, 78, 81, 85, 88, 91, 94, 97, 101, 104,
107, 111, 114, 117, 121, 124, 127, 131, 134, 137, 141, 144, 147, 150, 154, 157, 160, 163,
167, 170, 173, 176, 179, 182, 185, 188, 191, 194, 197, 200, 202, 205, 208, 210, 213, 215,
217, 220, 222, 224, 226, 229, 231, 232, 234, 236, 238, 239, 241, 242, 244, 245, 246, 248,
249, 250, 251, 251, 252, 253, 253, 254, 254, 255, 255, 255, 255, 255, 255, 255, 254, 254,
253, 253, 252, 251, 251, 250, 249, 248, 246, 245, 244, 242, 241, 239, 238, 236, 234, 232,
231, 229, 226, 224, 222, 220, 217, 215, 213, 210, 208, 205, 202, 200, 197, 194, 191, 188,
185, 182, 179, 176, 173, 170, 167, 163, 160, 157, 154, 150, 147, 144, 141, 137, 134, 131,
127, 124, 121, 117, 114, 111, 107, 104, 101, 97, 94, 91, 88, 85, 81, 78, 75, 72,
69, 66, 63, 60, 58, 55, 52, 49, 47, 44, 42, 39, 37, 35, 32, 30, 28, 26,
24, 22, 20, 18, 17, 15, 13, 12, 11, 9, 8, 7, 6, 5, 4, 3, 2, 2,
1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};

uBit.display.setBrightness(0);
uBit.display.print(smiley);

for (int k = 0; k < cycle_length ; k++)
{
if (k <= max_display_brightness)
{
display_brightness++;
}
if (k > cycle_length - (max_display_brightness + 1))
{
display_brightness--;
}
uBit.display.setBrightness(display_brightness);

if (k <= brightness)
{
start_brightness++;

}
if (k > cycle_length - (brightness + 1))
{
start_brightness--;
}

for (int i = 0; i < strip_length; i++)
{
b[0 + i * 3] = map(sins[(k + i * 120) % 360], 0, 255, 0, start_brightness);
b[1 + i * 3] = map(sins[(k + 120 + i * 120) % 360], 0, 255, 0, start_brightness);
b[2 + i * 3] = map(sins[(k + 240 + i * 120) % 360], 0, 255, 0, start_brightness);
}
uBit.serial.send(start_brightness + "\r\n");
neopixel_send_buffer(uBit.io.RGB, b);
uBit.sleep(delay);
}
disableLEDs();
uBit.display.clear();
uBit.display.setBrightness(max_display_brightness);
}

bool mute_mic = false;

void playsound(int freq)
Expand Down

0 comments on commit 4b99f0a

Please sign in to comment.