peony3000

Gadgeteer Servo Code (Working)

Apr 25th, 2012
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.52 KB | None | 0 0
  1. using System;
  2. using System.Threading;
  3. using Microsoft.SPOT;
  4. using Microsoft.SPOT.Presentation;
  5. using Microsoft.SPOT.Presentation.Controls;
  6. using Microsoft.SPOT.Presentation.Media;
  7. using Microsoft.SPOT.Touch;
  8.  
  9. using Gadgeteer.Networking;
  10. using GT = Gadgeteer;
  11. using GTM = Gadgeteer.Modules;
  12. using Gadgeteer.Modules.GHIElectronics;
  13.  
  14. namespace Gadgeteer_Servo_Test_02
  15. {
  16.  
  17.  
  18.  
  19.     public partial class Program
  20.     {
  21.            
  22.         GT.Timer timer = new GT.Timer(1000, GT.Timer.BehaviorType.RunContinuously);
  23.         GT.Interfaces.PWMOutput servo;
  24.         Boolean sway = true;
  25.  
  26.         // This method is run when the mainboard is powered up or reset.  
  27.         void ProgramStarted()
  28.         {
  29.  
  30.            
  31.             timer.Tick += new GT.Timer.TickEventHandler(timer_Tick);
  32.             timer.Start();
  33.  
  34.             GT.Socket socket = GT.Socket.GetSocket(11, true, null, null);
  35.             servo = new GT.Interfaces.PWMOutput(socket, GT.Socket.Pin.Seven, extender);
  36.            
  37.             //GT.Interfaces.PWMOutput servo = extender.SetupPWMOutput(GT.Socket.Pin.Seven);
  38.        
  39.             //servo = extender.SetupPWMOutput(GT.Socket.Pin.Seven);
  40.             //servo.Active = true;
  41.          
  42.             // print something so we know we have started
  43.             Debug.Print("Program Started");
  44.         }
  45.  
  46.         void timer_Tick(GT.Timer timer)
  47.         {
  48.            //GetXmlFromWeb();
  49.             if (sway)
  50.             {
  51.                 printServoDisplay(0, Convert.ToUInt32("75"));
  52.                 sway = false;
  53.             }
  54.             else {
  55.                 printServoDisplay(0, Convert.ToUInt32("150"));
  56.                 sway = true;
  57.             }
  58.  
  59.         }
  60.  
  61.      
  62.  
  63.         void printServoDisplay(int lineNumber, uint displaySetting)
  64.         {
  65.             //uint xPos = 0;
  66.             //oledDisplay.SimpleGraphics.DisplayText(displayMessage, Resources.GetFont(Resources.FontResources.NinaB), GT.Color.White, xPos, lineNumber*12);
  67.  
  68.             switch (lineNumber)
  69.             {
  70.                 case 0:
  71.                     // 750,000 to 2,250,000 mid point is 1,500,000
  72.                     //servo.SetPulse(20 * 1000 * 1000, (displaySetting - 10) * 100 * 1000);
  73.                     servo.SetPulse(20 * 1000 * 1000, displaySetting * 10 * 1000);
  74.                    
  75.                     Debug.Print("displaySetting " + displaySetting);
  76.                     break;
  77.                
  78.                 default:
  79.                     break;
  80.             }
  81.        
  82.         }
  83.  
  84.      
  85.  
  86.        
  87.     }
  88. }
Advertisement
Add Comment
Please, Sign In to add comment