廣告廣告
  加入我的最愛 設為首頁 風格修改
首頁 首尾
 手機版   訂閱   地圖  簡體 
您是第 11665 個閱讀者
 
發表文章
  可列印版   加為IE收藏   收藏主題   上一主題 | 下一主題   
i1012347 手機 會員卡
個人頭像
個人文章 個人相簿 個人日記 個人地圖
社區建設獎 優秀管理員勳章
頭銜:教育是良心的事業...  教育是良心的事業...
版主
級別: 版主 該用戶目前不上站
版區: (限)限級遊動漫
推文 x480 鮮花 x3890
分享: 轉寄此文章 Facebook Plurk Twitter 複製連結到剪貼簿 轉換為繁體 轉換為簡體 載入圖片
推文 x0
[晴天][快樂] Controlling ServoMotor By Using Of Potentiometer In Arduino  (Arduino//android c# servo)
https://stackoverflow.com/questions/44966702/control-a-servo-by-c-windows-10-iot-and-the-magellanic-servocontroller-cpu-i

https://www.google.com/search?rlz=1C1AOHY_zh-TWTW708TW708&ei=cRI7XNXTC8jc8QXO9b2ADA&q=android+c%23+servo&oq=android+c%23+servo&gs_l=psy-ab.3...2816.8165..8560...0.0..0.107.500.4j2......0....1..gws-wiz.......0i71j0j0i22i30j0i13i30.D87a6QN1xMU
Control a Servo by C#, Windows 10 IoT and the Magellanic.ServoController - CPU issues and how to resolve them?

using Windows.UI.Xaml; using Windows.UI.Xaml.Controls; using Magellanic.ServoController; using System; using System.Threading.Tasks; namespace App5 { public sealed partial class MainPage : Page { public MainPage() { this.InitializeComponent(); } private async Task MoveServoToCentre(double MovementTime, double CalculatedFrequency) {     using (var servo = new ServoController(5)) {         servo.Frequency = Convert.ToInt32(CalculatedFrequency);         await servo.Connect();         servo.SetPosition(90).AllowTimeToMove(Convert.ToInt32(MovementTime)).Go();         servo.Dispose(); } } private async void Slider_Value_ChangedAsync(object sender, Windows.UI.Xaml.Controls.Primitives.RangeBaseValueChangedEventArgs e) { Slider slider = sender as Slider; if (slider.Value < 50) {         await CalculationAsync(slider.Value); } else if (slider.Value > 50) {         await CalculationAsync(slider.Value); } } public string PreviousValue; public double RequiredFrequenz; private async Task CalculationAsync(double value) { if (PreviousValue != null) { double Result = System.Math.Abs(Convert.ToDouble(PreviousValue)) - value; if (Result < 0) { RequiredFrequenz = 100; } else if (Result > 0) { RequiredFrequenz = 200; } double TimeToMove = System.Math.Abs(((int)Math.Round(Result * 3.8))); System.Diagnostics.Debug.WriteLine(TimeToMove); System.Diagnostics.Debug.WriteLine(Result); System.Diagnostics.Debug.WriteLine(value); System.Diagnostics.Debug.WriteLine(PreviousValue); System.Diagnostics.Debug.WriteLine(RequiredFrequenz);         await MoveServoToCentre(TimeToMove, RequiredFrequenz); TimeToMove = 0; } else { if (value > 50) { double TimeToMove = ((int)Math.Round((value - 50) * 3.8)); RequiredFrequenz = 100; System.Diagnostics.Debug.WriteLine(TimeToMove); System.Diagnostics.Debug.WriteLine(value); System.Diagnostics.Debug.WriteLine(PreviousValue); System.Diagnostics.Debug.WriteLine(RequiredFrequenz);           await MoveServoToCentre(TimeToMove, RequiredFrequenz); TimeToMove = 0; } else if (value < 50) { double TimeToMove = System.Math.Abs(((int)Math.Round((value - 50) * 3.8))); RequiredFrequenz = 200; System.Diagnostics.Debug.WriteLine(TimeToMove); System.Diagnostics.Debug.WriteLine(value); System.Diagnostics.Debug.WriteLine(PreviousValue); System.Diagnostics.Debug.WriteLine(RequiredFrequenz);           await MoveServoToCentre(TimeToMove, RequiredFrequenz); TimeToMove = 0; } } PreviousValue = value.ToString();     value = 0; } } }[/pre]

Here a link to the code of the NuGet PlugIn:
https://github.com/jeremylindsayni/Magellanic.Ser...er/ServoController.cs


ServoController servo = new ServoController(5); protected override async void OnNavigatedTo(NavigationEventArgs e) {     await servo.Connect(); } private void MoveServoToCentre(double MovementTime, double CalculatedFrequency) {     servo.Frequency = Convert.ToInt32(CalculatedFrequency);     servo.SetPosition(90).AllowTimeToMove(Convert.ToInt32(MovementTime)).Go(); }[/pre]


shareimprove this answer



Introduction

In this article, I am explaining about  controlling the ServoMotor using Potentiometer in Arduino. In this article, I will control the Servo Motor in the adjustment of Potentiometer. 


Parts of the List
    Arduino UnoPotentiometerServo MotorBread BoardHook up wires 

Connection


Servo Motor
    Connect the Vcc of the Servo Motor to the 5v of the ArduinoUno.Connect the gnd of the bluetooth to the Gnd of the ArduinoUno.Connect the Vin of the bluetooth to the 09 of the ArduinoUno.

Potentiometer
    Connect as per the preceding figure to the Arduino board and the LCD Display.The Vin is connected to the LCD display in 03.
https://www.c-sharpcorner.com/article/controlling-servomotor-by-using-of-potentiometer-in-arduino/


    #include <Servo.h> const int servo1 = 3;       // first servo const int servo2 = 10;      // second servo const int servo3 = 5;       // third servo const int servo4 = 11;      // fourth servo const int servo5 = 9;       // fifth servo const int joyH = 2;        // L/R Parallax Thumbstick const int joyV = 3;        // U/D Parallax Thumbstick const int joyX = 4;        // L/R Parallax Thumbstick const int joyP = 5;        // U/D Parallax Thumbstick const int potpin = 0;      // O/C potentiometer int servoVal;           // variable to read the value from the analog pin Servo myservo1;  // create servo object to control a servo Servo myservo2;  // create servo object to control a servo Servo myservo3;  // create servo object to control a servo Servo myservo4;  // create servo object to control a servo Servo myservo5;  // create servo object to control a servo void setup() {     // Servo   myservo1.attach(servo1);  // attaches the servo   myservo2.attach(servo2);  // attaches the servo   myservo3.attach(servo3);  // attaches the servo   myservo4.attach(servo4);  // attaches the servo   myservo5.attach(servo5);  // attaches the servo   // Inizialize Serial   Serial.begin(9600);  }   void loop(){     servoVal = analogRead(potpin);       servoVal = map(servoVal, 0, 1023, 0, 179);     myservo5.write(servoVal);       delay(15);      // Display Joystick values using the serial monitor     outputJoystick();       // Read the horizontal joystick value  (value between 0 and 1023)     servoVal = analogRead(joyH);              servoVal = map(servoVal, 0, 1023, 0, 180);     // scale it to use it with the servo (result  between 0 and 180)     myservo2.write(servoVal);                         // sets the servo position according to the scaled value       // Read the horizontal joystick value  (value between 0 and 1023)     servoVal = analogRead(joyV);               servoVal = map(servoVal, 0, 1023, 70, 180);     // scale it to use it with the servo (result between 70 and 180)     myservo1.write(servoVal);                           // sets the servo position according to the scaled value     delay(15);                                       // waits for the servo to get there // Read the horizontal joystick value  (value between 0 and 1023)     servoVal = analogRead(joyP);               servoVal = map(servoVal, 0, 1023, 70, 180);     // scale it to use it with the servo (result between 70 and 180)     myservo4.write(servoVal);                           // sets the servo position according to the scaled value     delay(15);                                       // waits for the servo to get there // Read the horizontal joystick value  (value between 0 and 1023)     servoVal = analogRead(joyX);               servoVal = map(servoVal, 0, 1023, 70, 180);     // scale it to use it with the servo (result between 70 and 180)     myservo3.write(servoVal);                           // sets the servo position according to the scaled value     delay(15);                                       // waits for the servo to get there }   /** * Display joystick values */ void outputJoystick(){       Serial.print(analogRead(joyH));      Serial.print ("---");      Serial.print(analogRead(joyV));      Serial.println ("----------------");      Serial.print(analogRead(joyP));      Serial.println ("----------------");      Serial.print(analogRead(joyX));      Serial.println ("----------------");  }



吞食天地2
kof 10th
kof2003

<!-- BEGIN 數位男女個人地圖 - bbs-mychat.com - v001 -->
<div><iframe frameborder="0" width="500" height="400" src="http://bbs-mychat.com/map.php?uid=26923&plugin=1&width=500&height=400" marginheight="2" marginwidth="2" scrolling="auto" allowtransparency="yes" name="mychatmap" id="mychatmap"></iframe></div>
<!-- END 數位男女個人地圖 -->
獻花 x0 回到頂端 [樓 主] From:臺灣中華電信股份有限公司 | Posted:2019-01-13 18:33 |

首頁  發表文章
Powered by PHPWind v1.3.6
Copyright © 2003-04 PHPWind
Processed in 0.116014 second(s),query:15 Gzip disabled
本站由 瀛睿律師事務所 擔任常年法律顧問 | 免責聲明 | 本網站已依台灣網站內容分級規定處理 | 連絡我們 | 訪客留言