├── old ├── Makefile ├── README └── blinky.c ├── .gitignore ├── led30 ├── led30.ino └── cRGB.h └── tiny-bike └── tiny-bike.ino /old/Makefile: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/donpdonp/bikelights/master/old/Makefile -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.eep 2 | *.elf 3 | *.hex 4 | *.lss 5 | *.lst 6 | *.map 7 | *.o 8 | *.sym 9 | .dep/ 10 | -------------------------------------------------------------------------------- /old/README: -------------------------------------------------------------------------------- 1 | My bicycle runs a Teensy++ board powered by a lead-acid battery. 2 | A number of LEDs are wired to the board and taped to parts of 3 | the bicycle. 4 | 5 | Position LEDs Teensy PIN 6 | 7 | On-Board Orange D6 8 | Teensy 9 | 10 | Handlebar White B3 11 | Headlamp 12 | 13 | Forks Blue D1 14 | 15 | Handlebar Blue D2 16 | Ends 17 | 18 | Back Ultraviolet D4 19 | 20 | Back left Red B5(bad) 21 | Green B6 22 | Blue B7 23 | 24 | Back right Red C6 25 | Green C7 26 | Blue D7 27 | 28 | Bucket Green B4 29 | Underneath 30 | -------------------------------------------------------------------------------- /led30/led30.ino: -------------------------------------------------------------------------------- 1 | //https://github.com/cpldcpu/light_ws2812 2 | #include 3 | #include 4 | 5 | #define LEDCount 30 6 | WS2812 NeoA(LEDCount); 7 | cRGB value; 8 | byte intensity; 9 | byte sign; 10 | 11 | int ledRed = 3; 12 | int ledGreen = 4; 13 | 14 | void setup() { 15 | NeoA.setOutput(2); 16 | 17 | pinMode(ledGreen, OUTPUT); 18 | pinMode(ledRed, OUTPUT); 19 | 20 | digitalWrite(ledGreen, HIGH); 21 | NeoA.setColorOrderRGB(); 22 | intensity = 0; 23 | sign = 1; 24 | } 25 | 26 | void loop() { 27 | int i = 0; 28 | if (sign) { 29 | intensity++; 30 | if (intensity == 255) 31 | sign = 0; 32 | } 33 | else { 34 | intensity--; 35 | if (intensity == 0) 36 | sign = 1; 37 | } 38 | 39 | while (i < LEDCount){ 40 | if ((i % 3) == 0) { // First LED, and every third after that 41 | value.b = 0; 42 | value.g = 0; 43 | value.r = intensity; // RGB Value -> Red Only 44 | NeoA.set_crgb_at(i, value); // Set value at LED found at index 0 45 | } 46 | else if ((i % 3) == 1) { // Second LED, and every third after that 47 | value.b = 0; 48 | value.g = intensity; 49 | value.r = 0; // RGB Value -> Green Only 50 | NeoA.set_crgb_at(i, value); // Set value at LED found at index 0 51 | } 52 | else { // Third LED, and every third after that 53 | value.b = intensity; 54 | value.g = 0; 55 | value.r = 0; // RGB Value -> Blue Only 56 | NeoA.set_crgb_at(i, value); // Set value at LED found at index 0 57 | } 58 | i++; 59 | } 60 | 61 | NeoA.sync(); // Sends the data to the LEDs 62 | delay(10); // Wait (ms) 63 | } 64 | -------------------------------------------------------------------------------- /tiny-bike/tiny-bike.ino: -------------------------------------------------------------------------------- 1 | #define USE_HSV 1 2 | #include 3 | 4 | WS2812 NeoA(16); 5 | //WS2812 NeoB(8); // 8 LED 6 | 7 | cRGB color; 8 | 9 | int ledR = 3; 10 | int ledG = 4; 11 | 12 | void setup() { 13 | randomSeed(analogRead(0)); 14 | 15 | NeoA.setOutput(2); 16 | //NeoB.setOutput(5); 17 | pinMode(ledG, OUTPUT); 18 | pinMode(ledR, OUTPUT); 19 | 20 | digitalWrite(ledG, HIGH); 21 | 22 | // 0-7 front lights 23 | color.r = 155; color.g = 155; color.b = 155; 24 | for(int i=0; i < 8; i++) { 25 | NeoA.set_crgb_at(i, color); // Set color at LED found at index 0 26 | } 27 | 28 | // 8-15 back lights 29 | color.r = 155; color.g = 0; color.b = 0; 30 | for(int i=8; i < 16; i++) { 31 | NeoA.set_crgb_at(i, color); // Set color at LED found at index 0 32 | } 33 | 34 | NeoA.sync(); // Sends the color to the LED 35 | } 36 | 37 | void loop() { 38 | 39 | // cycle front strip 40 | digitalWrite(ledR, HIGH); 41 | for(int i=0; i < 8; i++) { 42 | color.r = 0; color.g = 150; color.b = 0; // RGB color -> Half Red 43 | NeoA.set_crgb_at(i, color); // Set color at LED found at index 0 44 | NeoA.sync(); // Sends the color to the LED 45 | delay(90); 46 | color.r = 155; color.g = 155; color.b = 155; 47 | NeoA.set_crgb_at(i, color); // Set color at LED found at index 0 48 | NeoA.sync(); // Sends the color to the LED 49 | delay(90); 50 | } 51 | 52 | for(int i=7; i >= 0; i--) { 53 | color.r = 0; color.g = 0; color.b = 155; 54 | NeoA.set_crgb_at(i, color); // Set color at LED found at index 0 55 | NeoA.sync(); // Sends the color to the LED 56 | delay(90); 57 | color.r = 255; color.g = 255; color.b = 255; 58 | NeoA.set_crgb_at(i, color); // Set color at LED found at index 0 59 | NeoA.sync(); // Sends the color to the LED 60 | delay(90); 61 | } 62 | 63 | delay(300); 64 | 65 | 66 | // cycle back strip 67 | digitalWrite(ledR, LOW); 68 | for(int i=8; i < 16; i++) { 69 | color.SetHSV(random(255),255,155); 70 | NeoA.set_crgb_at(i, color); // Set color at LED found at index 0 71 | NeoA.sync(); // Sends the color to the LED 72 | delay(150); 73 | color.r = 155; color.g = 0; color.b = 0; 74 | NeoA.set_crgb_at(i, color); // Set color at LED found at index 0 75 | NeoA.sync(); // Sends the color to the LED 76 | delay(90); 77 | } 78 | 79 | for(int i=15; i > 7; i--) { 80 | color.SetHSV(random(255),255,155); 81 | NeoA.set_crgb_at(i, color); // Set color at LED found at index 0 82 | NeoA.sync(); // Sends the color to the LED 83 | delay(150); 84 | color.r = 155; color.g = 0; color.b = 0; 85 | NeoA.set_crgb_at(i, color); // Set color at LED found at index 0 86 | NeoA.sync(); // Sends the color to the LED 87 | delay(90); 88 | } 89 | 90 | delay(300); // Wait 500 ms 91 | 92 | } 93 | 94 | -------------------------------------------------------------------------------- /led30/cRGB.h: -------------------------------------------------------------------------------- 1 | #ifndef CRGB_H 2 | #define CRGB_H 3 | 4 | /* 5 | Control a RGB led with Hue, Saturation and Brightness (HSB / HSV ) 6 | 7 | Hue is change by an analog input. 8 | Brightness is changed by a fading function. 9 | Saturation stays constant at 255 10 | 11 | getRGB() function based on 12 | dim_curve idea by Jims 13 | 14 | created 05-01-2010 by kasperkamperman.com 15 | */ 16 | 17 | /* 18 | dim_curve 'lookup table' to compensate for the nonlinearity of human vision. 19 | Used in the getRGB function on saturation and brightness to make 'dimming' look more natural. 20 | Exponential function used to create values below : 21 | x from 0 - 255 : y = round(pow( 2.0, x+64/40.0) - 1) 22 | */ 23 | 24 | // uncomment this line if you use HSV is many projects 25 | // #define USE_HSV 26 | 27 | #ifdef USE_HSV 28 | const byte dim_curve[] = { 29 | 0, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 30 | 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 31 | 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 32 | 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 33 | 8, 8, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 11, 11, 11, 34 | 11, 11, 12, 12, 12, 12, 12, 13, 13, 13, 13, 14, 14, 14, 14, 15, 35 | 15, 15, 16, 16, 16, 16, 17, 17, 17, 18, 18, 18, 19, 19, 19, 20, 36 | 20, 20, 21, 21, 22, 22, 22, 23, 23, 24, 24, 25, 25, 25, 26, 26, 37 | 27, 27, 28, 28, 29, 29, 30, 30, 31, 32, 32, 33, 33, 34, 35, 35, 38 | 36, 36, 37, 38, 38, 39, 40, 40, 41, 42, 43, 43, 44, 45, 46, 47, 39 | 48, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 40 | 63, 64, 65, 66, 68, 69, 70, 71, 73, 74, 75, 76, 78, 79, 81, 82, 41 | 83, 85, 86, 88, 90, 91, 93, 94, 96, 98, 99, 101, 103, 105, 107, 109, 42 | 110, 112, 114, 116, 118, 121, 123, 125, 127, 129, 132, 134, 136, 139, 141, 144, 43 | 146, 149, 151, 154, 157, 159, 162, 165, 168, 171, 174, 177, 180, 183, 186, 190, 44 | 193, 196, 200, 203, 207, 211, 214, 218, 222, 226, 230, 234, 238, 242, 248, 255, 45 | }; 46 | #endif 47 | 48 | struct cRGB { 49 | uint8_t g; 50 | uint8_t r; 51 | uint8_t b; 52 | 53 | #ifdef USE_HSV 54 | void SetHSV(int hue, byte sat, byte val) { 55 | /* convert hue, saturation and brightness ( HSB/HSV ) to RGB 56 | The dim_curve is used only on brightness/value and on saturation (inverted). 57 | This looks the most natural. 58 | */ 59 | 60 | val = dim_curve[val]; 61 | sat = 255 - dim_curve[255 - sat]; 62 | 63 | int base; 64 | 65 | if (sat == 0) { // Acromatic color (gray). Hue doesn't mind. 66 | r = val; 67 | g = val; 68 | b = val; 69 | } 70 | else { 71 | base = ((255 - sat) * val) >> 8; 72 | 73 | switch (hue / 60) { 74 | case 0: 75 | r = val; 76 | g = (((val - base)*hue) / 60) + base; 77 | b = base; 78 | break; 79 | 80 | case 1: 81 | r = (((val - base)*(60 - (hue % 60))) / 60) + base; 82 | g = val; 83 | b = base; 84 | break; 85 | 86 | case 2: 87 | r = base; 88 | g = val; 89 | b = (((val - base)*(hue % 60)) / 60) + base; 90 | break; 91 | 92 | case 3: 93 | r = base; 94 | g = (((val - base)*(60 - (hue % 60))) / 60) + base; 95 | b = val; 96 | break; 97 | 98 | case 4: 99 | r = (((val - base)*(hue % 60)) / 60) + base; 100 | g = base; 101 | b = val; 102 | break; 103 | 104 | case 5: 105 | r = val; 106 | g = base; 107 | b = (((val - base)*(60 - (hue % 60))) / 60) + base; 108 | break; 109 | } 110 | } 111 | } 112 | #endif 113 | }; 114 | 115 | #endif -------------------------------------------------------------------------------- /old/blinky.c: -------------------------------------------------------------------------------- 1 | /* LED Bike Blirker for Teensy ATMEL Board 2 | * http://www.pjrc.com/teensy/ 3 | */ 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | #define CONFIG_OUT_B(n) (DDRB |= (1<