Skip to content

Commit 19ea9b1

Browse files
committed
Add HERO C# CANdle example
1 parent 61c2f11 commit 19ea9b1

File tree

4 files changed

+174
-0
lines changed

4 files changed

+174
-0
lines changed
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup>
4+
<LangVersion>5</LangVersion>
5+
</PropertyGroup>
6+
<PropertyGroup>
7+
<AssemblyName>CANdleExample</AssemblyName>
8+
<OutputType>Exe</OutputType>
9+
<RootNamespace>CANdleExample</RootNamespace>
10+
<ProjectTypeGuids>{b69e3092-b931-443c-abe7-7e7b65f2a37f};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
11+
<ProductVersion>9.0.21022</ProductVersion>
12+
<SchemaVersion>2.0</SchemaVersion>
13+
<ProjectGuid>{9686CA05-C0FE-4ED6-B707-A10AD058F14D}</ProjectGuid>
14+
<TargetFrameworkVersion>v4.4</TargetFrameworkVersion>
15+
<NetMfTargetsBaseDir Condition="'$(NetMfTargetsBaseDir)'==''">$(MSBuildExtensionsPath32)\Microsoft\.NET Micro Framework\</NetMfTargetsBaseDir>
16+
<DeployDevice>Cross Link HERO .NETMF_Mini-USB</DeployDevice>
17+
<DeployTransport>USB</DeployTransport>
18+
</PropertyGroup>
19+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
20+
<DebugSymbols>true</DebugSymbols>
21+
<DebugType>full</DebugType>
22+
<Optimize>false</Optimize>
23+
<OutputPath>bin\Debug\</OutputPath>
24+
<DefineConstants>DEBUG;TRACE</DefineConstants>
25+
<ErrorReport>prompt</ErrorReport>
26+
<WarningLevel>4</WarningLevel>
27+
</PropertyGroup>
28+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
29+
<DebugType>pdbonly</DebugType>
30+
<Optimize>true</Optimize>
31+
<OutputPath>bin\Release\</OutputPath>
32+
<DefineConstants>TRACE</DefineConstants>
33+
<ErrorReport>prompt</ErrorReport>
34+
<WarningLevel>4</WarningLevel>
35+
</PropertyGroup>
36+
<Import Project="$(NetMfTargetsBaseDir)$(TargetFrameworkVersion)\CSharp.Targets" />
37+
<ItemGroup>
38+
<Compile Include="Properties\AssemblyInfo.cs" />
39+
<Compile Include="Program.cs" />
40+
</ItemGroup>
41+
<ItemGroup>
42+
<Reference Include="CTRE, Version=4.4.0.4, Culture=neutral, processorArchitecture=MSIL">
43+
<SpecificVersion>False</SpecificVersion>
44+
<Private>False</Private>
45+
</Reference>
46+
<Reference Include="CTRE.Phoenix.LowLevel, Version=5.2.1.1, Culture=neutral, processorArchitecture=MSIL">
47+
<SpecificVersion>False</SpecificVersion>
48+
<Private>False</Private>
49+
</Reference>
50+
<Reference Include="ctre_netmf_native, Version=1.2.0.6, Culture=neutral, processorArchitecture=MSIL">
51+
<SpecificVersion>False</SpecificVersion>
52+
<Private>False</Private>
53+
</Reference>
54+
<Reference Include="Microsoft.SPOT.Hardware" />
55+
<Reference Include="Microsoft.SPOT.Native" />
56+
</ItemGroup>
57+
</Project>
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 16
4+
VisualStudioVersion = 16.0.31515.178
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CANdleExample", "CANdleExample.csproj", "{9686CA05-C0FE-4ED6-B707-A10AD058F14D}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{9686CA05-C0FE-4ED6-B707-A10AD058F14D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{9686CA05-C0FE-4ED6-B707-A10AD058F14D}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{9686CA05-C0FE-4ED6-B707-A10AD058F14D}.Debug|Any CPU.Deploy.0 = Debug|Any CPU
17+
{9686CA05-C0FE-4ED6-B707-A10AD058F14D}.Release|Any CPU.ActiveCfg = Release|Any CPU
18+
{9686CA05-C0FE-4ED6-B707-A10AD058F14D}.Release|Any CPU.Build.0 = Release|Any CPU
19+
{9686CA05-C0FE-4ED6-B707-A10AD058F14D}.Release|Any CPU.Deploy.0 = Release|Any CPU
20+
EndGlobalSection
21+
GlobalSection(SolutionProperties) = preSolution
22+
HideSolutionNode = FALSE
23+
EndGlobalSection
24+
GlobalSection(ExtensibilityGlobals) = postSolution
25+
SolutionGuid = {899F0C9C-5DBB-452F-B179-A82834F67B48}
26+
EndGlobalSection
27+
EndGlobal

HERO C#/CANdleExample/Program.cs

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
using System.Threading;
2+
using CTRE.Phoenix.LED;
3+
4+
namespace CANdleExample
5+
{
6+
public class Program
7+
{
8+
public static void Main()
9+
{
10+
CANdle candle = new CANdle(0);
11+
12+
candle.ConfigBrightnessScalar(0.1f); // Make LEDs 10% brightness
13+
14+
/* Start with setLED in a rainbow for a couple second */
15+
candle.SetLEDs(0, 0, 0, startIdx: 0, count: 1);
16+
candle.SetLEDs(0, 0, 255, startIdx: 1, count: 1);
17+
candle.SetLEDs(0, 255, 0, startIdx: 2, count: 1);
18+
candle.SetLEDs(0, 255, 255, startIdx: 3, count: 1);
19+
candle.SetLEDs(255, 0, 0, startIdx: 4, count: 1);
20+
candle.SetLEDs(255, 0, 255, startIdx: 5, count: 1);
21+
candle.SetLEDs(255, 255, 0, startIdx: 6, count: 1);
22+
candle.SetLEDs(255, 255, 255, startIdx: 7, count: 1);
23+
Thread.Sleep(5000);
24+
25+
26+
/* Loop through some animations every 1 second for the 8 on-board LEDs */
27+
int animationIndex = 0;
28+
/* loop forever */
29+
while (true)
30+
{
31+
Animation toAnimate;
32+
switch(animationIndex)
33+
{
34+
/* If animationIndex is not valid, make it 0 and start from the beginning */
35+
default:
36+
animationIndex = 0;
37+
goto case 0;
38+
39+
/* Normal cases from here */
40+
case 0:
41+
toAnimate = new RainbowAnimation();
42+
animationIndex++;
43+
break;
44+
case 1:
45+
toAnimate = new LarsonAnimation(128, 128, 0, numLed: 8);
46+
animationIndex++;
47+
break;
48+
case 2:
49+
toAnimate = new FireAnimation(numLed: 8);
50+
animationIndex++;
51+
break;
52+
case 3:
53+
toAnimate = new TwinkleAnimation(0, 255, 128, numLed: 8);
54+
animationIndex = 0; // Start over from the top
55+
break;
56+
}
57+
58+
candle.Animate(toAnimate);
59+
60+
/* wait a bit */
61+
Thread.Sleep(1000);
62+
}
63+
}
64+
}
65+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
using System.Reflection;
2+
using System.Runtime.CompilerServices;
3+
using System.Runtime.InteropServices;
4+
5+
// General Information about an assembly is controlled through the following
6+
// set of attributes. Change these attribute values to modify the information
7+
// associated with an assembly.
8+
[assembly: AssemblyTitle("CANdleExample")]
9+
[assembly: AssemblyDescription("")]
10+
[assembly: AssemblyConfiguration("")]
11+
[assembly: AssemblyCompany("")]
12+
[assembly: AssemblyProduct("CANdleExample")]
13+
[assembly: AssemblyCopyright("Copyright © 2023")]
14+
[assembly: AssemblyTrademark("")]
15+
[assembly: AssemblyCulture("")]
16+
17+
// Version information for an assembly consists of the following four values:
18+
//
19+
// Major Version
20+
// Minor Version
21+
// Build Number
22+
// Revision
23+
//
24+
[assembly: AssemblyVersion("1.0.0.0")]
25+
[assembly: AssemblyFileVersion("1.0.0.0")]

0 commit comments

Comments
 (0)