/* This Program Controls up to 4 7 Segment displays using OSC messages to commuincate
IP address must be unique and the Port number must match that of the sending software
OSC Message structure as follows
/display/digit xxxx the x represents the digit to be displayed
/display/clear
/display/colour xxx xxx xxx x represents the RGB Colour values between 0 and 255
*/
#include <Adafruit_NeoPixel.h>
#define PIN 6 // Define the pin where your NeoPixels are connected
#define NUM_LEDS 113 // Total number of NeoPixels
void clearDisplay();
void displayNumber(int number);
void displayDoubleDigit(int thousandsDigit, int hundredsDigit, int tensDigit, int onesDigit, int tensOffset, int hundredsOffset, int thousandsOffset);
int RED = 255;
int GREEN = 255;
int BLUE = 255;
int CURINT = 0;
Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUM_LEDS, PIN, NEO_GRB + NEO_KHZ800);
// Define LED configurations for each digit (0-9) using binary notation
const uint64_t digitLEDs[10] = {
0b11111111000000000000000000000000000000000000000000000000ULL, // d
0b00000000111111110000000000000000000000000000000000000000ULL, // d
0b00000000000000001111111100000000000000000000000000000000ULL, // d
0b00000000000000000000000011111111000000000000000000000000ULL, // d
0b00000000000000000000000000000000111111110000000000000000ULL, // d
0b00000000000000000000000000000000000000001111111100000000ULL, // d
0b00000000000000000000000000000000000000000000000011111111ULL, // d
0b11111111111111111111111111111111111111111111111100000000ULL, // 0
0b00000000111111111111111100000000000000000000000000000000ULL, // 1
0b00000000000000001111111111111111111111111111111111111111ULL, // 2
0b11111111000000000000000011111111111111111111111111111111ULL, // 3
0b11111111111111110000000000000000000000001111111111111111ULL, // 4
0b11111111111111110000000011111111111111110000000011111111ULL, // 5
0b11111111111111111111111111111111000000000000000011111111ULL, // 6
0b11111111000000000000000000000000111111111111111100000000ULL, // 7
0b11111111111111111111111111111111111111111111111111111111ULL, // 8
0b11111111111111110000000000000000111111111111111111111111ULL // 9
};
int displayedNumber = -1;
void setup() {
strip.begin();
strip.show(); // Initialize all pixels to 'off'
Serial.begin(9600);
Serial.println("Zero");
Serial.println("One");
displayNumber(2);
}
void loop() {
}
void displayNumber(int number) {
int thousandsDigit = number / 1000;
int hundredsDigit = (number % 1000)/100;
int tensDigit = (number % 100)/10;
int onesDigit = number % 10;
Serial.println(onesDigit);
Serial.println(tensDigit);
Serial.println(hundredsDigit);
Serial.println(thousandsDigit);
displayDoubleDigit(thousandsDigit, hundredsDigit, tensDigit, onesDigit, 56, 112, 168);
}
void displayDoubleDigit(int thousandsDigit, int hundredsDigit, int tensDigit, int onesDigit, int tensOffset, int hundredsOffset, int thousandsOffset) {
if (
tensDigit >= 0 && tensDigit <= 9
&& onesDigit >= 0 && onesDigit <= 9
&& hundredsDigit >= 0 && hundredsDigit <= 9
&& thousandsDigit >= 0 && thousandsDigit <= 9
) {
uint64_t thousandsConfig = digitLEDs[thousandsDigit];
uint64_t hundredsConfig = digitLEDs[hundredsDigit];
uint64_t tensConfig = digitLEDs[tensDigit];
uint64_t onesConfig = digitLEDs[onesDigit];
for (int i = 0; i < 57; i++) {
if (thousandsConfig & (1ULL << i)) {
int ledIndex = i + thousandsOffset;
strip.setPixelColor(ledIndex, strip.Color(RED, GREEN, BLUE)); // Turn on the LEDs for the ones digit with 56x3 offset
}
if (hundredsConfig & (1ULL << i)) {
int ledIndex = i + hundredsOffset;
strip.setPixelColor(ledIndex, strip.Color(RED, GREEN, BLUE)); // Turn on the LEDs for the ones digit with 56x2 offset
}
if (tensConfig & (1ULL << i)) {
int ledIndex = i + tensOffset;
strip.setPixelColor(ledIndex, strip.Color(RED, GREEN, BLUE)); // Turn on the LEDs for the tens digit with 56 Offset
}
if (onesConfig & (1ULL << i)) {
strip.setPixelColor(i, strip.Color(RED, GREEN, BLUE)); // Turn on the LEDs for the ones digit No Offset
}
}
strip.show();
}
}
void clearDisplay() {
Serial.println("Clearing Display");
for (int i = 0; i < NUM_LEDS; i++) {
strip.setPixelColor(i, strip.Color(0, 0, 0)); // Turn off all LEDs
}
strip.show();
}