Пример #1
0
        public static void Main()
        {
            var LeftJoystick = new AnalogJoystick(Pins.GPIO_PIN_A0, Pins.GPIO_PIN_A1);
            var RightJoystick = new AnalogJoystick(Pins.GPIO_PIN_A2, Pins.GPIO_PIN_A3);

            var matrix = new Max72197221(chipSelect: Pins.GPIO_PIN_D8);

            matrix.Shutdown(Max72197221.ShutdownRegister.NormalOperation);
            matrix.SetDecodeMode(Max72197221.DecodeModeRegister.NoDecodeMode);
            matrix.SetDigitScanLimit(7);
            matrix.SetIntensity(8);

            var comp = new Composition(new byte[8], 8, 8);

            var leftBall = new PlayerMissile("leftBall", 0, 0);
            var rightBall = new PlayerMissile("rightBall", 0, 0);

            comp.AddMissile(leftBall);
            comp.AddMissile(rightBall);

            while (true)
            {
                leftBall.X = LeftJoystick.X / 128;
                leftBall.Y = LeftJoystick.Y / 128;
                rightBall.X = RightJoystick.X / 128;
                rightBall.Y = RightJoystick.Y / 128;

                Debug.Print("X=" + LeftJoystick.X.ToString() + " (" + LeftJoystick.XDirection.ToString() + ")" + ", Y=" + LeftJoystick.Y.ToString() + " (" + LeftJoystick.YDirection.ToString() + ")");

                matrix.Display(comp.GetFrame(0, 0));

                Thread.Sleep(80);
            }
        }
Пример #2
0
        /// <summary>
        /// During development, Main() acts as the ConsoleBootLoader, making it easy to debug the game.
        /// When game development is complete, comment out the content Main() to remove the overhead
        /// </summary>
        public static void Main() {
#if dev
            var joystickLeft = new AnalogJoystick(xAxisPin: Pins.GPIO_PIN_A0, yAxisPin: Pins.GPIO_PIN_A1);
            var joystickRight = new AnalogJoystick(xAxisPin: Pins.GPIO_PIN_A2, yAxisPin: Pins.GPIO_PIN_A3);
            var matrix = new Max72197221(chipSelect: Pins.GPIO_PIN_D8);
            var speaker = new PWM(Pins.GPIO_PIN_D5);
            var resourceLoader = new SDResourceLoader();
            var buttonLeft = new PushButton(Pins.GPIO_PIN_D0, Port.InterruptMode.InterruptEdgeLevelLow, null, Port.ResistorMode.PullUp);
            var buttonRight = new PushButton(Pins.GPIO_PIN_D1, Port.InterruptMode.InterruptEdgeLevelLow, null, Port.ResistorMode.PullUp);
            var args = new object[(int)CartridgeVersionInfo.LoaderArgumentsVersion100.Size];

            var index = 0;
            args[index++] = CartridgeVersionInfo.CurrentVersion;
            args[index++] = joystickLeft;
            args[index++] = joystickRight;
            args[index++] = matrix;
            args[index++] = speaker;
            args[index++] = resourceLoader;
            args[index++] = buttonLeft;
            args[index] = buttonRight;

            matrix.Shutdown(Max72197221.ShutdownRegister.NormalOperation);
            matrix.SetDecodeMode(Max72197221.DecodeModeRegister.NoDecodeMode);
            matrix.SetDigitScanLimit(7);
            matrix.SetIntensity(8);

            Run(args);
#endif
        }
Пример #3
0
        public static void Main() {

            var maxPowerControl = new OutputPort(Pins.GPIO_PIN_D0, false);
            Thread.Sleep(5);

            InitializeSpinnerDisplay();

            _max = new Max72197221(chipSelect: Pins.GPIO_PIN_D8);
            
            DisplayTestMode();

            ShutdownTestMode();

            DigitScanLimitTest();

            DigitDecodeTest();

            StringToDigitTest();

            var spinnerThread = new Thread(Spinner);
            spinnerThread.Start(); 
            
            var intensityThread = new Thread(IntensityTest);
            intensityThread.Start();

            WaitForEver();
        }
