Advertisement
Guest User

Untitled

a guest
Jan 20th, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.01 KB | None | 0 0
  1. public async Task Initialize()
  2. {
  3. try
  4. {
  5. if (!LightningProvider.IsLightningEnabled)
  6. {
  7. throw new Exception("No lightning provider detected!");
  8. }
  9.  
  10. LowLevelDevicesController.DefaultProvider = LightningProvider.GetAggregateProvider();
  11.  
  12. Gpio = await GpioController.GetDefaultAsync();
  13.  
  14. APhase = Gpio.OpenPin(19);
  15. BPhase = Gpio.OpenPin(6);
  16.  
  17. APhase.SetDriveMode(GpioPinDriveMode.Output);
  18. BPhase.SetDriveMode(GpioPinDriveMode.Output);
  19.  
  20. Pwm = await PwmController.GetDefaultAsync();
  21. Pwm.SetDesiredFrequency(1000);
  22.  
  23. AEnable = Pwm.OpenPin(26);
  24. BEnable = Pwm.OpenPin(13);
  25. }
  26. catch (Exception e)
  27. {
  28. throw e;
  29. }
  30. }
  31.  
  32. private bool stopMove = true;
  33.  
  34. private double speed = 1;
  35.  
  36. public void StopMove()
  37. {
  38. stopMove = true;
  39. }
  40.  
  41. public async Task MoveForward()
  42. {
  43. await Task.Delay(1);
  44. stopMove = false;
  45.  
  46. APhase.Write(GpioPinValue.Low);
  47. BPhase.Write(GpioPinValue.Low);
  48.  
  49. AEnable.SetActiveDutyCyclePercentage(speed);
  50. BEnable.SetActiveDutyCyclePercentage(speed);
  51.  
  52. Debug.WriteLine("Starting...");
  53.  
  54. AEnable.Start();
  55. BEnable.Start();
  56.  
  57. while (!stopMove) { }
  58.  
  59. AEnable.Stop();
  60. BEnable.Stop();
  61.  
  62. AEnable.SetActiveDutyCyclePercentage(0);
  63. BEnable.SetActiveDutyCyclePercentage(0);
  64. }
  65.  
  66. public async Task MoveBackward()
  67. {
  68. await Task.Delay(1);
  69. stopMove = false;
  70.  
  71. APhase.Write(GpioPinValue.High);
  72. BPhase.Write(GpioPinValue.High);
  73.  
  74. AEnable.SetActiveDutyCyclePercentage(speed);
  75. BEnable.SetActiveDutyCyclePercentage(speed);
  76.  
  77. AEnable.Start();
  78. BEnable.Start();
  79.  
  80. while (!stopMove) { }
  81.  
  82. AEnable.Stop();
  83. BEnable.Stop();
  84.  
  85. AEnable.SetActiveDutyCyclePercentage(0);
  86. BEnable.SetActiveDutyCyclePercentage(0);
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement