#include <FastLED.h>
#define DATA_PIN 23 // Pin where the data line is connected
#define NUM_LEDS 21 // Number of LEDs
#define LED_TYPE WS2812B // Type of LED
#define COLOR_ORDER GRB // Color order for WS2812B
CRGB leds[NUM_LEDS]; // Array to hold LED data
// Define the segments for each number/letter (abcdefg)
byte segments[12] = {
0b0111111, // 0
0b0000110, // 1
0b1011011, // 2
0b1001111, // 3
0b1100110, // 4
0b1101101, // 5
0b1111101, // 6
0b0000111, // 7
0b1111111, // 8
0b1101111, // 9
0b0111001, // C
0b1110001 // F
};
void setup() {
Serial.begin(9600); // Start the Serial communication
FastLED.addLeds<LED_TYPE, DATA_PIN, COLOR_ORDER>(leds, NUM_LEDS);
FastLED.clear(); // Initialize all pixels to 'off'
FastLED.show();
}
void loop() {
if (Serial.available() > 0) {
char input = Serial.read(); // Read the input character
displayCharacter(input);
}
}
void displayCharacter(char input) {
// Clear the previous display
FastLED.clear();
// Convert the character to the corresponding number/letter
int num = -1; // Initialize to an invalid number
if (input >= '0' && input <= '9') {
num = input - '0'; // Convert '0'-'9' to 0-9
} else if (input == 'C') {
num = 10; // Set for character 'C'
} else if (input == 'F') {
num = 11; // Set for character 'F'
}
// If the input is valid, display it
if (num >= 0 && num < 12) {
// Map the segments to the corresponding LEDs
for (int seg = 0; seg < 7; seg++) {
// Each segment corresponds to 3 LEDs
int ledIndex = seg * 3; // Starting LED index for the segment
// Check if the segment is on
if (segments[num] & (1 << seg)) {
// Light up the segment
for (int i = 0; i < 3; i++) {
leds[ledIndex + i] = CRGB::Blue; // Turn on LEDs for this segment
}
}
}
FastLED.show(); // Update the strip
}
}