Created
April 14, 2017 14:06
-
-
Save anonymous/efd11fe599c3c9287c6a1a0c4d34a1f9 to your computer and use it in GitHub Desktop.
Seeed Studio Circular LED & TinyCLR OS
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
http://wiki.seeedstudio.com/wiki/Grove_-_Circular_LED | |
http://wiki.seeedstudio.com/images/7/72/Circular_LED_v0.9b.pdf | |
http://www.my-semi.com/file/MY9221_BF_0.7.pdf | |
using System; | |
using System.Threading; | |
using GHIElectronics.TinyCLR.Devices.Gpio; | |
using GHIElectronics.TinyCLR.Pins; | |
namespace babylette | |
{ | |
public class Program | |
{ | |
static GpioController GPIO = GpioController.GetDefault(); | |
static GpioPin ClockPin = GPIO.OpenPin(FEZPandaIII.Gpio.D7); | |
static GpioPin DataPin = GPIO.OpenPin(FEZPandaIII.Gpio.D6); | |
static ushort CmdMode = 0; | |
static void Send16bit(ushort data) | |
{ | |
for (int i = 0; i < 16; i++) | |
{ | |
if ((data & 0x8000) > 0) | |
DataPin.Write(GpioPinValue.High); | |
else | |
DataPin.Write(GpioPinValue.Low); | |
if (ClockPin.Read() == GpioPinValue.High) | |
ClockPin.Write(GpioPinValue.Low); | |
else | |
ClockPin.Write(GpioPinValue.High); | |
data <<= 1; | |
//Thread.Sleep(1); | |
} | |
} | |
static void WriteLEDs(ushort[] leds) | |
{ | |
Send16bit(CmdMode); | |
Thread.Sleep(1); | |
if (ClockPin.Read() == GpioPinValue.High) | |
ClockPin.Write(GpioPinValue.Low); | |
else | |
ClockPin.Write(GpioPinValue.High); | |
if (ClockPin.Read() == GpioPinValue.High) | |
ClockPin.Write(GpioPinValue.Low); | |
else | |
ClockPin.Write(GpioPinValue.High); | |
if (ClockPin.Read() == GpioPinValue.High) | |
ClockPin.Write(GpioPinValue.Low); | |
else | |
ClockPin.Write(GpioPinValue.High); | |
if (ClockPin.Read() == GpioPinValue.High) | |
ClockPin.Write(GpioPinValue.Low); | |
else | |
ClockPin.Write(GpioPinValue.High); | |
for (int count = 0; count < 12; count++) | |
{ | |
Send16bit( leds[count]); | |
} | |
Send16bit(CmdMode); | |
//Thread.Sleep(1); | |
if (ClockPin.Read() == GpioPinValue.High) | |
ClockPin.Write(GpioPinValue.Low); | |
else | |
ClockPin.Write(GpioPinValue.High); | |
for (int count = 12; count < 24; count++) | |
{ | |
Send16bit( leds[count]); | |
} | |
//latch | |
//Thread.Sleep(10); | |
for (int i = 0; i < 8; i++) | |
{ | |
//Thread.Sleep(1); | |
if (DataPin.Read() == GpioPinValue.High) | |
DataPin.Write(GpioPinValue.Low); | |
else | |
DataPin.Write(GpioPinValue.High); | |
//Thread.Sleep(1); | |
} | |
} | |
public static void Main() | |
{ | |
ClockPin.SetDriveMode(GpioPinDriveMode.Output); | |
DataPin.SetDriveMode(GpioPinDriveMode.Output); | |
//ClockPin.Write(GpioPinValue.h); | |
//DataPin.Write(GpioPinValue.Low); | |
ushort[] leds = new ushort[24];// 24 LEDs | |
int k = 0; | |
while (true) | |
{ | |
//Array.Clear(leds, 0, leds.Length); | |
if (leds[k] > 0) | |
leds[k] = 0; | |
else | |
leds[k] = 0x0f; | |
k++; | |
if (k == 24) | |
k = 0; | |
WriteLEDs(leds); | |
Thread.Sleep(30); | |
} | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment