peony3000

Gadgeteer Beeper (Weird)

Apr 25th, 2012
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.60 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_Beep_01
  15. {
  16.  
  17.     public partial class Program
  18.     {
  19.            
  20.         GT.Timer timer = new GT.Timer(1000, GT.Timer.BehaviorType.RunContinuously);
  21.         GT.Interfaces.PWMOutput beeper;
  22.         uint highNote = 1000;
  23.         uint lowNote = 100;
  24.         double noteRange;
  25.  
  26.         // This method is run when the mainboard is powered up or reset.  
  27.         void ProgramStarted()
  28.         {
  29.  
  30.             timer.Tick += new GT.Timer.TickEventHandler(timer_Tick);
  31.             timer.Start();
  32.  
  33.             GT.Socket socket = GT.Socket.GetSocket(11, true, null, null);
  34.             beeper = new GT.Interfaces.PWMOutput(socket, GT.Socket.Pin.Seven, eBlockExpansion);
  35.  
  36.             noteRange = highNote - lowNote;
  37.  
  38.             // print something so we know we have started
  39.             Debug.Print("Program Started");
  40.         }
  41.  
  42.         void timer_Tick(GT.Timer timer)
  43.         {
  44.  
  45.             printSound(20, lowNote + (UInt32)(joystick.GetJoystickPostion().X * noteRange));
  46.  
  47.         }
  48.  
  49.      
  50.  
  51.         void printSound(uint soundLength, uint soundSetting)
  52.         {
  53.             beeper.SetPulse(soundLength * 1000 * 1000, soundSetting * 10 * 1000);
  54.             Debug.Print("soundSetting " + soundSetting);
  55.         }
  56.  
  57.      
  58.  
  59.        
  60.     }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment