#include "NeoCol.h"
#include <stdlib.h>
uint8_t NeoGreen [NeoNum];
uint8_t NeoBlue [NeoNum];
uint8_t NeoRed [NeoNum];
void NeoBit (uint8_t Data, int8_t BitCount)
{
if ((Data >> BitCount) & 0x01)
{
NeoPin = 1;
_delay (6);
NeoPin = 0;
}
else
{
NeoPin = 1;
_delay (3);
NeoPin = 0;
}
}
void NeoInit (void)
{
uint8_t NeoPixel;
for (NeoPixel = 0; NeoPixel < NeoNum; NeoPixel++)
{
if (NeoPixel < 10)
{ NeoGreen[NeoPixel] = 0; NeoBlue[NeoPixel] = 0; NeoRed[NeoPixel] = 64; }
else if ((NeoPixel >= 10) & (NeoPixel < 20))
{ NeoGreen[NeoPixel] = 0; NeoBlue[NeoPixel] = 64; NeoRed[NeoPixel] = 0; }
else if ((NeoPixel >= 20) & (NeoPixel < 30))
{ NeoGreen[NeoPixel] = 0; NeoBlue[NeoPixel] = 64; NeoRed[NeoPixel] = 64; }
else if ((NeoPixel >= 30) & (NeoPixel < 40))
{ NeoGreen[NeoPixel] = 64; NeoBlue[NeoPixel] = 0; NeoRed[NeoPixel] = 0; }
else if ((NeoPixel >= 40) & (NeoPixel < 50))
{ NeoGreen[NeoPixel] = 64; NeoBlue[NeoPixel] = 0; NeoRed[NeoPixel] = 64; }
else if ((NeoPixel >= 50) & (NeoPixel < NeoNum))
{ NeoGreen[NeoPixel] = 64; NeoBlue[NeoPixel] = 64; NeoRed[NeoPixel] = 0; }
}
}
void NeoDraw (void)
{
uint8_t NeoPixel;
int8_t BitCount;
for (NeoPixel = 0; NeoPixel < NeoNum; NeoPixel++)
{
for (BitCount = 7; BitCount >= 0; BitCount--)
NeoBit(NeoGreen[NeoPixel], BitCount);
for (BitCount = 7; BitCount >= 0; BitCount--)
NeoBit(NeoRed[NeoPixel], BitCount);
for (BitCount = 7; BitCount >= 0; BitCount--)
NeoBit(NeoBlue[NeoPixel], BitCount);
}
//output_low (NeoPin);
}
void NeoRotate (void)
{
uint8_t NeoPixel;
for (NeoPixel = 0; NeoPixel < NeoNum - 1; NeoPixel++)
{
NeoGreen[NeoPixel] = NeoGreen[NeoPixel + 1];
NeoBlue[NeoPixel] = NeoBlue[NeoPixel + 1];
NeoRed[NeoPixel] = NeoRed[NeoPixel + 1];
}
NeoGreen[NeoNum - 1] = NeoGreen[0];
NeoBlue[NeoNum - 1] = NeoBlue[0];
NeoRed[NeoNum - 1] = NeoRed[0];
}
void main()
{
OSCCON = 0; // Use clock specified in config: 48MHz
NeoPin = 0; // Set data line to - initially
TRISB = 0; // Set port B to output
NeoInit ();
while(1)
{
NeoDraw ();
NeoRotate ();
__delay_ms (25);
}
}