Ejemplo n.º 1
0
        /// <summary>
        /// </summary>
        /// <param name="spi"></param>
        static void ADC_MCP3008Demo(ISPI spi)
        {
            var adc  = new MCP3008(spi);
            var done = false;

            System.Console.Clear();
            const double referenceVoltage = 5;

            while (!done)
            {
                for (var adcPort = 0; adcPort < 1; adcPort++)
                {
                    var adcValue     = adc.Read(adcPort);
                    var voltageValue = adc.ComputeVoltage(referenceVoltage, adcValue);
                    System.Console.WriteLine($"ADC [{adcPort}] = {adcValue}, voltage:{voltageValue}");
                }

                if (System.Console.KeyAvailable)
                {
                    if (System.Console.ReadKey().Key == ConsoleKey.Q)
                    {
                        done = true;
                        break;
                    }
                }
                Thread.Sleep(500);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Test a strip on 1 APA 102 RGB LED.
        /// Old Nusbio extension use nusbio pin 4 for the clock and pin 5 for the data.
        /// APA 102 use a compatible SPI protocol with no CS and MISO, just CLOCK and MOSI.
        /// </summary>
        /// <param name="spi"></param>
        static void Api102RgbLedSample(ISPI spi)
        {
            var brightness = APA102LEDStrip.MAX_BRIGHTNESS / 3 * 2;
            var wait       = 100;
            var api102     = new APA102LEDStrip(1, spi);
            var done       = false;

            while (!done)
            {
                for (int i = 0; i <= 255; i += 4)
                {
                    if (System.Console.KeyAvailable)
                    {
                        if (System.Console.ReadKey().Key == ConsoleKey.Q)
                        {
                            done = true;
                            break;
                        }
                    }

                    var color = APA102LEDStrip.Wheel(i);
                    System.Console.WriteLine($"Index:{i:000}, Color:{APA102LEDStrip.ToHexValue(color)}");
                    api102
                    .AllToOneColor(color, brightness)
                    .Show()
                    .Wait(wait);
                }
            }
            api102.AllOff();
        }
Ejemplo n.º 3
0
 public APA102LEDStrip(int ledCount, ISPI spi)
 {
     this._spi        = spi;
     this._brightness = MAX_BRIGHTNESS / 3;
     this.MaxLed      = ledCount;
     this.Init();
     this.AllOff();
 }
Ejemplo n.º 4
0
 public NusbioMatrix(
     ISPI spi,
     MAX7219_WIRING_TO_8x8_LED_MATRIX max7219Wiring,
     int deviceCount = 1) :
     base(spi, deviceCount)
 {
     this.MAX7219Wiring = max7219Wiring;
 }
Ejemplo n.º 5
0
        public static NusbioMatrix Initialize(
            ISPI spi,
            MAX7219_WIRING_TO_8x8_LED_MATRIX MAX7218Wiring,
            int deviceCount)
        {
            var matrix = new NusbioMatrix(spi, MAX7218Wiring, deviceCount: deviceCount);

            matrix.Begin(DEFAULT_BRIGTHNESS_DEMO);
            return(matrix);
        }
Ejemplo n.º 6
0
        /*
         * Create a new controler
         * Params :
         * dataPin		pin on the Arduino where data gets shifted out
         * clockPin		pin for the clock
         * csPin		pin for selecting the device
         * deviceCount	maximum number of devices that can be controled
         */
        public MAX7219(ISPI spi, int deviceCount = 1, Int16 width = 8, Int16 height = 8) : base(width, height)
        {
            this._spi = spi;

            if (deviceCount <= 0 || deviceCount > MAX_MAX7219_CHAINABLE)
            {
                deviceCount = MAX_MAX7219_CHAINABLE;
            }

            _deviceCount = deviceCount;

            for (var i = 0; i < 64; i++)
            {
                _pixels[i] = 0x00;
            }

            for (var i = 0; i < _deviceCount; i++)
            {
                var r1 = this.SpiTransfer(i, OP_DISPLAYTEST, 0);

                //scanlimit is set to max on startup
                // The scan-limit register sets how many digits are displayed, from 1 to 8. T
                // Originally the MAX7219 is for Display 7-Segment Display from 1 to 8.
                // The scan limit defines how many 7-Segment are contolled.
                // Each 7-Segments require 8 LEDs time 8, it is 8 x 8 = 64.
                // Since we want to handle most of the time 8x8 LEDs we need to set it to
                // the max.
                var r2 = this.SetScanLimit(i, MAX_SCAN_LIMIT - 1);

                // decode is done in source
                var r3 = this.SpiTransfer(i, OP_DECODEMODE, 0); // No decode mode, see datasheet page 7

                this.Clear(i, refresh: true);
                //we go into Shutdown-mode on startup
                this.Shutdown(true, i);
            }
        }
Ejemplo n.º 7
0
        static void CypressFlashMemorySample(ISPI spi)
        {
            var flash = new CypressFlashMemory(spi);

            flash.ReadIdentification();
            System.Console.WriteLine(flash.GetDeviceInfo());
            var _64kAbdcString = PerformanceHelper.Get64kStringAbcd();
            var _64kAbdcBuffer = PerformanceHelper.GetAsciiBuffer(_64kAbdcString).ToList();
            var _64kFredString = PerformanceHelper.Get64kStringFred();
            var _64kFredBuffer = PerformanceHelper.GetAsciiBuffer(_64kFredString).ToList();
            var _64k0123String = PerformanceHelper.Get64kString0123();
            var _64k0123Buffer = PerformanceHelper.GetAsciiBuffer(_64k0123String).ToList();
            var ph             = new PerformanceHelper();
            var WRITE_FLASH    = false;

            if (WRITE_FLASH)
            {
                // flash.FormatFlash((done) => { System.Console.WriteLine($"{done} formatted"); });

                // Write the 16 Mb of FLASH using 64k string
                // Each block or page must be erased before being written

                ph.Start();
                for (var _64kBlock = 10; _64kBlock < flash.MaxBlock; _64kBlock++)
                {
                    ph.AddByte(CypressFlashMemory.BLOCK_SIZE);
                    System.Console.WriteLine($"Writing block:{_64kBlock}/{flash.MaxBlock}, {_64kBlock * 100.0 / flash.MaxBlock:0}%");
                    var r = false;

                    if (_64kBlock == 10)
                    {
                        r = flash.WritePages(_64kBlock * CypressFlashMemory.BLOCK_SIZE, _64k0123Buffer, format: true);
                    }
                    else
                    {
                        if (_64kBlock % 2 == 0)
                        {
                            r = flash.WritePages(_64kBlock * CypressFlashMemory.BLOCK_SIZE, _64kAbdcBuffer, format: true);
                        }
                        else
                        {
                            r = flash.WritePages(_64kBlock * CypressFlashMemory.BLOCK_SIZE, _64kFredBuffer, format: true);
                        }
                    }
                    if (!r)
                    {
                        System.Console.WriteLine($"Error writing block:{_64kBlock}");
                    }
                }
                ph.Stop();
                System.Console.WriteLine($"Write Operation:{ph.GetResultInfo()}");
                System.Console.ReadKey();
            }

            // Read the 16 Mb of FLASH and verify result
            ph = new PerformanceHelper();
            ph.Start();
            for (var _64kBlock = 10; _64kBlock < flash.MaxBlock; _64kBlock++)
            {
                System.Console.WriteLine($"Reading block:{_64kBlock}/{flash.MaxBlock}, {_64kBlock*100.0/flash.MaxBlock:0}%");
                var buffer = new List <byte>();
                if (flash.ReadPages(_64kBlock * CypressFlashMemory.BLOCK_SIZE, CypressFlashMemory.BLOCK_SIZE, buffer))
                {
                    var resultString = PerformanceHelper.AsciiBufferToString(buffer.ToArray());
                    ph.AddByte(CypressFlashMemory.BLOCK_SIZE);
                    var result = false;
                    if (_64kBlock % 2 == 0)
                    {
                        result = (resultString == _64kAbdcString);
                        System.Console.WriteLine($"Reading block:{_64kBlock}, Status:{result}");
                    }
                    else
                    {
                        result = (resultString == _64kFredString);
                        System.Console.WriteLine($"Reading block:{_64kBlock}, Status:{result}");
                    }
                    if (!result && Debugger.IsAttached)
                    {
                        Debugger.Break();
                    }
                }
            }
            ph.Stop();
            System.Console.WriteLine($"Read Operation:{ph.GetResultInfo()}");
            System.Console.ReadKey();
        }
Ejemplo n.º 8
0
 public CypressFlashMemory(ISPI spi)
 {
     this.SetUserHardwareInterfaceState(DeviceState.Initializing);
     this._spi = spi;
 }
Ejemplo n.º 9
0
 public MCP300X_Base(int maxADConverter, ISPI spi)
 {
     this._spi           = spi;
     this.MaxAdConverter = maxADConverter;
 }
Ejemplo n.º 10
0
 public MCP3004(ISPI spi)
     : base(4, spi)
 {
 }
Ejemplo n.º 11
0
 public MCP3008(ISPI spi)
     : base(8, spi)
 {
 }