Click here to Skip to main content
15,891,745 members
Articles / Internet of Things / Arduino

Simulating and controlling GE Color Effects Lights with Arduino

Rate me:
Please Sign up or sign in to vote.
4.80/5 (13 votes)
27 Nov 2012CPOL13 min read 137.8K   1.4K   25  
Simulating and Controlling GE Color Effects Lights with Arduino
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;

namespace GELightsSimulator
{
   class Bulb
   {
      int id = -1; // bulb address
      Color c = Color.Black; // colour of the bulb - default is black
      Pen BulbBorder = Pens.White; // the border of the bulb
      Brush BulbBackground = Brushes.Black; // the background of the bulb
      Rectangle big = Rectangle.Empty; // the rectangle including the border
      Rectangle small = Rectangle.Empty; // the rectangle excluding the border

      public Bulb(int Id, int x, int y)
      {
         // save the address
         id = Id;

         // work out the rectangles
         big = new Rectangle(x, y, 10, 10);
         small = new Rectangle(x+1, y+1, 8, 8);
      }

      public void Set(int r, int g, int b, int brightness)
      {
         // create the colour
         c = Color.FromArgb(brightness, r*16, g*16, b*16);
      }
      public void SetBrightness(int brightness)
      {
         // create the colour
         c = Color.FromArgb(brightness, c.R, c.G, c.B);
      }

      public void Draw(Graphics G)
      {
         // draw the bulb background
         G.FillEllipse(BulbBackground, big);

         // draw the outline
         G.DrawEllipse(BulbBorder, big);

         // draw the bulb content
         G.FillEllipse(new SolidBrush(c), small);
      }

      public Rectangle GetRectangle()
      {
         // return the area to invalidate
         return small;
      }
   }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Australia Australia
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions