-
Notifications
You must be signed in to change notification settings - Fork 46
/
CRGBSet_7segment_2digits.ino
128 lines (106 loc) · 4.6 KB
/
CRGBSet_7segment_2digits.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
//***************************************************************
// Two digit seven segment number display example using CRGBArray and CRGBSet.
// A number from 0-99 can be displayed. This demo repeats counting from 0 to 25.
//
// For this example the number segments are wired in the following layout:
// http://imgur.com/cgabMfK
// It also assumes that each segment has the same number of pixels. There is
// a variable below which allows the number of pixels per segment to be changed.
//
// This example uses 5 Pixels Per Segment (pps).
// 5pps x 7segments x 2digits = 70 pixels total
//
//
// Marc Miller, Oct 2016
// (There is also a 3digit version of this sketch now, added Feb 2019.)
//***************************************************************
#include "FastLED.h"
#define DATA_PIN 11
#define CLK_PIN 13
#define LED_TYPE APA102
#define COLOR_ORDER BGR
#define NUM_LEDS 70
#define BRIGHTNESS 40
#define FRAMES_PER_SECOND 120
uint8_t pps = 5; // number of Pixels Per Segment
CHSV segON10(142,200,255); // color of 10s digit segments
CHSV segON(42,255,255); // color of 1s digit segments
/* CRGB leds[NUM_LEDS]; <--not using this. Using CRGBArray instead. */
CRGBArray<NUM_LEDS> leds;
// Name segments (based on layout in link above) and define pixel ranges.
CRGBSet segA( leds(pps*0, pps-1+(pps*0) ));
CRGBSet segB( leds(pps*1, pps-1+(pps*1) ));
CRGBSet segC( leds(pps*2, pps-1+(pps*2) ));
CRGBSet segD( leds(pps*3, pps-1+(pps*3) ));
CRGBSet segE( leds(pps*4, pps-1+(pps*4) ));
CRGBSet segF( leds(pps*5, pps-1+(pps*5) ));
CRGBSet segG( leds(pps*6, pps-1+(pps*6) ));
uint8_t count = 0; // keeps track of what number to display
//---------------------------------------------------------------
void setup() {
Serial.begin(115200); // Allows serial monitor output (check baud rate)
delay(3000); // 3 second delay for recovery
//FastLED.addLeds<LED_TYPE,DATA_PIN,COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
FastLED.addLeds<LED_TYPE,DATA_PIN,CLK_PIN,COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
FastLED.setBrightness(BRIGHTNESS);
FastLED.clear(); // Initially clear all pixels
}
//---------------------------------------------------------------
void loop()
{
EVERY_N_MILLISECONDS(1000){
setSegments(count); // Determine which segments are ON or OFF
count++; // Advance the count by one
if (count > 25) { count = 0; } // Reset count back to zero
}
FastLED.delay(1000/FRAMES_PER_SECOND);
}
//---------------------------------------------------------------
void setSegments(uint8_t count){
// Based on the current count set number segments on or off
uint8_t c1 = 0; // Variable to store 1s digit
uint8_t c10 = 0; // Variable to store 10s digit
uint8_t c;
CHSV segCOLOR(0,0,0);
if (count > 9) { // Split out 1s and 10s digits if count is greater then 9
c1 = count % 10;
c10 = count / 10;
} else {
c1 = count;
c10 = 0;
}
//Serial.print("count = "); Serial.print(count); // Print to serial monitor current count
//Serial.print("\t 10s: "); Serial.print(c10); // Print 10s digit
//Serial.print(" 1s: "); Serial.println(c1); // Print 1s digit
// Operate on 1s digit segments first, shift them over, and then do the 10s digit segments
for (uint8_t i=0; i < 2; i++) {
if (i == 0) {
c = c1;
segCOLOR = segON;
} else {
c = c10;
segCOLOR = segON10;
}
segA = segB = segC = segD = segE = segF = segG = CRGB::Black; // Initially set segments off
if (c == 0) { segB = segC = segD = segE = segF = segG = segCOLOR; }
if (c == 1) { segB = segG = segCOLOR; }
if (c == 2) { segA = segB = segC = segE = segF = segCOLOR; }
if (c == 3) { segA = segB = segC = segF = segG = segCOLOR; }
if (c == 4) { segA = segB = segD = segG = segCOLOR; }
if (c == 5) { segA = segC = segD = segF = segG = segCOLOR; }
if (c == 6) { segA = segC = segD = segE = segF = segG = segCOLOR; }
if (c == 7) { segB = segC = segG = segCOLOR; }
if (c == 8) { segA = segB = segC = segD = segE = segF = segG = segCOLOR; }
if (c == 9) { segA = segB = segC = segD = segF = segG = segCOLOR; }
if (i == 0) { // Shift segments over to 1s digit display area
for (uint8_t p=0; p < (7*pps); p++) {
leds[p+(7*pps)] = leds[p];
}
}
//----Comment this out if you want the 10s digit to display zeros----
if (c10 == 0 && i == 1) { // If count is less then 10 set all 10s digit segments off
segA = segB = segC = segD = segE = segF = segG = CRGB::Black;
}
//-------------------------------------------------------------------
}
}//end setSegments