Skip to content

Commit

Permalink
Merge pull request #2 from SupremeSports/feature-01
Browse files Browse the repository at this point in the history
Upgraded to variable pixels per segment/decimal
  • Loading branch information
UnexpectedMaker authored Jan 20, 2019
2 parents c07b953 + 51a179b commit 897d1e5
Show file tree
Hide file tree
Showing 6 changed files with 693 additions and 208 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,16 @@ You can then initialise the display with the following line that includes the nu

Neo7Segment disp( 5, 4 );

You can also initialise the display with custom pixels per segment and pixel per decimal point

#define PIXELS_DIGITS 5 // Number of digits
#define PIXELS_PER_SEGMENT 4 // Pixels per segment - If you want more than 10 pixels per segment, modify the Neo7Segment.cpp
#define PIXELS_PER_POINT 1 // Pixels per decimal point - CANNOT be higher than PIXELS_PER_SEGMENT
#define PIXELS_PIN 4 // Pin number

// Initalise the display with 5 Neo7Segment boards, 4 LEDs per segment, 1 decimal point LED, connected to GPIO 4
Neo7Segment disp(PIXELS_DIGITS, PIXELS_PER_SEGMENT, PIXELS_PER_POINT, PIXELS_PIN);

You then start the display with the bebin method, passing the brightness:

disp.Begin(20);
Expand Down
225 changes: 225 additions & 0 deletions examples/Neo7Segment_Counter/Neo7Segment_Counter.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,225 @@
//Displays all digits with the same number counting from 0 to 9. Odd numbers have decimal point ON, others OFF.
//Push button on pin 5 to control color changing
#include <Neo7Segment.h>

#define PIXELS_DIGITS 5 // Number of digits
#define PIXELS_PER_SEGMENT 4 // If you want more than 10 pixels per segment, modify the Neo7Segment_Var.cpp
#define PIXELS_PER_POINT 1 // CANNOT be higher than PIXELS_PER_SEGMENT
#define PIXELS_PIN 4 // Pin number

// Initalise the display with 5 Neo7Segment boards, 4 LEDs per segment, 1 decimal point LED, connected to GPIO 4
Neo7Segment disp(PIXELS_DIGITS, PIXELS_PER_SEGMENT, PIXELS_PER_POINT, PIXELS_PIN);

int loopIndex = 0;
byte rainbowIndex = 0;
unsigned long nextRainbow = 0;
int displayFeature = 0;
long nextCount = millis();

//Button pin define
#define buttonPin 5

bool changeColor = false;
bool buttonActive = false;
int digitDisplay = 0;

String text = "";

void setup()
{
Serial.begin(9600);
delay(1000);

pinMode(buttonPin, INPUT);

// Start the display with a brightness value of 20
disp.Begin(20);

// Set the initial display feature to show as 0
displayFeature = 0;
}

void loop()
{
// Wait until the display is initialised before we try to show anything
if ( !disp.IsReady() )
return;

readButtonPush();

if ( millis() > nextCount )
{
digitDisplay += 1;
nextCount = millis() + 1000;
}

if (digitDisplay > 9)
digitDisplay = 0;

String dot = ( ( digitDisplay%2 ) == 0 ) ? "." : "";
String digit = String( digitDisplay );

text = "";
for ( int i = 0; i < PIXELS_DIGITS; i++ )
text = text + digit + dot;

// Switch sequence when pressing on button
if ( changeColor )
displayFeature = (displayFeature + 1) % 13;

// Display stuff on the Neo7Segment displays
if (nextRainbow < millis() || changeColor)
colorChangingSequences();

changeColor = false;
}

