Created
January 5, 2016 19:35
-
-
Save markusgritsch/ae85e24cf63eb8866bd3 to your computer and use it in GitHub Desktop.
Code for this video: https://www.youtube.com/watch?v=u_rdroWi2ho
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <util/delay.h> | |
#include <oled.h> | |
#include <tri.h> | |
void setup() | |
{ | |
//Serial.begin( 115200 ); | |
oled_init(); | |
_delay_ms( 100 ); // Wait for the OLED display to come up. | |
oled_config(); | |
} | |
static const uint8_t sinustable[ 0x100 ] = { | |
0x80, 0x7d, 0x7a, 0x77, 0x74, 0x70, 0x6d, 0x6a, | |
0x67, 0x64, 0x61, 0x5e, 0x5b, 0x58, 0x55, 0x52, | |
0x4f, 0x4d, 0x4a, 0x47, 0x44, 0x41, 0x3f, 0x3c, | |
0x39, 0x37, 0x34, 0x32, 0x2f, 0x2d, 0x2b, 0x28, | |
0x26, 0x24, 0x22, 0x20, 0x1e, 0x1c, 0x1a, 0x18, | |
0x16, 0x15, 0x13, 0x11, 0x10, 0x0f, 0x0d, 0x0c, | |
0x0b, 0x0a, 0x08, 0x07, 0x06, 0x06, 0x05, 0x04, | |
0x03, 0x03, 0x02, 0x02, 0x02, 0x01, 0x01, 0x01, | |
0x01, 0x01, 0x01, 0x01, 0x02, 0x02, 0x02, 0x03, | |
0x03, 0x04, 0x05, 0x06, 0x06, 0x07, 0x08, 0x0a, | |
0x0b, 0x0c, 0x0d, 0x0f, 0x10, 0x11, 0x13, 0x15, | |
0x16, 0x18, 0x1a, 0x1c, 0x1e, 0x20, 0x22, 0x24, | |
0x26, 0x28, 0x2b, 0x2d, 0x2f, 0x32, 0x34, 0x37, | |
0x39, 0x3c, 0x3f, 0x41, 0x44, 0x47, 0x4a, 0x4d, | |
0x4f, 0x52, 0x55, 0x58, 0x5b, 0x5e, 0x61, 0x64, | |
0x67, 0x6a, 0x6d, 0x70, 0x74, 0x77, 0x7a, 0x7d, | |
0x80, 0x83, 0x86, 0x89, 0x8c, 0x90, 0x93, 0x96, | |
0x99, 0x9c, 0x9f, 0xa2, 0xa5, 0xa8, 0xab, 0xae, | |
0xb1, 0xb3, 0xb6, 0xb9, 0xbc, 0xbf, 0xc1, 0xc4, | |
0xc7, 0xc9, 0xcc, 0xce, 0xd1, 0xd3, 0xd5, 0xd8, | |
0xda, 0xdc, 0xde, 0xe0, 0xe2, 0xe4, 0xe6, 0xe8, | |
0xea, 0xeb, 0xed, 0xef, 0xf0, 0xf1, 0xf3, 0xf4, | |
0xf5, 0xf6, 0xf8, 0xf9, 0xfa, 0xfa, 0xfb, 0xfc, | |
0xfd, 0xfd, 0xfe, 0xfe, 0xfe, 0xff, 0xff, 0xff, | |
0xff, 0xff, 0xff, 0xff, 0xfe, 0xfe, 0xfe, 0xfd, | |
0xfd, 0xfc, 0xfb, 0xfa, 0xfa, 0xf9, 0xf8, 0xf6, | |
0xf5, 0xf4, 0xf3, 0xf1, 0xf0, 0xef, 0xed, 0xeb, | |
0xea, 0xe8, 0xe6, 0xe4, 0xe2, 0xe0, 0xde, 0xdc, | |
0xda, 0xd8, 0xd5, 0xd3, 0xd1, 0xce, 0xcc, 0xc9, | |
0xc7, 0xc4, 0xc1, 0xbf, 0xbc, 0xb9, 0xb6, 0xb3, | |
0xb1, 0xae, 0xab, 0xa8, 0xa5, 0xa2, 0x9f, 0x9c, | |
0x99, 0x96, 0x93, 0x90, 0x8c, 0x89, 0x86, 0x83 | |
}; | |
static uint8_t charset[ 64 ] = { 0 }; | |
static void doplasma( uint8_t * fb ) | |
{ | |
static uint8_t xbuf[ 32 ]; | |
static uint8_t ybuf[ 16 ]; | |
static uint8_t c1a,c1b; | |
static uint8_t c2a,c2b; | |
static uint8_t c1A,c1B; | |
static uint8_t c2A,c2B; | |
static uint8_t x, y, i; | |
c1a = c1A; | |
c1b = c1B; | |
for ( y = 0; y < 16; ++y ) { | |
ybuf[ y ] = ( sinustable[ c1a ] + sinustable[ c1b ] ) >> 1; | |
c1a += 4; | |
c1b += 9; | |
} | |
c1A += 3; | |
c1B -= 5; | |
c2a = c2A; | |
c2b = c2B; | |
for ( x = 0; x < 32; ++x ) { | |
xbuf[ x ] = ( sinustable[ c2a ] + sinustable[ c2b ] ) >> 1; | |
c2a += 3; | |
c2b += 7; | |
} | |
c2A += 2; | |
c2B -= 3; | |
for ( y = 0; y < 8; ++y ) { | |
for ( x = 0; x < 32; ++x ) { | |
for ( i = 0; i < 4; ++i, ++fb ) { | |
* fb = ( charset[ ( ( ( xbuf[ x ] + ybuf[ y * 2 ] ) >> 3 ) + i ) % 16 ] & 0x0f | | |
charset[ ( ( ( xbuf[ x ] + ybuf[ y * 2 + 1 ] ) >> 3 ) + i ) % 16 ] & 0xf0 ); | |
} | |
} | |
} | |
} | |
static void makechar (void) | |
{ | |
const unsigned char bittab[ 4 ] = { | |
0x11, 0x22, 0x44, 0x88 | |
}; | |
uint8_t i, ii, b, s, c; | |
for ( c = 0; c < 16; ++c ) { | |
s = sinustable[ c << 4 ]; | |
//s = c << 4; | |
for ( i = 0; i < 4; ++i ){ | |
b = 0; | |
for ( ii = 0; ii < 4; ++ii ) { | |
if ( ( rand() & 0xff ) <= s ) { | |
b |= bittab[ ii ]; | |
} | |
} | |
charset[ c * 4 + i ] = b; | |
} | |
} | |
} | |
void loop() | |
{ | |
makechar(); | |
uint8_t * fb = get_fb(); | |
while ( 1 ) { | |
transfer_frame_buffer(); | |
doplasma( fb ); | |
_delay_ms( 10 ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment