📄 form1.cs
字号:
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(448, 149);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.linkLabel1,
this.button_Address,
this.textBox_port_adress,
this.textBox_byte,
this.pictureBox_D0,
this.pictureBox_D1,
this.pictureBox_D2,
this.pictureBox_D3,
this.pictureBox_D4,
this.pictureBox_D5,
this.pictureBox_D6,
this.pictureBox_D7,
this.button_Dance,
this.button_Count,
this.Not,
this.button_Reset_Leds,
this.checkBox_Pin8,
this.checkBox_Pin7,
this.checkBox_Pin6,
this.checkBox_Pin5,
this.checkBox_Pin4,
this.checkBox_Pin3,
this.checkBox_Pin2,
this.checkBox_Pin1,
this.button_Send_Bits});
this.MaximizeBox = false;
this.Name = "Form1";
this.Text = "Controlling LEDs with Parallel Port";
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void Reset_LEDs() // Makes all the data pins low so the LED's turned off
{
PortAccess.Output(adress, 0);
}
#region LED Picture Loadings
private void LoadNewPict_D0()
{
string path = @"C:\C#\LED\on.gif";
this.pictureBox_D0.Image = Image.FromFile (path);
}
private void LoadNewPict_D1()
{
string path = @"C:\C#\LED\on.gif";
this.pictureBox_D1.Image = Image.FromFile (path);
}
private void LoadNewPict_D2()
{
string path = @"C:\C#\LED\on.gif";
this.pictureBox_D2.Image = Image.FromFile (path);
}
private void LoadNewPict_D3()
{
string path = @"C:\C#\LED\on.gif";
this.pictureBox_D3.Image = Image.FromFile (path);
}
private void LoadNewPict_D4()
{
string path = @"C:\C#\LED\on.gif";
this.pictureBox_D4.Image = Image.FromFile (path);
}
private void LoadNewPict_D5()
{
string path = @"C:\C#\LED\on.gif";
this.pictureBox_D5.Image = Image.FromFile (path);
}
private void LoadNewPict_D6()
{
string path = @"C:\C#\LED\on.gif";
this.pictureBox_D6.Image = Image.FromFile (path);
}
private void LoadNewPict_D7()
{
string path = @"C:\C#\LED\on.gif";
this.pictureBox_D7.Image = Image.FromFile (path);
}
private void LoadOldPict_D0()
{
string path = @"C:\C#\LED\off.gif";
this.pictureBox_D0.Image = Image.FromFile (path);
}
private void LoadOldPict_D1()
{
string path = @"C:\C#\LED\off.gif";
this.pictureBox_D1.Image = Image.FromFile (path);
}
private void LoadOldPict_D2()
{
string path = @"C:\C#\LED\off.gif";
this.pictureBox_D2.Image = Image.FromFile (path);
}
private void LoadOldPict_D3()
{
string path = @"C:\C#\LED\off.gif";
this.pictureBox_D3.Image = Image.FromFile (path);
}
private void LoadOldPict_D4()
{
string path = @"C:\C#\LED\off.gif";
this.pictureBox_D4.Image = Image.FromFile (path);
}
private void LoadOldPict_D5()
{
string path = @"C:\C#\LED\off.gif";
this.pictureBox_D5.Image = Image.FromFile (path);
}
private void LoadOldPict_D6()
{
string path = @"C:\C#\LED\off.gif";
this.pictureBox_D6.Image = Image.FromFile (path);
}
private void LoadOldPict_D7()
{
string path = @"C:\C#\LED\off.gif";
this.pictureBox_D7.Image = Image.FromFile (path);
}
#endregion
void onCheckBoxClick(object sender, EventArgs e) //For checkboxes and the imageboxes you can also use a loop here
{
int value = 0;
if(checkBox_Pin1.Checked)
{
value += (int)Math.Pow(2,0);
LoadNewPict_D0();
}
else
LoadOldPict_D0();
value += 0;
if(checkBox_Pin2.Checked)
{
value += (int)Math.Pow(2,1);
LoadNewPict_D1();
}
else
LoadOldPict_D1();
value += 0;
if(checkBox_Pin3.Checked)
{
value += (int)Math.Pow(2,2);
LoadNewPict_D2();
}
else
LoadOldPict_D2();
value += 0;
if(checkBox_Pin4.Checked)
{
value += (int)Math.Pow(2,3);
LoadNewPict_D3();
}
else
LoadOldPict_D3();
value += 0;
if(checkBox_Pin5.Checked)
{
value += (int)Math.Pow(2,4);
LoadNewPict_D4();
}
else
LoadOldPict_D4();
value += 0;
if(checkBox_Pin6.Checked)
{
value += (int)Math.Pow(2,5);
LoadNewPict_D5();
}
else
LoadOldPict_D5();
value += 0;
if(checkBox_Pin7.Checked)
{
value += (int)Math.Pow(2,6);
LoadNewPict_D6();
}
else
LoadOldPict_D6();
value += 0;
if(checkBox_Pin8.Checked)
{
value += (int)Math.Pow(2,7);
LoadNewPict_D7();
}
else
LoadOldPict_D7();
value += 0;
PortAccess.Output(adress, value);
}
private void button_Send_Bits_Click(object sender, System.EventArgs e) // Sends decimal to data pins
{
PortAccess.Output(adress, Int32.Parse(this.textBox_byte.Text));
}
private void button_Reset_Leds_Click(object sender, System.EventArgs e) // Unchecks the checkboxes and reset leds
{
j=0; i=0;
Reset_LEDs();
checkBox_Pin8.Checked = false;
checkBox_Pin7.Checked = false;
checkBox_Pin6.Checked = false;
checkBox_Pin5.Checked = false;
checkBox_Pin4.Checked = false;
checkBox_Pin3.Checked = false;
checkBox_Pin2.Checked = false;
checkBox_Pin1.Checked = false;
}
void dance_LEDs(object o2, EventArgs e2) //Gives a motion to the LEDs
{
if(j<9)
{
switch(j)
{
case 0:
PortAccess.Output(888, 24);
break;
case 1:
PortAccess.Output(888, 36);
break;
case 2:
PortAccess.Output(888, 66);
break;
case 3:
PortAccess.Output(888, 129);
break;
case 4:
PortAccess.Output(888, 0);
break;
case 5:
PortAccess.Output(888, 129);
break;
case 6:
PortAccess.Output(888, 195);
break;
case 7:
PortAccess.Output(888, 231);
break;
case 8:
PortAccess.Output(888, 255);
break;
}
}
else
{
((System.Windows.Forms.Timer)o2).Stop();
((System.Windows.Forms.Timer)o2).Tick -= new EventHandler(dance_LEDs);
}
j+=1;
}
private void button_Dance_Click(object sender, System.EventArgs e) // Executes the timer and dance LEDs function
{
System.Windows.Forms.Timer timer02 = new System.Windows.Forms.Timer();
timer02.Interval = 200;
timer02.Tick += new EventHandler(dance_LEDs);
timer02.Enabled = true;
}
void count_binary(object o1, EventArgs e1) //Makes the leds counting in binary form
{
if(i<256)
{
PortAccess.Output(adress, i);
i+=1;
}
else
{
((System.Windows.Forms.Timer)o1).Stop();
((System.Windows.Forms.Timer)o1).Tick -= new EventHandler(count_binary);
}
}
private void button_Count_Click(object sender, System.EventArgs e) //Activates the timer for bnary counting delays
{
System.Windows.Forms.Timer timer01 = new System.Windows.Forms.Timer();
timer01.Interval = 100;
timer01.Tick += new EventHandler(count_binary);
timer01.Enabled = true;
}
private void button_Address_Click(object sender, System.EventArgs e) //Sets the parallel port address for the program to run
{
if(this.textBox_port_adress.Text == "378")
adress = 888;
else
adress = 632;
}
private void linkLabel1_LinkClicked_1(object sender, System.Windows.Forms.LinkLabelLinkClickedEventArgs e)
{
// Change the color of the link text by setting LinkVisited
// to True.
linkLabel1.LinkVisited = true;
// Call the Process.Start method to open the default browser
// with a URL:
System.Diagnostics.Process.Start("mailto:ls@izdir.com");
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -