mirror of
https://github.com/dekuNukem/exixe.git
synced 2025-10-31 11:17:03 -07:00
adding library installtion instructions
This commit is contained in:
@@ -34,10 +34,17 @@ void loop()
|
||||
my_tube1.crossfade_init(count, 15, 127, 0);
|
||||
my_tube2.crossfade_init(10-count, 15, 127, 0);
|
||||
|
||||
/*
|
||||
again, crossfade_run() is non-blocking, that means
|
||||
you can run other tasks in the loop.
|
||||
just make sure to call it at least every 33ms
|
||||
and check its return value to see if it's finished.
|
||||
*/
|
||||
while(1)
|
||||
{
|
||||
unsigned char result1 = my_tube1.crossfade_run();
|
||||
unsigned char result2 = my_tube2.crossfade_run();
|
||||
// exit when both animations are finished
|
||||
if(result1 == EXIXE_ANIMATION_FINISHED && result2 == EXIXE_ANIMATION_FINISHED)
|
||||
break;
|
||||
}
|
||||
|
||||
BIN
arduino_library/exixe.zip
Normal file
BIN
arduino_library/exixe.zip
Normal file
Binary file not shown.
@@ -1,35 +0,0 @@
|
||||
/*
|
||||
Demo for exixe modules
|
||||
https://github.com/dekuNukem/exixe
|
||||
|
||||
exixe "Getting Started" guide
|
||||
https://github.com/dekuNukem/exixe/blob/master/getting_started.md
|
||||
|
||||
Demo 2: loop digits
|
||||
*/
|
||||
|
||||
#include "exixe.h"
|
||||
|
||||
// change this to the cs pin you're using
|
||||
int cs_pin = 10;
|
||||
unsigned char count;
|
||||
|
||||
exixe my_tube = exixe(cs_pin);
|
||||
|
||||
void setup()
|
||||
{
|
||||
my_tube.clear();
|
||||
my_tube.set_led(127, 0, 127); // purple
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
count++;
|
||||
/*
|
||||
1st arg: Digit to show, 0 to 9
|
||||
2nd arg: Digit brightness, 0 to 127
|
||||
3rd arg: Overdrive, 0 disable 1 enable
|
||||
*/
|
||||
my_tube.show_digit(count, 127, 0);
|
||||
delay(500);
|
||||
}
|
||||
@@ -1,44 +0,0 @@
|
||||
/*
|
||||
Demo for exixe modules
|
||||
https://github.com/dekuNukem/exixe
|
||||
|
||||
exixe "Getting Started" guide
|
||||
https://github.com/dekuNukem/exixe/blob/master/getting_started.md
|
||||
|
||||
Demo 3: Loop digits with crossfade animation
|
||||
*/
|
||||
|
||||
#include "exixe.h"
|
||||
|
||||
// change this to the cs pin you're using
|
||||
int cs_pin = 10;
|
||||
unsigned char count;
|
||||
exixe my_tube = exixe(cs_pin);
|
||||
|
||||
void setup()
|
||||
{
|
||||
my_tube.clear();
|
||||
my_tube.set_led(127, 0, 127); // purple
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
count++;
|
||||
/*
|
||||
1st arg: Digit to show, 0 to 9
|
||||
2nd arg: how many frames does crossfade last, 30 frames = 1 second
|
||||
3rd arg: digit brightness, 0 to 127
|
||||
4th arg: overdrive, 0 disable 1 enable
|
||||
|
||||
This function sets up the crossfade animation
|
||||
call crossfade_run() to actually start it
|
||||
*/
|
||||
my_tube.crossfade_init(count, 15, 127, 0);
|
||||
|
||||
// crossfade_run() is non-blocking and returns right away
|
||||
// call it regularly(at least every 33ms) for a smooth animation
|
||||
// check its return value to see if the animation is finished
|
||||
while(my_tube.crossfade_run() == EXIXE_ANIMATION_IN_PROGRESS)
|
||||
;
|
||||
delay(250);
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
/*
|
||||
Demo for exixe modules
|
||||
https://github.com/dekuNukem/exixe
|
||||
|
||||
exixe "Getting Started" guide
|
||||
https://github.com/dekuNukem/exixe/blob/master/getting_started.md
|
||||
|
||||
Demo 4: Loop digits on two tubes
|
||||
*/
|
||||
|
||||
|
||||
#include "exixe.h"
|
||||
|
||||
// change those to the cs pins you're using
|
||||
int cs1 = 10;
|
||||
int cs2 = 9;
|
||||
unsigned char count;
|
||||
|
||||
exixe my_tube1 = exixe(cs1);
|
||||
exixe my_tube2 = exixe(cs2);
|
||||
|
||||
void setup()
|
||||
{
|
||||
my_tube1.clear();
|
||||
my_tube2.clear();
|
||||
my_tube1.set_led(127, 0, 127); // purple;
|
||||
my_tube2.set_led(127, 127, 0); // yellow;
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
count = (count + 1) % 10; // keep count between 0 to 9
|
||||
my_tube1.show_digit(count, 127, 0);
|
||||
my_tube2.show_digit(10 - count, 127, 0);
|
||||
delay(500);
|
||||
}
|
||||
@@ -1,46 +0,0 @@
|
||||
/*
|
||||
Demo for exixe modules
|
||||
https://github.com/dekuNukem/exixe
|
||||
|
||||
exixe "Getting Started" guide
|
||||
https://github.com/dekuNukem/exixe/blob/master/getting_started.md
|
||||
|
||||
Demo 5: Loop digits on two tubes with crossfade animation
|
||||
*/
|
||||
|
||||
|
||||
#include "exixe.h"
|
||||
|
||||
// change those to the cs pins you're using
|
||||
int cs1 = 10;
|
||||
int cs2 = 9;
|
||||
unsigned char count;
|
||||
|
||||
exixe my_tube1 = exixe(cs1);
|
||||
exixe my_tube2 = exixe(cs2);
|
||||
|
||||
void setup()
|
||||
{
|
||||
my_tube1.clear();
|
||||
my_tube2.clear();
|
||||
my_tube1.set_led(127, 0, 127); // purple;
|
||||
my_tube2.set_led(127, 127, 0); // yellow;
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
count = (count + 1) % 10; // keep count between 0 to 9
|
||||
|
||||
my_tube1.crossfade_init(count, 15, 127, 0);
|
||||
my_tube2.crossfade_init(10-count, 15, 127, 0);
|
||||
|
||||
while(1)
|
||||
{
|
||||
unsigned char result1 = my_tube1.crossfade_run();
|
||||
unsigned char result2 = my_tube2.crossfade_run();
|
||||
if(result1 == EXIXE_ANIMATION_FINISHED && result2 == EXIXE_ANIMATION_FINISHED)
|
||||
break;
|
||||
}
|
||||
|
||||
delay(250);
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
#include "exixe.h"
|
||||
|
||||
// change this to the cs pin you're using
|
||||
int cs_pin = 10;
|
||||
unsigned char count;
|
||||
|
||||
exixe my_tube = exixe(cs_pin);
|
||||
|
||||
void setup()
|
||||
{
|
||||
;
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
count++;
|
||||
/*
|
||||
1st arg: Digit to show, 0 to 9
|
||||
2nd arg: Digit brightness, 0 to 127
|
||||
3rd arg: Backlight red, 0 to 127
|
||||
4th arg: Backlight green, 0 to 127
|
||||
5th arg: Backlight blue, 0 to 127
|
||||
6th arg: Overdrive, 0 disable 1 enable
|
||||
*/
|
||||
my_tube.show(count, 127, 127, 0, 127, 0);
|
||||
delay(500);
|
||||
}
|
||||
@@ -17,7 +17,6 @@ exixe::exixe(int my_cs)
|
||||
digitalWrite(cs_pin, HIGH);
|
||||
SPI.begin();
|
||||
SPI.beginTransaction(SPISettings(8000000, MSBFIRST, SPI_MODE0));
|
||||
show_digit(0, 0, 0);
|
||||
}
|
||||
|
||||
void exixe::spi_write()
|
||||
@@ -65,7 +64,6 @@ void exixe::show_digit(unsigned char digit, unsigned char brightness, unsigned c
|
||||
spi_buf[0] = overdrive ? EXIXE_SPI_HEADER_OD : EXIXE_SPI_HEADER; // first byte, header
|
||||
spi_buf[digit] = 0x80 | brightness; // set digit brightness
|
||||
|
||||
animation_src_digit = digit;
|
||||
spi_write();
|
||||
}
|
||||
|
||||
@@ -99,34 +97,24 @@ void exixe::set_dots(unsigned char left_brightness, unsigned char right_brightne
|
||||
spi_write();
|
||||
}
|
||||
|
||||
void exixe::crossfade_init(unsigned char digit, unsigned int duration_frames, unsigned char brightness, unsigned char overdrive)
|
||||
void exixe::crossfade(unsigned char source_digit, unsigned char destination_digit, unsigned int duration_frames, unsigned char brightness, unsigned char overdrive)
|
||||
{
|
||||
animation_dest_digit = cap_digit(digit);
|
||||
animation_start = millis() / EXIXE_ANIMATION_FPS;
|
||||
animation_duration = duration_frames;
|
||||
animation_brightness = brightness & 0x7f;
|
||||
animation_overdrive = overdrive;
|
||||
animation_step = (float)animation_brightness / (float)animation_duration;
|
||||
}
|
||||
|
||||
unsigned char exixe::crossfade_run()
|
||||
{
|
||||
unsigned long current_frame = (millis() / EXIXE_ANIMATION_FPS) - animation_start;
|
||||
brightness &= 0x7f;
|
||||
float step = (float)brightness / (float)duration_frames;
|
||||
|
||||
if(current_frame > animation_duration)
|
||||
{
|
||||
animation_src_digit = animation_dest_digit;
|
||||
return EXIXE_ANIMATION_FINISHED;
|
||||
}
|
||||
source_digit = cap_digit(source_digit);
|
||||
destination_digit = cap_digit(destination_digit);
|
||||
|
||||
memset(spi_buf, 0, EXIXE_SPI_BUF_SIZE);
|
||||
memset(spi_buf, 0x80, EXIXE_SPI_BUF_SIZE - 5);
|
||||
spi_buf[0] = animation_overdrive ? EXIXE_SPI_HEADER_OD : EXIXE_SPI_HEADER;
|
||||
|
||||
unsigned char temp = cap_float(animation_step * (float)current_frame);
|
||||
spi_buf[animation_src_digit] = 0x80 | (animation_brightness - temp);
|
||||
spi_buf[animation_dest_digit] = 0x80 | temp;
|
||||
spi_write();
|
||||
spi_buf[0] = overdrive ? EXIXE_SPI_HEADER_OD : EXIXE_SPI_HEADER;
|
||||
|
||||
return EXIXE_ANIMATION_IN_PROGRESS;
|
||||
for (int i = 0; i < duration_frames; ++i)
|
||||
{
|
||||
unsigned char temp = cap_float(step * (float)i);
|
||||
spi_buf[source_digit] = 0x80 | (brightness - temp);
|
||||
spi_buf[destination_digit] = 0x80 | temp;
|
||||
spi_write();
|
||||
delay(16);
|
||||
}
|
||||
}
|
||||
@@ -4,35 +4,22 @@
|
||||
#define EXIXE_SPI_BUF_SIZE (16)
|
||||
#define EXIXE_SPI_HEADER (0xaa)
|
||||
#define EXIXE_SPI_HEADER_OD (0xab)
|
||||
#define EXIXE_ANIMATION_FPS (30)
|
||||
#define EXIXE_ANIMATION_IN_PROGRESS (1)
|
||||
#define EXIXE_ANIMATION_FINISHED (0)
|
||||
|
||||
class exixe
|
||||
{
|
||||
public:
|
||||
exixe(int my_cs);
|
||||
exixe(int);
|
||||
void show_digit(unsigned char digit, unsigned char brightness, unsigned char overdrive);
|
||||
void set_led(unsigned char red, unsigned char green, unsigned char blue);
|
||||
void set_dots(unsigned char left_brightness, unsigned char right_brightness);
|
||||
void crossfade_init(unsigned char digit, unsigned int duration_frames, unsigned char brightness, unsigned char overdrive);
|
||||
unsigned char crossfade_run();
|
||||
void crossfade(unsigned char source_digit, unsigned char destination_digit, unsigned int duration_frames, unsigned char brightness, unsigned char overdrive);
|
||||
void clear();
|
||||
private:
|
||||
unsigned char cs_pin;
|
||||
unsigned char spi_buf[EXIXE_SPI_BUF_SIZE];
|
||||
void spi_write();
|
||||
unsigned char cap_digit(unsigned char digit);
|
||||
unsigned char cap_float(float temp);
|
||||
void spi_write();
|
||||
|
||||
//------- crossfade animation variables -------
|
||||
unsigned char animation_src_digit;
|
||||
unsigned char animation_dest_digit;
|
||||
unsigned long animation_start;
|
||||
unsigned long animation_duration;
|
||||
unsigned char animation_brightness;
|
||||
unsigned char animation_overdrive;
|
||||
float animation_step;
|
||||
};
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user