private Vector2 CalculatePosition(NeoPixelSetup neoPixelSetup, NeoPixelStrip strip, int pixelNumber)
 {
     if (strip.StripPosition == StripPosition.Bottom)
     {
         if (strip.RowIndex % 2 == 0)
         {
             return(CalculateBottomLeftPosition(neoPixelSetup, strip, pixelNumber));
         }
         else
         {
             return(CalculateBottomRightPosition(neoPixelSetup, strip, pixelNumber));
         }
     }
     else
     {
         if (strip.RowIndex % 2 == 0)
         {
             return(CalculateTopLeftPosition(neoPixelSetup, strip, pixelNumber));
         }
         else
         {
             return(CalculateTopRightPosition(neoPixelSetup, strip, pixelNumber));
         }
     }
 }
        private Vector2 CalculateTopRightPosition(NeoPixelSetup neoPixelSetup, NeoPixelStrip strip, int pixelNumber)
        {
            float  distanceBetweenPixels = neoPixelSetup.StripLength / strip.Pixels.Length;
            double triangleSide          = CalculateIsoscelesRightTriangleSide(distanceBetweenPixels);
            float  y = (float)(pixelNumber * triangleSide + strip.Pixels.Length * triangleSide);
            float  x = (float)(pixelNumber * triangleSide + strip.RowIndex * neoPixelSetup.DistanceBetweenStrips);

            return(new Vector2(x, y));
        }
        protected static void StartNeoPixel()
        {
            strip = new NeoPixelStrip(150, "neopixelstrip01");

            CreateCyclesCollection();

            neoPixelThread          = new Thread(StartNeoPixelThread);
            neoPixelThread.Priority = ThreadPriority.Lowest;
            neoPixelThread.Start();
        }
Exemple #4
0
        public static void Main()
        {
            strip     = new NeoPixelStrip(50, "LaughOMeter");
            analogPin = new AnalogInput(Cpu.AnalogChannel.ANALOG_3);

            while (true)
            {
                try
                {
                    Debug.Print(analogPin.Read().ToString());
                    strip.SetLevel(((ushort)(analogPin.Read() * 100 / maxVal)), palette);
                }
                catch { }
                Thread.Sleep(500);
            }
        }
Exemple #5
0
        public static NeoPixelSetup CreateNeoPixelSetup(
            IEnumerable <string> driverNames,
            int stripsPerDriver,
            int pixelsPerStrip)
        {
            List <NeoPixelDriver> drivers = new List <NeoPixelDriver>();
            int stripCount = 0;

            foreach (var driverName in driverNames)
            {
                var driver = new NeoPixelDriver()
                {
                    Name = driverName
                };
                for (int i = 0; i < stripsPerDriver; i++)
                {
                    var strip = new NeoPixelStrip()
                    {
                        Pixels        = new Color[pixelsPerStrip],
                        StripPosition = stripCount % 2 == 0 ? StripPosition.Bottom : StripPosition.Top,
                        RowIndex      = stripCount / 2
                    };
                    stripCount++;
                    for (int j = 0; j < pixelsPerStrip; j++)
                    {
                        strip.Pixels[j] = Color.Black;
                    }
                    driver.Strips.Add(strip);
                }
                drivers.Add(driver);
            }

            //Measurements from RL
            float distanceBetweenStrips = 10.666f;
            float stripLength           = 75f;

            return(new NeoPixelSetup()
            {
                Drivers = drivers,
                DistanceBetweenStrips = distanceBetweenStrips,
                StripLength = stripLength,
            });
        }
 /// <summary>
 /// Get the XY position of a given pixel.
 /// (0,0) is bottom left
 /// Expects the angle to be 45 degrees between pixels
 /// </summary>
 public Vector2 GetPosition(NeoPixelStrip strip, int pixelIndex)
 {
     return(precalculatedPixelPositions[strip][pixelIndex]);
 }