Skip to content

Commit

Permalink
Add HERO C# CANdle example
Browse files Browse the repository at this point in the history
  • Loading branch information
CoryNessCTR committed Oct 18, 2023
1 parent 61c2f11 commit 19ea9b1
Show file tree
Hide file tree
Showing 4 changed files with 174 additions and 0 deletions.
57 changes: 57 additions & 0 deletions HERO C#/CANdleExample/CANdleExample.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<LangVersion>5</LangVersion>
</PropertyGroup>
<PropertyGroup>
<AssemblyName>CANdleExample</AssemblyName>
<OutputType>Exe</OutputType>
<RootNamespace>CANdleExample</RootNamespace>
<ProjectTypeGuids>{b69e3092-b931-443c-abe7-7e7b65f2a37f};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<ProductVersion>9.0.21022</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{9686CA05-C0FE-4ED6-B707-A10AD058F14D}</ProjectGuid>
<TargetFrameworkVersion>v4.4</TargetFrameworkVersion>
<NetMfTargetsBaseDir Condition="'$(NetMfTargetsBaseDir)'==''">$(MSBuildExtensionsPath32)\Microsoft\.NET Micro Framework\</NetMfTargetsBaseDir>
<DeployDevice>Cross Link HERO .NETMF_Mini-USB</DeployDevice>
<DeployTransport>USB</DeployTransport>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<Import Project="$(NetMfTargetsBaseDir)$(TargetFrameworkVersion)\CSharp.Targets" />
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Program.cs" />
</ItemGroup>
<ItemGroup>
<Reference Include="CTRE, Version=4.4.0.4, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<Private>False</Private>
</Reference>
<Reference Include="CTRE.Phoenix.LowLevel, Version=5.2.1.1, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<Private>False</Private>
</Reference>
<Reference Include="ctre_netmf_native, Version=1.2.0.6, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<Private>False</Private>
</Reference>
<Reference Include="Microsoft.SPOT.Hardware" />
<Reference Include="Microsoft.SPOT.Native" />
</ItemGroup>
</Project>
27 changes: 27 additions & 0 deletions HERO C#/CANdleExample/CANdleExample.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.31515.178
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CANdleExample", "CANdleExample.csproj", "{9686CA05-C0FE-4ED6-B707-A10AD058F14D}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{9686CA05-C0FE-4ED6-B707-A10AD058F14D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9686CA05-C0FE-4ED6-B707-A10AD058F14D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9686CA05-C0FE-4ED6-B707-A10AD058F14D}.Debug|Any CPU.Deploy.0 = Debug|Any CPU
{9686CA05-C0FE-4ED6-B707-A10AD058F14D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9686CA05-C0FE-4ED6-B707-A10AD058F14D}.Release|Any CPU.Build.0 = Release|Any CPU
{9686CA05-C0FE-4ED6-B707-A10AD058F14D}.Release|Any CPU.Deploy.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {899F0C9C-5DBB-452F-B179-A82834F67B48}
EndGlobalSection
EndGlobal
65 changes: 65 additions & 0 deletions HERO C#/CANdleExample/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
using System.Threading;
using CTRE.Phoenix.LED;

namespace CANdleExample
{
public class Program
{
public static void Main()
{
CANdle candle = new CANdle(0);

candle.ConfigBrightnessScalar(0.1f); // Make LEDs 10% brightness

/* Start with setLED in a rainbow for a couple second */
candle.SetLEDs(0, 0, 0, startIdx: 0, count: 1);
candle.SetLEDs(0, 0, 255, startIdx: 1, count: 1);
candle.SetLEDs(0, 255, 0, startIdx: 2, count: 1);
candle.SetLEDs(0, 255, 255, startIdx: 3, count: 1);
candle.SetLEDs(255, 0, 0, startIdx: 4, count: 1);
candle.SetLEDs(255, 0, 255, startIdx: 5, count: 1);
candle.SetLEDs(255, 255, 0, startIdx: 6, count: 1);
candle.SetLEDs(255, 255, 255, startIdx: 7, count: 1);
Thread.Sleep(5000);


/* Loop through some animations every 1 second for the 8 on-board LEDs */
int animationIndex = 0;
/* loop forever */
while (true)
{
Animation toAnimate;
switch(animationIndex)
{
/* If animationIndex is not valid, make it 0 and start from the beginning */
default:
animationIndex = 0;
goto case 0;

/* Normal cases from here */
case 0:
toAnimate = new RainbowAnimation();
animationIndex++;
break;
case 1:
toAnimate = new LarsonAnimation(128, 128, 0, numLed: 8);
animationIndex++;
break;
case 2:
toAnimate = new FireAnimation(numLed: 8);
animationIndex++;
break;
case 3:
toAnimate = new TwinkleAnimation(0, 255, 128, numLed: 8);
animationIndex = 0; // Start over from the top
break;
}

candle.Animate(toAnimate);

/* wait a bit */
Thread.Sleep(1000);
}
}
}
}
25 changes: 25 additions & 0 deletions HERO C#/CANdleExample/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("CANdleExample")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("CANdleExample")]
[assembly: AssemblyCopyright("Copyright © 2023")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

0 comments on commit 19ea9b1

Please sign in to comment.