can anybody see a way of speeding this program up my NETMF skills are not that good.
//Re-written for Panda II taken from http://docs.macetech.com/doku.php/octobrite
using System;
using Microsoft.SPOT;
using OctoBrite;
namespace FEZ_Panda_II_Application_OctoBrite
{
public class Program
{
public static void Main()
{
Debug.EnableGCMessages(false);
// Variables for sample function
float offset = 0.0f;
var octoBrite = new TLC5947();
while (true)
{
// Scan across whole array with fading, in red, green, and blue
for (offset = 0.0f; offset < 360; offset += 0.5f)
{
octoBrite.LEDscan(4095, 0, 0, offset);
//Thread.Sleep(2);
}
for (offset = 0.0f; offset < 360; offset += 0.5f)
{
octoBrite.LEDscan(0, 4095, 0, offset);
//Thread.Sleep(2);
}
for (offset = 0.0f; offset < 360; offset += 0.5f)
{
octoBrite.LEDscan(0, 0, 4095, offset);
//Thread.Sleep(2);
}
}
}
}
}
//Re-written for Panda II taken from http://docs.macetech.com/doku.php/octobrite
using System;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using GHIElectronics.NETMF.System;
using GHIElectronics.NETMF.FEZ;
namespace OctoBrite
{
public class TLC5947
{
// Number of OctoBrites / TLC5947 devices
public byte NumOctoBrites = 1;
// Jagged Array storing color values
// BLUE: LEDChannels[x][0] Range: {0 to 4095}
// GREEN: LEDChannels[x][1] Range: {0 to 4095}
// RED: LEDChannels[x][2] Range: {0 to 4095}
public ushort[][] LEDChannels = new ushort[8][] { new ushort[3] {0,0,0}, new ushort[3] {0,0,0}, new ushort[3] {0,0,0}, new ushort[3] {0,0,0},
new ushort[3] {0,0,0}, new ushort[3] {0,0,0}, new ushort[3] {0,0,0}, new ushort[3] {0,0,0}};
OutputPort enablepin = new OutputPort((Cpu.Pin)GHIElectronics.NETMF.FEZ.FEZ_Pin.Digital.Di10, false);//BL
OutputPort latchpin = new OutputPort((Cpu.Pin)GHIElectronics.NETMF.FEZ.FEZ_Pin.Digital.Di9, false);//XL
OutputPort clockpin = new OutputPort((Cpu.Pin)GHIElectronics.NETMF.FEZ.FEZ_Pin.Digital.Di13, false);//CL
OutputPort datapin = new OutputPort((Cpu.Pin)GHIElectronics.NETMF.FEZ.FEZ_Pin.Digital.Di11, false);//SI
// Sample function to draw a scanning pattern with fading
public void LEDscan(int red, int green, int blue, float degreeoffset)
{
float brightnessfactor = 0.0f;
float scanindex = (float)(1 + MathEx.Sin((double)(degreeoffset * 3.14159f / 180))) * ((float)(NumOctoBrites * 8 ) / 2);
for (int LEDindex = 0; LEDindex < (NumOctoBrites * 8); LEDindex++)
{
brightnessfactor = (float)MathEx.Exp((double)(0 - Fabs(scanindex - ((float)LEDindex + 0.5f)) * 1.3f));
LEDChannels[LEDindex][0] = (ushort)(blue * brightnessfactor);
LEDChannels[LEDindex][1] = (ushort)(green * brightnessfactor);
LEDChannels[LEDindex][2] = (ushort)(red * brightnessfactor);
}
WriteLEDArray();
}
//Bit banging method
public void WriteLEDArray()
{
ushort tempOne = 0;
//This method is used to get around the pointers used in the original Arduino code.
//The first two loops combine to give us the 24 channels assuming 1(NumOctoBrites * 8 * 3 = 24)
//The 3rd loop reads the bits and writes them out to the SI pin.
for (int i = 0; i < (NumOctoBrites * 8); i++)//Led channels 0-7
{
for (int h = 0; h < 3; h++)//Colours 0-2 Red, Green, Blue
{
tempOne = LEDChannels[i][h];//Colour brightness value
for (int j = 0; j < 12; j++)//12 bits 0-11
{
int bit = ((tempOne >> (11 - j)) & 1);//Bit = right shift. One bit at a time. For 12 bits * 24 = 288
if (bit == 1)
{
datapin.Write(true);//Its a 1
}
else
{
datapin.Write(false);//Its a 0
}
clockpin.Write(true);//Clock in the bit
clockpin.Write(false);
}
}
}
latchpin.Write(true);//Latch all 288 bits
latchpin.Write(false);
}
/// <summary>
/// Returns the absolute value (Renamed Fabs)
/// </summary>
/// <param name="x">A number</param>
/// <returns>absolute value of x</returns>
public float Fabs(float x)
{
if (x >= 0.0F) return x;
return (-x);
}
}
}
Thanks