Advertisement
VinSS

Servo_0.1

Nov 18th, 2019
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.52 KB | None | 0 0
  1. Servo servo1;
  2.  
  3. void setup() {
  4. // put your setup code here, to run once:
  5. servo1.attach(6);
  6. Serial.begin(9600);
  7. Serial.println("Start");
  8. }
  9.  
  10. void loop() {
  11. // put your main code here, to run repeatedly:
  12.  
  13. for(int i = 0; i < 180; i += 10)
  14. {
  15. Serial.println(i);
  16. delay(3000);
  17. servo1.write(i);
  18. }
  19. }
  20. -------------------------------------------------------------------------------------
  21. using System;
  22. using System.Collections.Generic;
  23. using System.ComponentModel;
  24. using System.Data;
  25. using System.Drawing;
  26. using System.Linq;
  27. using System.Text;
  28. using System.Threading.Tasks;
  29. using System.Windows.Forms;
  30.  
  31. using System.IO.Ports;
  32.  
  33. namespace WindowsFormsApplication3
  34. {
  35. public partial class Form1 : Form
  36. {
  37. public Form1()
  38. {
  39. InitializeComponent();
  40.  
  41. comboBox1.Items.Clear();
  42. foreach (string portName in SerialPort.GetPortNames())
  43. {
  44. comboBox1.Items.Add(portName);
  45. }
  46. comboBox1.SelectedIndex = 0;
  47. }
  48.  
  49. private void button2_Click(object sender, EventArgs e)
  50. {
  51. serialPort1.Open();
  52. }
  53.  
  54. private void button3_Click(object sender, EventArgs e)
  55. {
  56. serialPort1.Close();
  57. }
  58.  
  59. private void serialPort1_DataReceived(object sender, SerialDataReceivedEventArgs e)
  60. {
  61. SerialPort sp = (SerialPort)sender;
  62. label1.Text = sp.ReadExisting();
  63. }
  64. }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement