peony3000

Gadgeteer_DD02_Oled_Colorsense_01

Feb 23rd, 2013
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.63 KB | None | 0 0
  1. using System;
  2. using System.Collections;
  3. using System.Threading;
  4. using Microsoft.SPOT;
  5. using Microsoft.SPOT.Presentation;
  6. using Microsoft.SPOT.Presentation.Controls;
  7. using Microsoft.SPOT.Presentation.Media;
  8. using Microsoft.SPOT.Touch;
  9.  
  10. using Gadgeteer.Networking;
  11. using GT = Gadgeteer;
  12. using GTM = Gadgeteer.Modules;
  13. using Gadgeteer.Modules.GHIElectronics;
  14. using Gadgeteer.Modules.Seeed;
  15.  
  16. namespace Gadgeteer_DD02_Oled_Colorsense_01
  17. {
  18.     public partial class Program
  19.     {
  20.  
  21.         // create a timer that ticks every half second
  22.         GT.Timer timer = new GT.Timer(500);          
  23.  
  24.         // This method is run when the mainboard is powered up or reset.  
  25.         void ProgramStarted()
  26.         {
  27.             /*******************************************************************************************
  28.             Modules added in the Program.gadgeteer designer view are used by typing
  29.             their name followed by a period, e.g.  button.  or  camera.
  30.            
  31.             Many modules generate useful events. Type +=<tab><tab> to add a handler to an event, e.g.:
  32.                 button.ButtonPressed +=<tab><tab>
  33.            
  34.             If you want to do something periodically, use a GT.Timer and handle its Tick event, e.g.:
  35.                 GT.Timer timer = new GT.Timer(1000); // every second (1000ms)
  36.                 timer.Tick +=<tab><tab>
  37.                 timer.Start();
  38.             *******************************************************************************************/
  39.            
  40.             // create a timer tick event handling robot
  41.             timer.Tick += new GT.Timer.TickEventHandler(timer_Tick);
  42.  
  43.             // start the timer ticking
  44.             timer.Start();
  45.  
  46.             // turn on the color sensor lights
  47.             colorSense.ToggleOnboardLED(true);
  48.  
  49.             // Use Debug.Print to show messages in Visual Studio's "Output" window during debugging.
  50.             Debug.Print("Program Started");
  51.         }
  52.  
  53.         void timer_Tick(GT.Timer timer)
  54.         {
  55.             // the timer ticked!
  56.             Debug.Print("Red " + colorSense.ReadColorChannels().Red);
  57.             Debug.Print("Green " + colorSense.ReadColorChannels().Green);
  58.             Debug.Print("Blue " + colorSense.ReadColorChannels().Blue);
  59.             Debug.Print("Clear " + colorSense.ReadColorChannels().Clear);
  60.  
  61.             // match the oled screen color to the color sensor readings
  62.             oledDisplay.SimpleGraphics.BackgroundColor = GT.Color.FromRGB((byte)colorSense.ReadColorChannels().Red, (byte)colorSense.ReadColorChannels().Green, (byte)colorSense.ReadColorChannels().Blue);
  63.         }
  64.     }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment