Advertisement
Dani_info

on/off arduino

Mar 10th, 2018
101
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. 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. namespace ON_OFF_arduino
  13. {
  14.     public partial class Form1 : Form
  15.     {
  16.         public SerialPort myport;
  17.         public Form1()
  18.         {
  19.             InitializeComponent();
  20.         }
  21.  
  22.         private void button1_Click(object sender, EventArgs e)
  23.         {
  24.             myport = new SerialPort();
  25.             myport.BaudRate = 9600;
  26.             myport.PortName = "COM5";
  27.             myport.Open();
  28.             myport.WriteLine("O");
  29.             myport.Close();
  30.         }
  31.  
  32.         private void button2_Click(object sender, EventArgs e)
  33.         {
  34.             myport = new SerialPort();
  35.             myport.BaudRate = 9600;
  36.             myport.PortName = "COM5";
  37.             myport.Open();
  38.             myport.WriteLine("F");
  39.             myport.Close();
  40.         }
  41.     }
  42. }
  43.  
  44. --------------------------------------------------------------------------
  45. void setup()  
  46. {  
  47.    
  48.   Serial.begin(9600);  
  49.   pinMode(13, OUTPUT);  
  50. }  
  51.  
  52.  
  53.  
  54. void loop()  
  55. {  
  56.   if(Serial.available())  
  57.   {  
  58.  char  data=Serial.read();  
  59.   Serial.println(data);  
  60.   switch(data)  
  61.   {  
  62.     case 'O':digitalWrite(13, HIGH);  
  63.     break;  
  64.     case 'F':digitalWrite(13, LOW);  
  65.     break;  
  66.      
  67.   }  
  68.   }  
  69. }
Advertisement
RAW Paste Data Copied
Advertisement