void colorChangingSequences()
{
switch(displayFeature)
{
case 0:
disp.DisplayTextColorCycle( text, rainbowIndex );
nextRainbow = millis() + 10;
rainbowIndex++;
break;

case 1:
disp.DisplayTextVerticalRainbow( text, disp.Color(255,0,0), disp.Color(0,0,255) );
nextRainbow = millis() + 10;
break;

case 2:
nextRainbow = millis() + 250;
rainbowIndex+=5;
loopIndex++;
if (loopIndex > 1)
loopIndex = 0;

disp.ForceUppercase( true );
disp.DisplayTextMarquee( text, loopIndex, disp.Wheel( rainbowIndex & 255 ) );

break;

case 3:
disp.ForceUppercase( false );
disp.DisplayTextVerticalRainbow( text, disp.Wheel( rainbowIndex & 255 ) , disp.Wheel( ( rainbowIndex + 50 ) & 255 ) );
nextRainbow = millis() + 10;
rainbowIndex--;
break;

case 4:
nextRainbow = millis() + 50;
rainbowIndex+=5;
loopIndex++;
if ( loopIndex > ( PIXELS_PER_SEGMENT-1 ) )
loopIndex = 0;

disp.DisplayTextChaser( text, loopIndex, disp.Wheel( rainbowIndex & 255 ) );

break;

case 5:
rainbowIndex++;

if (rainbowIndex % 5 == 0)
{
loopIndex++;
if (loopIndex >= disp.GetSpinAllLength())
loopIndex = 0;
}

disp.SetDigitSegments(0, disp.GetSpinAllAtIndex(loopIndex), disp.Color(0, 0, 50));
disp.SetDigitSegments(1, disp.GetSpinAllAtIndex(loopIndex), disp.Color(0, 0, 100));
disp.SetDigitSegments(2, disp.GetSpinAllAtIndex(loopIndex), disp.Color(0, 0, 150));
disp.SetDigitSegments(3, disp.GetSpinAllAtIndex(loopIndex), disp.Color(0, 0, 200));
disp.SetDigitSegments(4, disp.GetSpinAllAtIndex(loopIndex), disp.Color(0, 0, 250));

for (int i = 5; i<PIXELS_DIGITS; i++)
disp.SetDigit(i, "", disp.Color(0, 0, 0));

nextRainbow = millis() + 10;
break;

case 6:
if (rainbowIndex > (2*PIXELS_PER_SEGMENT*PIXELS_DIGITS))
rainbowIndex = 0;

disp.DisplayKnightRider(rainbowIndex, disp.Color(255,0,255));
nextRainbow = millis() + 10;
rainbowIndex++;
break;

case 7:
disp.ForceUppercase(false);
disp.DisplayTextHorizontalRainbow(text, disp.Wheel(rainbowIndex & 255) , disp.Wheel((rainbowIndex + 150) & 255));
nextRainbow = millis() + 50;
rainbowIndex--;
break;

case 8://
disp.DisplayBorderAnimation(rainbowIndex, disp.Color(0, 0, 250));
nextRainbow = millis() + 100;
rainbowIndex--;
break;

case 9:
disp.DisplayTime((digitDisplay*10+digitDisplay), (digitDisplay*10+digitDisplay), digitDisplay, disp.Color(255, 200, 0), disp.Color(0, 0, 255));
nextRainbow = millis() + 500;
break;

case 10:
disp.DisplayTextColorCycle(text, rainbowIndex);
nextRainbow = millis() + 10;
rainbowIndex++;
break;

case 11: // Same as case #5, but allows to send complete string and change each digit's color
uint32_t digitColors[PIXELS_DIGITS];
digitColors[0] = disp.Color(255, 0, 0);
digitColors[1] = disp.Color(127, 127, 0);
digitColors[2] = disp.Color(0, 255, 0);
digitColors[3] = disp.Color(0, 127, 127);
digitColors[4] = disp.Color(0, 0, 255);

for (int i = 5; i<PIXELS_DIGITS; i++)
digitColors[i] = disp.Color(0, 0, 0);

disp.DisplayTextDigitColor(text, digitColors);
nextRainbow = millis() + 50;
rainbowIndex++;
break;

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
disp.SetDigit(0, text, disp.Color(0, 0, 255));
disp.SetDigit(1, text, disp.Color(0, 127, 127));
disp.SetDigit(2, text, disp.Color(0, 255, 0));
disp.SetDigit(3, text, disp.Color(127, 127, 0));
disp.SetDigit(4, text, disp.Color(255, 0, 0));

nextRainbow = millis() + 50;
rainbowIndex++;
break;

default:
displayFeature = 0;
break;
}
}

void readButtonPush()
{
bool buttonPressed = !digitalRead(buttonPin);
if (buttonPressed)
{
if (!buttonActive)
buttonActive = true;
}
else
{
if (buttonActive)
changeColor = true;

buttonActive = false;
}
}
66 changes: 55 additions & 11 deletions examples/Neo7Segment_Demo/Neo7Segment_Demo.ino
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
//Displays different designs
//Changes feature every 5 seconds
#include <Neo7Segment.h>

// Initalise the display with 5 Neo7Segment boards connected to GPIO 4
Neo7Segment disp( 5, 4 );
#define PIXELS_DIGITS 5 // Number of digits
#define PIXELS_PER_SEGMENT 4 // Pixels per segment - If you want more than 10 pixels per segment, modify the Neo7Segment_Var.cpp
#define PIXELS_PER_POINT 1 // Pixels per decimal point - CANNOT be higher than PIXELS_PER_SEGMENT
#define PIXELS_PIN 4 // Pin number

// Initalise the display with 5 Neo7Segment boards, 4 LEDs per segment, 1 decimal point LED, connected to GPIO 4
Neo7Segment disp(PIXELS_DIGITS, PIXELS_PER_SEGMENT, PIXELS_PER_POINT, PIXELS_PIN);

int loopIndex = 0;
byte rainbowIndex = 0;
unsigned long nextRainbow = 0;
int displayFeature = 0;
int nextSwitch = 10000;
long nextSwitch = millis();

void setup()
{
Expand All @@ -34,12 +41,16 @@ void loop()
if ( millis() > nextSwitch )
{
nextSwitch = millis() + 5000;
displayFeature = ( displayFeature + 1 ) % 11;
displayFeature = ( displayFeature + 1 ) % 13;
}

// Display stuff on the Neo7Segment displays
if ( nextRainbow < millis() )
{
colorChangingSequences();
}

void colorChangingSequences()
{
switch( displayFeature )
{
case 0:
Expand Down Expand Up @@ -97,7 +108,7 @@ void loop()
nextRainbow = millis() + 25;
rainbowIndex+=5;
loopIndex++;
if ( loopIndex > 3 )
if ( loopIndex > ( PIXELS_PER_SEGMENT-1 ) )
loopIndex = 0;

disp.DisplayTextChaser("lolol", loopIndex, disp.Wheel( rainbowIndex & 255 ) );
Expand All @@ -106,11 +117,11 @@ void loop()

case 5:
rainbowIndex++;

if ( rainbowIndex % 5 == 0 )
{
loopIndex++;
if ( loopIndex == disp.GetSpinAllLength() )
if ( loopIndex >= disp.GetSpinAllLength() )
loopIndex = 0;
}

Expand All @@ -119,9 +130,17 @@ void loop()
disp.SetDigitSegments( 2, disp.GetSpinAllAtIndex( loopIndex ), disp.Color(0, 0, 150) );
disp.SetDigitSegments( 3, disp.GetSpinAllAtIndex( loopIndex ), disp.Color(0, 0, 200) );
disp.SetDigitSegments( 4, disp.GetSpinAllAtIndex( loopIndex ), disp.Color(0, 0, 250) );

for (int i = 5; i<PIXELS_DIGITS; i++)
disp.SetDigit(i, "", disp.Color(0, 0, 0));

nextRainbow = millis() + 10;
break;

case 6:
if (rainbowIndex > (2*PIXELS_PER_SEGMENT*PIXELS_DIGITS))
rainbowIndex = 0;

disp.DisplayKnightRider( rainbowIndex, disp.Color(255,0,255) );
nextRainbow = millis() + 80;
rainbowIndex++;
Expand All @@ -147,12 +166,37 @@ void loop()
break;

case 10:
disp.DisplayTextColorCycle( "0....0", rainbowIndex );
disp.DisplayTextColorCycle( "0....0 ", rainbowIndex );
nextRainbow = millis() + 10;
rainbowIndex++;
break;

case 11: // Same as case #5, but allows to send complete string and change each digit's color
uint32_t digitColors[PIXELS_DIGITS];
digitColors[0] = disp.Color(255, 0, 0);
digitColors[1] = disp.Color(127, 127, 0);
digitColors[2] = disp.Color(0, 255, 0);
digitColors[3] = disp.Color(0, 127, 127);
digitColors[4] = disp.Color(0, 0, 255);

disp.DisplayTextDigitColor("8.8.8.8.8.", digitColors);
nextRainbow = millis() + 50;
rainbowIndex++;
break;

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
disp.SetDigit(0, "5", disp.Color(0, 0, 255));
disp.SetDigit(1, "4", disp.Color(0, 127, 127));
disp.SetDigit(2, "3", disp.Color(0, 255, 0));
disp.SetDigit(3, "2", disp.Color(127, 127, 0));
disp.SetDigit(4, "1", disp.Color(255, 0, 0));

nextRainbow = millis() + 50;
rainbowIndex++;
break;

default:
displayFeature = 0;
break;
}
}
}

2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=Neo7Segment
version=1.0.1
version=2.0.3
author=UnexpectedMaker
maintainer=UnexpectedMaker
sentence=A library to display numbers and letters on Neo7Segment displays.
Expand Down
Loading

0 comments on commit 897d1e5

Please sign in to comment.