|
| 1 | +// -------------------------------------------------------------- |
| 2 | +// |
| 3 | +// B O O M Y T E C H |
| 4 | +// |
| 5 | +// SNAPPING DISPLAY |
| 6 | +// |
| 7 | +// YouTube: https://www.youtube.com/@boomytech7504 |
| 8 | +// |
| 9 | +// YOTUBE LINK TO THE VIDEO: https://youtu.be/Mb3xCe2Co3A |
| 10 | +// |
| 11 | +// EMail: boomytech@gmail.com |
| 12 | +// |
| 13 | +// -------------------------------------------------------------- |
| 14 | +// Segment sequence |
| 15 | +// aaaaa |
| 16 | +// f b |
| 17 | +// f b |
| 18 | +// ggggg |
| 19 | +// e c |
| 20 | +// e c |
| 21 | +// ddddd |
| 22 | +// dp |
| 23 | +// |
| 24 | +#include <Adafruit_NeoPixel.h> |
| 25 | +#include "Arduino.h" |
| 26 | +#include "BT_Display.h" |
| 27 | + |
| 28 | +Adafruit_NeoPixel pixel; |
| 29 | + |
| 30 | +// USER DEFINE PARAMETERS (must be defined in source file) |
| 31 | +// -------------------------------------------- |
| 32 | +byte digit_Brightness = 255; // Brightness |
| 33 | +unsigned int digit_Color = 3000; // HSV Digit Color |
| 34 | +byte digit_Active // Active Digit |
| 35 | +unsigned int totLedPerDigit; // led in a single digit |
| 36 | + |
| 37 | +// LED SCHEMA DEFINED BY USER (must be defined in source file) |
| 38 | +// -------------------------------------------- |
| 39 | +String _a,_b,_c,_d,_e,_f,_g,_dp; |
| 40 | +//eg. |
| 41 | +//disp._a = "3,4,5"; |
| 42 | +//disp._b = "0,1,2"; |
| 43 | +//disp._c = "12,13,14"; |
| 44 | +//disp._d = "16,17,18"; |
| 45 | +//disp._e = "19,20,21"; |
| 46 | +//disp._f = "6,7,8"; |
| 47 | +//disp._g = "9,10,11"; |
| 48 | +//disp._dp = "15"; |
| 49 | +// -------------------------------------------- |
| 50 | + |
| 51 | + |
| 52 | + |
| 53 | + |
| 54 | +// ---------------------------------------- |
| 55 | +// INIT |
| 56 | +// ---------------------------------------- |
| 57 | +void BTDisplay::init(int maxDisplays, int pinControl, unsigned int totLedPerDigit) { |
| 58 | + // Initialize neopixel library |
| 59 | + totLedPerDigit = totLedPerDigit; |
| 60 | + pixel = Adafruit_NeoPixel(maxDisplays*(totLedPerDigit), pinControl, NEO_GRB + NEO_KHZ800); |
| 61 | + pixel.begin(); |
| 62 | +} |
| 63 | + |
| 64 | +void BTDisplay::show() { |
| 65 | + pixel.show(); |
| 66 | +} |
| 67 | + |
| 68 | +// ---------------------------------------- |
| 69 | +// // SWITCH-ON/OFF A SINGLE SEGMENT |
| 70 | +// ---------------------------------------- |
| 71 | +void BTDisplay::ShowSeg(String segment, bool is_ON) { |
| 72 | + int pointer=0; |
| 73 | + int nextPointer=-1; |
| 74 | + String str=""; |
| 75 | + do { |
| 76 | + pointer=nextPointer+1; |
| 77 | + nextPointer = segment.indexOf(",",pointer); |
| 78 | + str = segment.substring(pointer, nextPointer).toInt(); |
| 79 | + pixel.setPixelColor(str.toInt()+(digit_Active * totLedPerDigit), pixel.ColorHSV(digit_Color, 255, is_ON ? digit_Brightness : 0 )); |
| 80 | + } while (nextPointer > 0); |
| 81 | +} |
| 82 | + |
| 83 | + |
| 84 | + |
| 85 | + |
| 86 | +// ---------------------------------------- |
| 87 | +// // SWITCH-ON SEGMENTS TO COMPOSE DIGIT |
| 88 | +// ---------------------------------------- |
| 89 | +void BTDisplay::digit_1() { ShowSeg(_a,0); ShowSeg(_b,1); ShowSeg(_c,1); ShowSeg(_d,0); ShowSeg(_e,0); ShowSeg(_f,0); ShowSeg(_g,0);} |
| 90 | +void BTDisplay::digit_2() { ShowSeg(_a,1); ShowSeg(_b,1); ShowSeg(_c,0); ShowSeg(_d,1); ShowSeg(_e,1); ShowSeg(_f,0); ShowSeg(_g,1);} |
| 91 | +void BTDisplay::digit_3() { ShowSeg(_a,1); ShowSeg(_b,1); ShowSeg(_c,1); ShowSeg(_d,1); ShowSeg(_e,0); ShowSeg(_f,0); ShowSeg(_g,1);} |
| 92 | +void BTDisplay::digit_4() { ShowSeg(_a,0); ShowSeg(_b,1); ShowSeg(_c,1); ShowSeg(_d,0); ShowSeg(_e,0); ShowSeg(_f,1); ShowSeg(_g,1);} |
| 93 | +void BTDisplay::digit_5() { ShowSeg(_a,1); ShowSeg(_b,0); ShowSeg(_c,1); ShowSeg(_d,1); ShowSeg(_e,0); ShowSeg(_f,1); ShowSeg(_g,1);} |
| 94 | +void BTDisplay::digit_6() { ShowSeg(_a,1); ShowSeg(_b,0); ShowSeg(_c,1); ShowSeg(_d,1); ShowSeg(_e,1); ShowSeg(_f,1); ShowSeg(_g,1);} |
| 95 | +void BTDisplay::digit_7() { ShowSeg(_a,1); ShowSeg(_b,1); ShowSeg(_c,1); ShowSeg(_d,0); ShowSeg(_e,0); ShowSeg(_f,0); ShowSeg(_g,0);} |
| 96 | +void BTDisplay::digit_8() { ShowSeg(_a,1); ShowSeg(_b,1); ShowSeg(_c,1); ShowSeg(_d,1); ShowSeg(_e,1); ShowSeg(_f,1); ShowSeg(_g,1);} |
| 97 | +void BTDisplay::digit_9() { ShowSeg(_a,1); ShowSeg(_b,1); ShowSeg(_c,1); ShowSeg(_d,1); ShowSeg(_e,0); ShowSeg(_f,1); ShowSeg(_g,1);} |
| 98 | +void BTDisplay::digit_0() { ShowSeg(_a,1); ShowSeg(_b,1); ShowSeg(_c,1); ShowSeg(_d,1); ShowSeg(_e,1); ShowSeg(_f,1); ShowSeg(_g,0);} |
| 99 | +void BTDisplay::digit_null() { ShowSeg(_a,0); ShowSeg(_b,0); ShowSeg(_c,0); ShowSeg(_d,0); ShowSeg(_e,0); ShowSeg(_f,0); ShowSeg(_g,0); |
| 100 | +} |
| 101 | + |
| 102 | + |
| 103 | +// ---------------------------------------- |
| 104 | +// SHOW RIGHT NUMBER ON SELECTED DIGIT (--display_Number--) |
| 105 | +// ---------------------------------------- |
| 106 | +void BTDisplay::digit(String str_digit) { |
| 107 | + if (str_digit == "") digit_null(); |
| 108 | + if (str_digit == "0") digit_0(); |
| 109 | + if (str_digit == "1") digit_1(); |
| 110 | + if (str_digit == "2") digit_2(); |
| 111 | + if (str_digit == "3") digit_3(); |
| 112 | + if (str_digit == "4") digit_4(); |
| 113 | + if (str_digit == "5") digit_5(); |
| 114 | + if (str_digit == "6") digit_6(); |
| 115 | + if (str_digit == "7") digit_7(); |
| 116 | + if (str_digit == "8") digit_8(); |
| 117 | + if (str_digit == "9") digit_9(); |
| 118 | + |
| 119 | +} |
| 120 | + |
| 121 | +// SWITCH OFF ALL SEGMENTS |
| 122 | +void BTDisplay::digit_ALL_off() { for (int i=0; i<=totLedPerDigit; i++) pixel.setPixelColor(i, pixel.ColorHSV(0,0,0)); } |
0 commit comments