Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- 2. using System.Collections.Generic;
- 3. using System.ComponentModel;
- 4. using System.Data;
- 5. using System.Drawing;
- 6. using System.Linq;
- 7. using System.Text;
- 8. using System.Threading.Tasks;
- 9. using System.Windows.Forms;
- 10. using System.IO.Ports;
- 11.
- 12.
- 13. namespace zapnuti_led
- 14. {
- 15. public partial class Form1 : Form
- 16. {
- 17. private SerialPort myport;
- 18.
- 19. public Form1()
- 20. {
- 21. InitializeComponent();
- 22. init();
- 23. }
- 24.
- 25. private void On_btn_Click(object sender, EventArgs e)
- 26. {
- 27. myport.WriteLine("ON");
- 28.
- 29. On_btn.Enabled = false;
- 30. Off_btn.Enabled = true;
- 31. pictureBox1.Image = zapnuti_led.Properties.Resources.zarovka;
- 32. }
- 33.
- 34. private void init()
- 35. {
- 36. try
- 37. {
- 38. myport = new SerialPort();
- 39. myport.BaudRate = 9600;
- 40. myport.PortName = "COM3";
- 41. myport.Open();
- 42. }
- 43. catch (Exception)
- 44. {
- 45. MessageBox.Show("Error!!");
- 46. }
- 47.
- 48. On_btn.Enabled = true;
- 49. Off_btn.Enabled = false;
- 50.
- 51. }
- 52.
- 53. private void Off_btn_Click(object sender, EventArgs e)
- 54. {
- 55. myport.WriteLine("OFF");
- 56.
- 57. On_btn.Enabled = true;
- 58. Off_btn.Enabled = false;
- 59. pictureBox1.Image = zapnuti_led.Properties.Resources.zarovka1;
- 60. }
- 61. }
- 62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement