Skip to content

Commit 08e1a48

Browse files
authored
Full Commit
0 parents  commit 08e1a48

32 files changed

+1481
-0
lines changed
Lines changed: 235 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,235 @@
1+
//******************************************************
2+
// LED Panel and Presentation OUTPUT
3+
const int LED1 = 13;
4+
const int LED2 = 12;
5+
const int LED3 = 11;
6+
const int LED4 = 10;
7+
const int LED5 = 9;
8+
const int LED6 = 8;
9+
const int LED7 = 7;
10+
const int LED8 = 6;
11+
const int LED9 = 5;
12+
const int LED_P = 4;
13+
14+
// Buttons (D. INPUT)
15+
const int BN1 = 3;
16+
const int BN2 = 2;
17+
// Buttons (A. INPUT) - Analog pins are INPUT by default
18+
#define BN3 A2
19+
#define BN4 A3
20+
#define BN5 A4
21+
22+
// Diode Inputs
23+
#define D1 A0
24+
#define D2 A1
25+
//******************************************************
26+
// Variables to keep track
27+
/* Order of variables - 1:ALL ON - 2:AUTO OFF - 3:AUTO - 4:Custom
28+
Presentation is separate.
29+
states are switched by using different buttons. presentation is turned on and off
30+
by toggling same button. its also connected to other states.*/
31+
int state_of4 = 2; // All off initially
32+
byte presentationState = 0; // Presentation off initially
33+
bool auto_transition = false; // transition to auto mode
34+
int previous_state = 2;
35+
36+
//******************************************************
37+
// Serial Comm variables and functions-------------------------------
38+
String COMstring; // String to store input from Serial Port
39+
String COMsequence; // String to store input sequence from Serial Port
40+
int sequence[9] = {1, 0, 1,
41+
0, 1, 0,
42+
1, 0, 1};
43+
44+
#define STRING2SEQUENCE for(int i=0; i<9; i++) {sequence[i] = (COMsequence.charAt(i)=='1') ? 1 : 0;}
45+
#define SWITCHBYSEQUENCE(seq, num) for(int i=0; i<num; i++) {(seq[i]==1) ? digitalWrite(getLedPin(i), HIGH) : digitalWrite(getLedPin(i), LOW);}
46+
47+
// Sequences----------------------------------------------------------
48+
// All LEDs and presentation on seqeunce
49+
int all_on[10] = {1, 1, 1,
50+
1, 1, 1,
51+
1, 1, 1,
52+
1};
53+
// All LEDs and presentation off seqeunce
54+
int all_off[10] = {0,};
55+
// Automatic Diode input sequences (2-inputs -> 9-outputs)
56+
int auto_1[9] = {0, 0, 0, /* D1=1 D2=1*/
57+
0, 0, 0,
58+
1, 1, 1};
59+
int auto_2[9] = {0, 0, 1, /* D1=1 D2=0*/
60+
0, 0, 1,
61+
1, 1, 1};
62+
int auto_3[9] = {1, 0, 0, /* D1=0 D2=1*/
63+
1, 0, 0,
64+
1, 1, 1};
65+
#define auto_4 all_on // D1=0 D2=0
66+
67+
const int getLedPin(int index) // For turning on LEDs based on sequence
68+
{
69+
switch(index)
70+
{
71+
case 0:
72+
return LED1;
73+
case 1:
74+
return LED2;
75+
case 2:
76+
return LED3;
77+
case 3:
78+
return LED4;
79+
case 4:
80+
return LED5;
81+
case 5:
82+
return LED6;
83+
case 6:
84+
return LED7;
85+
case 7:
86+
return LED8;
87+
case 8:
88+
return LED9;
89+
case 9:
90+
return LED_P;
91+
default:
92+
return -1; // error
93+
}
94+
}
95+
96+
// Function to toggle LED presentation with software debouncing
97+
void togglePresentation() {
98+
static unsigned long lastDebounceTime = 0;
99+
unsigned long debounceDelay = 1000; // Adjust debounce delay as needed
100+
unsigned long currentTime = millis();
101+
102+
if (currentTime - lastDebounceTime >= debounceDelay) {
103+
// Toggle presentation state
104+
presentationState = !presentationState;
105+
digitalWrite(LED_P, presentationState);
106+
(presentationState) ? Serial.println("*P1\r\n") : Serial.println("*P0\r\n");
107+
lastDebounceTime = currentTime;
108+
}
109+
}
110+
//******************************************************
111+
112+
// Setup Pins
113+
#define PIN_OUT(num) pinMode(LED##num, OUTPUT);
114+
#define PIN_IN(num) pinMode(BN##num, INPUT);
115+
116+
//******************************************************
117+
void setup()
118+
{
119+
PIN_OUT(1) PIN_OUT(2) PIN_OUT(3)
120+
PIN_OUT(4) PIN_OUT(5) PIN_OUT(6)
121+
PIN_OUT(7) PIN_OUT(8) PIN_OUT(9)
122+
pinMode(LED_P, OUTPUT);
123+
PIN_IN(1) PIN_IN(2)
124+
// Start Serial Communication
125+
Serial.begin(9600);
126+
}
127+
void loop()
128+
{
129+
// Get Serial Port Input from Desktop CLI------------------------------------
130+
if(Serial.available())
131+
{
132+
COMstring = Serial.readString();
133+
if(COMstring.charAt(0)=='#' && COMstring.charAt(1)=='C')
134+
{
135+
// to get only sequence from '#C111000111\r\n' format and convert to int array
136+
COMsequence = COMstring.substring(2,11);
137+
STRING2SEQUENCE
138+
state_of4 = 4; // Set state to Custom mode
139+
Serial.println("*M4\r\n");
140+
}
141+
if(COMstring.charAt(0)=='#' && COMstring.charAt(1)=='S')
142+
{
143+
Serial.println("*M2\r\n");
144+
delay(2000);
145+
Serial.println("*P0\r\n");
146+
}
147+
}
148+
// Read button and sensor inputs and assign states
149+
if(digitalRead(BN1)) // 1: Turn all ON
150+
{
151+
state_of4 = 1;
152+
}
153+
else if(digitalRead(BN2)) // 2: Turn all OFF
154+
{
155+
state_of4 = 2;
156+
}
157+
else if(digitalRead(BN3)) // 3: AUTO mode
158+
{
159+
state_of4 = 3;
160+
auto_transition = true;
161+
}
162+
else if(analogRead(BN5)) // 4: Custom mode
163+
{
164+
state_of4 = 4;
165+
}
166+
if(analogRead(BN4)) // Toggle Presentation---------
167+
{
168+
/*presentationState = !presentationState;
169+
digitalWrite(LED_P, presentationState);
170+
(presentationState) ? Serial.println("#P1\r\n") : Serial.println("#P0\r\n");*/
171+
togglePresentation();
172+
delay(200);
173+
}
174+
175+
// Do processes as per states
176+
switch (state_of4)
177+
{
178+
case 1:
179+
if(previous_state == 1) break;
180+
SWITCHBYSEQUENCE(all_on, 10);
181+
presentationState = 1;
182+
Serial.println("*M1\r\n");
183+
state_of4 = 0; // Reset state
184+
previous_state = 1;
185+
break;
186+
case 2:
187+
if(previous_state == 2) break;
188+
SWITCHBYSEQUENCE(all_off, 10);
189+
presentationState = 0;
190+
Serial.println("*M2\r\n");
191+
state_of4 = 0;
192+
previous_state = 2;
193+
break;
194+
case 3:
195+
if(digitalRead(D1) && digitalRead(D2))
196+
{
197+
SWITCHBYSEQUENCE(auto_1, 9);
198+
}
199+
else if(digitalRead(D1) && !digitalRead(D2))
200+
{
201+
SWITCHBYSEQUENCE(auto_2, 9);
202+
}
203+
else if(!digitalRead(D1) && digitalRead(D2))
204+
{
205+
SWITCHBYSEQUENCE(auto_3, 9);
206+
}
207+
else
208+
{
209+
SWITCHBYSEQUENCE(auto_4, 9);
210+
}
211+
state_of4 = 3; // Keep same state
212+
if(auto_transition==true && previous_state != 3)
213+
{
214+
Serial.println("*M3\r\n");
215+
}
216+
auto_transition = false; // transition over
217+
previous_state = 3;
218+
break;
219+
case 4:
220+
for(int i=0; i<9; i++)
221+
{
222+
(sequence[i]==1) ? digitalWrite(getLedPin(i), HIGH) : digitalWrite(getLedPin(i), LOW);
223+
}
224+
if(previous_state != 4)
225+
{
226+
Serial.println("*M4\r\n");
227+
}
228+
state_of4 = 0;
229+
previous_state = 4;
230+
break;
231+
default:
232+
break;
233+
}
234+
}
235+
//******************************************************
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.6.33801.468
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Arduino_LEDMatrix_GUI", "Arduino_LEDMatrix_GUI\Arduino_LEDMatrix_GUI.csproj", "{4239D6E5-70EF-4350-8C77-39F955E95FF0}"
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+
{4239D6E5-70EF-4350-8C77-39F955E95FF0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{4239D6E5-70EF-4350-8C77-39F955E95FF0}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{4239D6E5-70EF-4350-8C77-39F955E95FF0}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{4239D6E5-70EF-4350-8C77-39F955E95FF0}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {5F8E33FF-34FF-460B-8EA6-5D55811A901C}
24+
EndGlobalSection
25+
EndGlobal
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<configuration>
3+
<startup>
4+
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
5+
</startup>
6+
</configuration>
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+
<ProjectGuid>{4239D6E5-70EF-4350-8C77-39F955E95FF0}</ProjectGuid>
8+
<OutputType>WinExe</OutputType>
9+
<RootNamespace>Arduino_LEDMatrix_GUI</RootNamespace>
10+
<AssemblyName>Arduino_LEDMatrix_GUI</AssemblyName>
11+
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
12+
<FileAlignment>512</FileAlignment>
13+
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
14+
<Deterministic>true</Deterministic>
15+
</PropertyGroup>
16+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
17+
<PlatformTarget>AnyCPU</PlatformTarget>
18+
<DebugSymbols>true</DebugSymbols>
19+
<DebugType>full</DebugType>
20+
<Optimize>false</Optimize>
21+
<OutputPath>bin\Debug\</OutputPath>
22+
<DefineConstants>DEBUG;TRACE</DefineConstants>
23+
<ErrorReport>prompt</ErrorReport>
24+
<WarningLevel>4</WarningLevel>
25+
</PropertyGroup>
26+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
27+
<PlatformTarget>AnyCPU</PlatformTarget>
28+
<DebugType>pdbonly</DebugType>
29+
<Optimize>true</Optimize>
30+
<OutputPath>bin\Release\</OutputPath>
31+
<DefineConstants>TRACE</DefineConstants>
32+
<ErrorReport>prompt</ErrorReport>
33+
<WarningLevel>4</WarningLevel>
34+
</PropertyGroup>
35+
<PropertyGroup>
36+
<ApplicationIcon>Resources\icon_64.ico</ApplicationIcon>
37+
</PropertyGroup>
38+
<ItemGroup>
39+
<Reference Include="System" />
40+
<Reference Include="System.Core" />
41+
<Reference Include="System.Xml.Linq" />
42+
<Reference Include="System.Data.DataSetExtensions" />
43+
<Reference Include="Microsoft.CSharp" />
44+
<Reference Include="System.Data" />
45+
<Reference Include="System.Deployment" />
46+
<Reference Include="System.Drawing" />
47+
<Reference Include="System.Net.Http" />
48+
<Reference Include="System.Windows.Forms" />
49+
<Reference Include="System.Xml" />
50+
</ItemGroup>
51+
<ItemGroup>
52+
<Compile Include="Form1.cs">
53+
<SubType>Form</SubType>
54+
</Compile>
55+
<Compile Include="Form1.Designer.cs">
56+
<DependentUpon>Form1.cs</DependentUpon>
57+
</Compile>
58+
<Compile Include="Program.cs" />
59+
<Compile Include="Properties\AssemblyInfo.cs" />
60+
<EmbeddedResource Include="Form1.resx">
61+
<DependentUpon>Form1.cs</DependentUpon>
62+
</EmbeddedResource>
63+
<EmbeddedResource Include="Properties\Resources.resx">
64+
<Generator>ResXFileCodeGenerator</Generator>
65+
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
66+
<SubType>Designer</SubType>
67+
</EmbeddedResource>
68+
<Compile Include="Properties\Resources.Designer.cs">
69+
<AutoGen>True</AutoGen>
70+
<DependentUpon>Resources.resx</DependentUpon>
71+
<DesignTime>True</DesignTime>
72+
</Compile>
73+
<None Include="Properties\Settings.settings">
74+
<Generator>SettingsSingleFileGenerator</Generator>
75+
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
76+
</None>
77+
<Compile Include="Properties\Settings.Designer.cs">
78+
<AutoGen>True</AutoGen>
79+
<DependentUpon>Settings.settings</DependentUpon>
80+
<DesignTimeSharedInput>True</DesignTimeSharedInput>
81+
</Compile>
82+
</ItemGroup>
83+
<ItemGroup>
84+
<None Include="App.config" />
85+
</ItemGroup>
86+
<ItemGroup>
87+
<None Include="Resources\ON_LED_50.png" />
88+
</ItemGroup>
89+
<ItemGroup>
90+
<None Include="Resources\OFF_LED_50.png" />
91+
</ItemGroup>
92+
<ItemGroup>
93+
<None Include="Resources\icon_32.ico" />
94+
</ItemGroup>
95+
<ItemGroup>
96+
<None Include="Resources\icon_64.ico" />
97+
</ItemGroup>
98+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
99+
</Project>

0 commit comments

Comments
 (0)