Last active
August 29, 2015 14:23
-
-
Save bluenex/2bcb7eda6a6bfa74d3b6 to your computer and use it in GitHub Desktop.
Snippet to use Sharpduino to control dcmotor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Sharpduino; | |
using Sharpduino.Constants; | |
static void Main(string[] args) | |
{ | |
// Arduino controlling | |
int PWMvalue = 1; | |
var arduino = new ArduinoUno("COM21"); | |
while (!arduino.IsInitialized) ; | |
arduino.SetPinMode(ArduinoUnoPins.D11_PWM, PinModes.PWM); | |
Console.WriteLine("set pin 11 as PWM"); | |
while (PWMvalue != 0) | |
{ | |
Console.WriteLine("please set PWM value in range 1-255..."); | |
bool parseInt = Int32.TryParse(Console.ReadLine(), out PWMvalue); | |
if (!parseInt) | |
{ | |
Console.WriteLine("your input is not string nor convertable number."); | |
PWMvalue = 0; | |
} | |
arduino.SetPWM(ArduinoUnoPWMPins.D11_PWM, PWMvalue); | |
Console.WriteLine("set PWM = {0}", PWMvalue); | |
Console.WriteLine("fill 0 to exit or set any number in range 1-255 to continue."); | |
} | |
arduino.SetPWM(ArduinoUnoPWMPins.D11_PWM, 0); | |
Console.WriteLine("set PWM = 0"); | |
Console.WriteLine("disposing..."); | |
arduino.Dispose(); | |
Console.WriteLine("arduino disposed, press any key to terminate.."); | |
Console.ReadKey(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment