Skip to content

Commit

Permalink
adding library installtion instructions
Browse files Browse the repository at this point in the history
  • Loading branch information
dekuNukem committed Mar 6, 2018
1 parent 669ef85 commit 430083a
Show file tree
Hide file tree
Showing 10 changed files with 51 additions and 203 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Binary file added arduino_library/exixe.zip
Binary file not shown.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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();
}

Expand Down Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
File renamed without changes.

0 comments on commit 430083a

Please sign in to comment.