Пример #4
0
        public static void Main() {
            using (var matrix = new Max72197221(chipSelect: Pins.GPIO_PIN_D8, speedKHz: 10000)) {

                matrix.Shutdown(Max72197221.ShutdownRegister.NormalOperation);
                matrix.SetDecodeMode(Max72197221.DecodeModeRegister.NoDecodeMode);
                matrix.SetDigitScanLimit(7);
                matrix.SetIntensity(8);

                var comp = new Composition(new byte[]  {
                    0x00, 0x00,
                    0x00, 0x00,
                    0x00, 0x00,
                    0x00, 0x00,
                    0x03, 0xC0,
                    0x07, 0xE0,
                    0x0F, 0xF0,
                    0x0F, 0xF0,
                    0x0F, 0xF0,
                    0x0F, 0xF0,
                    0x07, 0xE0,
                    0x03, 0xC0,
                    0x00, 0x00,
                    0x00, 0x00,
                    0x00, 0x00,
                    0x00, 0x00,
                }, 16, 16);

                var player = new PlayerMissile("player", 0, 0);
                var missile = new PlayerMissile("missile", 0, 0);
                comp.AddMissile(player);
                comp.AddMissile(missile);

                while (true) {
                    for (var angle = 0; angle < 360; angle++) {
                        player.X = 8 + Math.Sin(angle * 2)/160;
                        player.Y = 8 + Math.Cos(angle * 2)/160;
                        missile.X = 8 + Math.Sin(angle) / 160;
                        missile.Y = 8 + Math.Cos(angle) / 160;
                        var frame = comp.GetFrame(Math.Sin(angle*20)/250 + 4, Math.Cos(angle*20)/250 + 4);
                        matrix.Display(frame);
                        Thread.Sleep(25);
                    }
                }
            }
        }
Пример #5
0
        public static void Main()
        {
#if NETDUINO || NETDUINO_PLUS
            var LeftJoystick = new AnalogJoystick(Pins.GPIO_PIN_A0, Pins.GPIO_PIN_A1);
            var RightJoystick = new AnalogJoystick(Pins.GPIO_PIN_A2, Pins.GPIO_PIN_A3);
            var matrix = new Max72197221(chipSelect: Pins.GPIO_PIN_D8);
#endif
#if NETDUINO_MINI
            var LeftJoystick = new AnalogJoystick(Pins.GPIO_PIN_5, Pins.GPIO_PIN_6, minYRange: 1023, maxYRange: 0, centerDeadZoneRadius: 30);
            var RightJoystick = new AnalogJoystick(Pins.GPIO_PIN_7, Pins.GPIO_PIN_8, minYRange: 1023, maxYRange: 0, centerDeadZoneRadius: 30);
            var matrix = new Max72197221(chipSelect: Pins.GPIO_PIN_17);
#endif

            matrix.Shutdown(Max72197221.ShutdownRegister.NormalOperation);
            matrix.SetDecodeMode(Max72197221.DecodeModeRegister.NoDecodeMode);
            matrix.SetDigitScanLimit(7);
            matrix.SetIntensity(4);

            var comp = new Composition(new byte[8], 8, 8);

            var leftBall = new PlayerMissile("leftBall", 0, 0);
            var rightBall = new PlayerMissile("rightBall", 0, 0);

            comp.AddMissile(leftBall);
            comp.AddMissile(rightBall);

            while (true)
            {
                leftBall.X = LeftJoystick.X / 128;
                leftBall.Y = LeftJoystick.Y / 128;
                rightBall.X = RightJoystick.X / 128;
                rightBall.Y = RightJoystick.Y / 128;

                Debug.Print("LEFT: (X=" + LeftJoystick.X + " (" + LeftJoystick.XDirection + ")" + ", Y=" + LeftJoystick.Y + " (" + LeftJoystick.YDirection + "), RIGHT: (X=" + RightJoystick.X + " (" + RightJoystick.XDirection + ")" + ", Y=" + RightJoystick.Y + " (" + RightJoystick.YDirection + ")");

                matrix.Display(comp.GetFrame(0, 0));

                Thread.Sleep(80);
            }
        }
Пример #6
0
        public static void Main() {
            InitializeSpinnerDisplay();

            _max = new Max72197221(chipSelect: Pins.GPIO_PIN_D8);
            
            DisplayTestMode();

            ShutdownTestMode();

            DigitScanLimitTest();

            DigitDecodeTest();

            StringToDigitTest();

            var spinnerThread = new Thread(Spinner);
            spinnerThread.Start(); 
            
            var intensityThread = new Thread(IntensityTest);
            intensityThread.Start();

            WaitForEver();
        }
Пример #7
0
        public static void Main() {
            SDResourceLoader rsc = null;

            Joystick = new AnalogJoystick(Pins.GPIO_PIN_A0, Pins.GPIO_PIN_A1);

            // I'm being lazy here and using the default on-board switch instead of the actual joystick button :)
            JoystickButton = new PushButton(pin: Pins.ONBOARD_SW1, target: new NativeEventHandler(ButtonEventHandler));

            var matrix = new Max72197221(chipSelect: Pins.GPIO_PIN_D8);

            matrix.Shutdown(Max72197221.ShutdownRegister.NormalOperation);
            matrix.SetDecodeMode(Max72197221.DecodeModeRegister.NoDecodeMode);
            matrix.SetDigitScanLimit(7);
            matrix.SetIntensity(8);

            try {
                // Load the resources from the SD card 
                // Place the content of the "SD Card Resources" folder at the root of an SD card
#if NETDUINO_MINI
                StorageDevice.MountSD(SDMountPoint, SPI.SPI_module.SPI1, Pins.GPIO_PIN_13);
#else
                StorageDevice.MountSD(SDMountPoint, SPI.SPI_module.SPI1, Pins.GPIO_PIN_D10);
#endif
                // Load the resources from the SD card 
                // Place the content of the "SD Card Resources" folder at the root of an SD card
                rsc = new SDResourceLoader();
                rsc.Load();

#if NETDUINO_MINI || NETDUINO
                StorageDevice.Unmount(SDMountPoint);
#endif
            }
            catch (IOException e) {
                ShowNoSDPresent(matrix);
            }

            // Using the space invaders bitmap in this example
            var Invaders = (Bitmap) rsc.Bitmaps["spaceinvaders.bmp.bin"];

            while (true) {
                // Read the current direction of the joystick
                X += (int) Joystick.XDirection;
                Y += (int) Joystick.YDirection;

                // Validate the position of the coordinates to prevent out-of-bound exceptions.
                if (X < 0) {
                    X = 0;
                }
                else if (X >= Invaders.Width - Bitmap.FrameSize) {
                    X = Invaders.Width - Bitmap.FrameSize;
                }

                if (Y < 0) {
                    Y = 0;
                }
                else if (Y >= Invaders.Height) {
                    Y = Invaders.Height - 1;
                }

                Debug.Print("X=" + Joystick.X.ToString() + " (" + Joystick.XDirection.ToString() + ")" + ", Y=" + Joystick.Y.ToString() + " (" + Joystick.YDirection.ToString() + ")");

                // move the bitmap according to the direction of the joystick
                matrix.Display(Invaders.GetFrame(X, Y));

                Thread.Sleep(80);
            }
        }
Пример #8
0
 // Shows and SD icon on the matrix and wait for a reset
 private static void ShowNoSDPresent(Max72197221 matrix) {
     matrix.Display(new byte[] { 0x7e, 0x42, 0x42, 0x42, 0x42, 0x42, 0x22, 0x1e });
     while (true) { 
         Thread.Sleep(1000); 
     }
 }