|
| 1 | +//Displays all digits with the same number counting from 0 to 9. Odd numbers have decimal point ON, others OFF. |
| 2 | +//Push button on pin 5 to control color changing |
| 3 | +#include <Neo7Segment.h> |
| 4 | + |
| 5 | +#define PIXELS_DIGITS 5 // Number of digits |
| 6 | +#define PIXELS_PER_SEGMENT 4 // If you want more than 10 pixels per segment, modify the Neo7Segment_Var.cpp |
| 7 | +#define PIXELS_PER_POINT 1 // CANNOT be higher than PIXELS_PER_SEGMENT |
| 8 | +#define PIXELS_PIN 4 // Pin number |
| 9 | + |
| 10 | +// Initalise the display with 5 Neo7Segment boards, 4 LEDs per segment, 1 decimal point LED, connected to GPIO 4 |
| 11 | +Neo7Segment disp(PIXELS_DIGITS, PIXELS_PER_SEGMENT, PIXELS_PER_POINT, PIXELS_PIN); |
| 12 | + |
| 13 | +int loopIndex = 0; |
| 14 | +byte rainbowIndex = 0; |
| 15 | +unsigned long nextRainbow = 0; |
| 16 | +int displayFeature = 0; |
| 17 | +long nextCount = millis(); |
| 18 | + |
| 19 | +//Button pin define |
| 20 | +#define buttonPin 5 |
| 21 | + |
| 22 | +bool changeColor = false; |
| 23 | +bool buttonActive = false; |
| 24 | +int digitDisplay = 0; |
| 25 | + |
| 26 | +String text = ""; |
| 27 | + |
| 28 | +void setup() |
| 29 | +{ |
| 30 | + Serial.begin(9600); |
| 31 | + delay(1000); |
| 32 | + |
| 33 | + pinMode(buttonPin, INPUT); |
| 34 | + |
| 35 | + // Start the display with a brightness value of 20 |
| 36 | + disp.Begin(20); |
| 37 | + |
| 38 | + // Set the initial display feature to show as 0 |
| 39 | + displayFeature = 0; |
| 40 | +} |
| 41 | + |
| 42 | +void loop() |
| 43 | +{ |
| 44 | + // Wait until the display is initialised before we try to show anything |
| 45 | + if ( !disp.IsReady() ) |
| 46 | + return; |
| 47 | + |
| 48 | + readButtonPush(); |
| 49 | + |
| 50 | + if ( millis() > nextCount ) |
| 51 | + { |
| 52 | + digitDisplay += 1; |
| 53 | + nextCount = millis() + 1000; |
| 54 | + } |
| 55 | + |
| 56 | + if (digitDisplay > 9) |
| 57 | + digitDisplay = 0; |
| 58 | + |
| 59 | + String dot = ( ( digitDisplay%2 ) == 0 ) ? "." : ""; |
| 60 | + String digit = String( digitDisplay ); |
| 61 | + |
| 62 | + text = ""; |
| 63 | + for ( int i = 0; i < PIXELS_DIGITS; i++ ) |
| 64 | + text = text + digit + dot; |
| 65 | + |
| 66 | + // Switch sequence when pressing on button |
| 67 | + if ( changeColor ) |
| 68 | + displayFeature = (displayFeature + 1) % 13; |
| 69 | + |
| 70 | + // Display stuff on the Neo7Segment displays |
| 71 | + if (nextRainbow < millis() || changeColor) |
| 72 | + colorChangingSequences(); |
| 73 | + |
| 74 | + changeColor = false; |
| 75 | +} |
| 76 | + |
| 77 | +void colorChangingSequences() |
| 78 | +{ |
| 79 | + switch(displayFeature) |
| 80 | + { |
| 81 | + case 0: |
| 82 | + disp.DisplayTextColorCycle( text, rainbowIndex ); |
| 83 | + nextRainbow = millis() + 10; |
| 84 | + rainbowIndex++; |
| 85 | + break; |
| 86 | + |
| 87 | + case 1: |
| 88 | + disp.DisplayTextVerticalRainbow( text, disp.Color(255,0,0), disp.Color(0,0,255) ); |
| 89 | + nextRainbow = millis() + 10; |
| 90 | + break; |
| 91 | + |
| 92 | + case 2: |
| 93 | + nextRainbow = millis() + 250; |
| 94 | + rainbowIndex+=5; |
| 95 | + loopIndex++; |
| 96 | + if (loopIndex > 1) |
| 97 | + loopIndex = 0; |
| 98 | + |
| 99 | + disp.ForceUppercase( true ); |
| 100 | + disp.DisplayTextMarquee( text, loopIndex, disp.Wheel( rainbowIndex & 255 ) ); |
| 101 | + |
| 102 | + break; |
| 103 | + |
| 104 | + case 3: |
| 105 | + disp.ForceUppercase( false ); |
| 106 | + disp.DisplayTextVerticalRainbow( text, disp.Wheel( rainbowIndex & 255 ) , disp.Wheel( ( rainbowIndex + 50 ) & 255 ) ); |
| 107 | + nextRainbow = millis() + 10; |
| 108 | + rainbowIndex--; |
| 109 | + break; |
| 110 | + |
| 111 | + case 4: |
| 112 | + nextRainbow = millis() + 50; |
| 113 | + rainbowIndex+=5; |
| 114 | + loopIndex++; |
| 115 | + if ( loopIndex > ( PIXELS_PER_SEGMENT-1 ) ) |
| 116 | + loopIndex = 0; |
| 117 | + |
| 118 | + disp.DisplayTextChaser( text, loopIndex, disp.Wheel( rainbowIndex & 255 ) ); |
| 119 | + |
| 120 | + break; |
| 121 | + |
| 122 | + case 5: |
| 123 | + rainbowIndex++; |
| 124 | + |
| 125 | + if (rainbowIndex % 5 == 0) |
| 126 | + { |
| 127 | + loopIndex++; |
| 128 | + if (loopIndex >= disp.GetSpinAllLength()) |
| 129 | + loopIndex = 0; |
| 130 | + } |
| 131 | + |
| 132 | + disp.SetDigitSegments(0, disp.GetSpinAllAtIndex(loopIndex), disp.Color(0, 0, 50)); |
| 133 | + disp.SetDigitSegments(1, disp.GetSpinAllAtIndex(loopIndex), disp.Color(0, 0, 100)); |
| 134 | + disp.SetDigitSegments(2, disp.GetSpinAllAtIndex(loopIndex), disp.Color(0, 0, 150)); |
| 135 | + disp.SetDigitSegments(3, disp.GetSpinAllAtIndex(loopIndex), disp.Color(0, 0, 200)); |
| 136 | + disp.SetDigitSegments(4, disp.GetSpinAllAtIndex(loopIndex), disp.Color(0, 0, 250)); |
| 137 | + |
| 138 | + for (int i = 5; i<PIXELS_DIGITS; i++) |
| 139 | + disp.SetDigit(i, "", disp.Color(0, 0, 0)); |
| 140 | + |
| 141 | + nextRainbow = millis() + 10; |
| 142 | + break; |
| 143 | + |
| 144 | + case 6: |
| 145 | + if (rainbowIndex > (2*PIXELS_PER_SEGMENT*PIXELS_DIGITS)) |
| 146 | + rainbowIndex = 0; |
| 147 | + |
| 148 | + disp.DisplayKnightRider(rainbowIndex, disp.Color(255,0,255)); |
| 149 | + nextRainbow = millis() + 10; |
| 150 | + rainbowIndex++; |
| 151 | + break; |
| 152 | + |
| 153 | + case 7: |
| 154 | + disp.ForceUppercase(false); |
| 155 | + disp.DisplayTextHorizontalRainbow(text, disp.Wheel(rainbowIndex & 255) , disp.Wheel((rainbowIndex + 150) & 255)); |
| 156 | + nextRainbow = millis() + 50; |
| 157 | + rainbowIndex--; |
| 158 | + break; |
| 159 | + |
| 160 | + case 8:// |
| 161 | + disp.DisplayBorderAnimation(rainbowIndex, disp.Color(0, 0, 250)); |
| 162 | + nextRainbow = millis() + 100; |
| 163 | + rainbowIndex--; |
| 164 | + break; |
| 165 | + |
| 166 | + case 9: |
| 167 | + disp.DisplayTime((digitDisplay*10+digitDisplay), (digitDisplay*10+digitDisplay), digitDisplay, disp.Color(255, 200, 0), disp.Color(0, 0, 255)); |
| 168 | + nextRainbow = millis() + 500; |
| 169 | + break; |
| 170 | + |
| 171 | + case 10: |
| 172 | + disp.DisplayTextColorCycle(text, rainbowIndex); |
| 173 | + nextRainbow = millis() + 10; |
| 174 | + rainbowIndex++; |
| 175 | + break; |
| 176 | + |
| 177 | + case 11: // Same as case #5, but allows to send complete string and change each digit's color |
| 178 | + uint32_t digitColors[PIXELS_DIGITS]; |
| 179 | + digitColors[0] = disp.Color(255, 0, 0); |
| 180 | + digitColors[1] = disp.Color(127, 127, 0); |
| 181 | + digitColors[2] = disp.Color(0, 255, 0); |
| 182 | + digitColors[3] = disp.Color(0, 127, 127); |
| 183 | + digitColors[4] = disp.Color(0, 0, 255); |
| 184 | + |
| 185 | + for (int i = 5; i<PIXELS_DIGITS; i++) |
| 186 | + digitColors[i] = disp.Color(0, 0, 0); |
| 187 | + |
| 188 | + disp.DisplayTextDigitColor(text, digitColors); |
| 189 | + nextRainbow = millis() + 50; |
| 190 | + rainbowIndex++; |
| 191 | + break; |
| 192 | + |
| 193 | + case 12: // Same as case #5, but allows to send string character (only first will be used) and change only one digit at a time |
| 194 | + disp.SetDigit(0, text, disp.Color(0, 0, 255)); |
| 195 | + disp.SetDigit(1, text, disp.Color(0, 127, 127)); |
| 196 | + disp.SetDigit(2, text, disp.Color(0, 255, 0)); |
| 197 | + disp.SetDigit(3, text, disp.Color(127, 127, 0)); |
| 198 | + disp.SetDigit(4, text, disp.Color(255, 0, 0)); |
| 199 | + |
| 200 | + nextRainbow = millis() + 50; |
| 201 | + rainbowIndex++; |
| 202 | + break; |
| 203 | + |
| 204 | + default: |
| 205 | + displayFeature = 0; |
| 206 | + break; |
| 207 | + } |
| 208 | +} |
| 209 | + |
| 210 | +void readButtonPush() |
| 211 | +{ |
| 212 | + bool buttonPressed = !digitalRead(buttonPin); |
| 213 | + if (buttonPressed) |
| 214 | + { |
| 215 | + if (!buttonActive) |
| 216 | + buttonActive = true; |
| 217 | + } |
| 218 | + else |
| 219 | + { |
| 220 | + if (buttonActive) |
| 221 | + changeColor = true; |
| 222 | + |
| 223 | + buttonActive = false; |
| 224 | + } |
| 225 | +} |
0 commit comments