Beispiel #1
0
        public static void Main()
        {
            // For ChipWorkX
            MCP4131 myMCP4131 = new MCP4131(ChipworkX.Pin.PB7, SPI.SPI_module.SPI2);

            // For FEZ (Panda2)
            //MCP4131 myMCP4131 = new MCP4131((Cpu.Pin)FEZ_Pin.Digital.Di51, SPI.SPI_module.SPI2);

            myMCP4131.initTCON();
            Thread.Sleep(100);

            while (true)
            {
                myMCP4131.setTap(128);
                for (int i = 128; i > 0; i--)
                {
                    //myMCP4131.decrement();
                    myMCP4131.setTap(i); // Comment this line and use decrement above
                    Debug.Print("i=" + i);
                    myMCP4131.readTap();
                    Debug.Print("Wiper REG: " + myMCP4131.Wiper_Reg);
                    myMCP4131.readStatus();
                    Debug.Print("Status REG: " + myMCP4131.Status_Reg);
                    myMCP4131.readTCON();
                    Debug.Print("TCON: " + myMCP4131.Tcon_Reg);

                    Thread.Sleep(100);
                }
                Debug.Print("At zero");
                Thread.Sleep(5000);
                
                for (int i = 0; i < 128; i++)
                {
                    //myMCP4131.increment();
                    myMCP4131.setTap(i); // Comment this line and use increment above
                    Debug.Print("i=" + i);
                    myMCP4131.readTap();
                    Debug.Print("Wiper REG: " + myMCP4131.Wiper_Reg);
                    myMCP4131.readStatus();
                    Debug.Print("Status REG: " + myMCP4131.Status_Reg);
                    myMCP4131.readTCON();
                    Debug.Print("TCON: " + myMCP4131.Tcon_Reg);
                    Thread.Sleep(100);
                }
            }
        }
Beispiel #2
0
        public static void Run(string[] args)
        {
            Console.WriteLine("Nusbio initialization");
            var serialNumber = Nusbio.Detect();

            if (serialNumber == null) // Detect the first Nusbio available
            {
                Console.WriteLine("Nusbio not detected");
                return;
            }

            using (var nusbio = new Nusbio(serialNumber))
            {
                Cls(nusbio);

                /*
                 * MCP4131
                 *  CS(SELECT g1)    [    ] VDD(POWER)
                 *  SCK(CLOCK g0)    [    ] P0B(POTENTIOMETER-GND)
                 *  SDI/SDO(MOSI g2) [    ] P0W(OUTPUT)
                 *  VSS(GND)         [    ] P0A(VCC)
                 */
                _mcp4131_10k = new  MCP4131(nusbio,
                                            NusbioGpio.Gpio1, // Select
                                            NusbioGpio.Gpio2, // Mosi
                                            NusbioGpio.None,  // Miso // USE THE SAME FOR NOW
                                            NusbioGpio.Gpio0  // Clock
                                            );
                _mcp4131_10k.Begin();

                //nusbio.SetPinMode(NusbioGpio.Gpio3, PinMode.Input);

                //_mcp4132_100k = new  MCP4132 (nusbio,
                //    NusbioGpio.Gpio3, // Select
                //    NusbioGpio.Gpio2, // Mosi
                //    NusbioGpio.Gpio0 // Clock
                //    );
                //_mcp4132_100k.Begin();

                while (nusbio.Loop())
                {
                    if (Console.KeyAvailable)
                    {
                        var k = Console.ReadKey(true).Key;

                        if (k == ConsoleKey.D0)
                        {
                            TestDigitalPotRange(_mcp4131_10k, !true);
                        }
                        if (k == ConsoleKey.D1)
                        {
                            TestDigitalPotRange(_mcp4132_100k);
                        }
                        if (k == ConsoleKey.L)
                        {
                            DigitalPotRangeForLed(_mcp4131_10k);
                        }
                        if (k == ConsoleKey.O)
                        {
                            OtherApiTests(_mcp4131_10k);
                        }
                        if (k == ConsoleKey.C)
                        {
                            Cls(nusbio);
                        }
                        if (k == ConsoleKey.Q)
                        {
                            break;
                        }
                        Cls(nusbio);
                    }
                }
            }

            Console.Clear();
        }