Esempio n. 1
0
        public static void Main()
        {
            OutputPort led = new OutputPort(Pins.ONBOARD_LED, false);
            InputPort button = new InputPort(Pins.ONBOARD_SW1, false, Port.ResistorMode.Disabled);

            bool buttonState = false;

            while (true)
            {
                buttonState = button.Read();

                if (buttonState == true)
                {

                    string URI = "http://RYANDESKTOP/blinky/home/push";
                    HttpWebRequest request = (HttpWebRequest)WebRequest.Create(URI);
                    request.Method = "GET";
                    HttpWebResponse response = (HttpWebResponse)request.GetResponse();

                    while (buttonState == true)
                    {

                        buttonState = button.Read();

                    }

                     URI = "http://RYANDESKTOP/blinky/home/release";
                    request = (HttpWebRequest)WebRequest.Create(URI);
                    request.Method = "GET";
                    response = (HttpWebResponse)request.GetResponse();

                }
            }
        }
Esempio n. 2
0
        public static void Main()
        {
            // wait for DHCP-allocated IP address and turn
            while (IPAddress.GetDefaultLocalAddress() == IPAddress.Any);

            pc = new ParseClient("[Here goes your Parse Application ID]", "[Here goes your Parse REST API Key]");

            var doorPort = new InputPort(Pins.GPIO_PIN_D0, true, Port.ResistorMode.PullDown);

            bool lastStatus = doorPort.Read();
            bool currentStatus;
            while (true)
            {
                currentStatus = doorPort.Read();
                if (currentStatus != lastStatus)
                {
                    pc.SendPushToChannel((currentStatus ? "Someone closed the door" : "Someone opened the door"));
                }
                lastStatus = currentStatus;
            }
            #region Interrupt port buggy implementation

            //var doorPort = new InterruptPort(Pins.GPIO_PIN_D0, true, Port.ResistorMode.PullDown, Port.InterruptMode.InterruptEdgeBoth);
            //doorPort.OnInterrupt += DoorSwitch_OnInterrupt;
            //Thread.Sleep(Timeout.Infinite);

            #endregion
        }
Esempio n. 3
0
        public static void Test()
        {

            // Create new Thread that runs the ExampleThreadFunction
            Thread ExampleThread = new Thread(new ThreadStart(ExampleThreadFunction));

            // SD stuff is in
            PersistentStorage sdPS = new PersistentStorage("SD");

            // Led stuff is in 
            OutputPort LED;
            LED = new OutputPort((Cpu.Pin)FEZ_Pin.Digital.LED, true);

            // Button stuff in
            InputPort Button;
            Button = new InputPort((Cpu.Pin)FEZ_Pin.Digital.LDR, false,
                                   Port.ResistorMode.PullUp);


            while (true)
            {
                //Led status at the beginning is off
                LED.Write(false);

                if (Button.Read())
                {

                    while (Button.Read()) ;   // wait while busy

                    //Led is on
                    LED.Write(true);

                    // Mount
                    sdPS.MountFileSystem();

                    // Start our new Thread
                    ExampleThread.Start();

                    while (Button.Read()) ;   // wait while busy

                    //Led is off
                    LED.Write(true);

                    // Abort our new Thread
                    ExampleThread.Abort();

                    // Unmount
                    sdPS.UnmountFileSystem();
                }

            }



        }
Esempio n. 4
0
        public static void Main()
        {
            // write your code here
            var led = new OutputPort(Pins.ONBOARD_LED, false);
            var input = new InputPort(Pins.GPIO_PIN_D7, true, Port.ResistorMode.Disabled);

            while (true)
            {
                Debug.Print("input=" + input.Read().ToString());
                led.Write(!input.Read());
                Thread.Sleep(100);
            }
        }
Esempio n. 5
0
        public static void Main()
        {
            // write your code here
            OutputPort led = new OutputPort(Pins.GPIO_PIN_D0, false);
            InputPort button = new InputPort(Pins.GPIO_PIN_D1, false, Port.ResistorMode.PullUp);
            OutputPort ledLight = new OutputPort(Pins.GPIO_PIN_D2, false);
            InputPort buttonLight = new InputPort(Pins.GPIO_PIN_D3, false, Port.ResistorMode.PullUp);
            AnalogInput pot = new AnalogInput(Pins.GPIO_PIN_A0);
            bool buttonState = false;
            bool isDark = false;
            int potValue = 0;

            while (true)
            {
                buttonState = !button.Read();
                isDark = buttonLight.Read() || buttonState;
                ledLight.Write(isDark);
                led.Write(buttonState);
                if (buttonState)
                {
                    //while (buttonState)
                    //{
                    //    potValue = pot.Read();
                    //    led.Write(true);
                    //    Thread.Sleep(potValue*10);
                    //    led.Write(false);
                    //    Thread.Sleep(potValue*10);
                    //    buttonState = !button.Read();
                    //}
                }
            }
        }
Esempio n. 6
0
        public static void Main()
        {
            bool currentState = false, lastState = false;
            led = new OutputPort(Pins.ONBOARD_LED, false);
            btn = new InputPort(Pins.ONBOARD_BTN, false, Port.ResistorMode.Disabled);

            int clicks = 0;

            StartApp(false);

            while (true)
            {
                currentState = btn.Read();

                //if button is pressed
                if (currentState && !lastState)
                {
                    clicks++;
                    bool prime = IsPrime(clicks);
                    if (prime)
                        FlashLed(1, true);

                    Debug.Print(clicks + " > " + prime);
                }

                lastState = currentState;
            }
        }
Esempio n. 7
0
        public static void Main()
        {
            Servo servo = new Servo(PWMChannels.PWM_PIN_D6);
            servo.Start();
            Servo servo2 = new Servo(PWMChannels.PWM_PIN_D9);
            servo2.Start();
            InputPort button = new InputPort(Pins.ONBOARD_BTN, false, Port.ResistorMode.Disabled);
            int pos = 0;

            while (true)
            {
                if (button.Read())
                {
                    if (pos == 0)
                    {
                        servo.MoveServoLeft();
                        servo2.MoveServoLeft();
                        pos = 1;
                    }
                    else if (pos == 1)
                    {
                        servo.MoveServoRight();
                        servo2.MoveServoRight();
                        pos = 0;
                    }
                }
            }
        }
Esempio n. 8
0
        public static void Main()
        {
            // Initialize Outputs
            OutputPort ledBuiltIn = new OutputPort(Pins.ONBOARD_LED, false);
            OutputPort ledGreen = new OutputPort(Pins.GPIO_PIN_D11, true);

            // Initialize Inputs
            InputPort button = new InputPort(Pins.ONBOARD_SW1, false, Port.ResistorMode.Disabled);

            // Declare variables
            bool buttonState = false;
            int buttonPress = 0;

            // Loop until button has been pressed 5 times
            while (buttonPress < 6)
            {
                // Read the button bool
                // TRUE when open, FALSE when closed
                buttonState = button.Read();

                // Turn on blue light when button open
                ledBuiltIn.Write(buttonState);

                // Turn green light on when button closed
                ledGreen.Write(!buttonState);
            }
        }
Esempio n. 9
0
        //click, led will flash twice. click to enter a number n, wait and led will flash n times
        public static void Main()
        {
            OutputPort led = new OutputPort(Pins.ONBOARD_LED, false);
            InputPort btn = new InputPort(Pins.ONBOARD_BTN, false, Port.ResistorMode.Disabled);
            bool currentState = false;
            bool lastState = false;
            int flashes = 0;
            bool ledOn = false;
            int clicks = -1;
            Stopwatch timer = Stopwatch.StartNew(); ;

            while (true)
            {
                timer.Stop();

                //if user has already introduced number
                if(timer.ElapsedMilliseconds > 3000)
                {
                    timer.Reset();

                    while(clicks > 0)
                    {
                        clicks--;
                        led.Write(true);
                        Thread.Sleep(500);
                        led.Write(false);
                        Thread.Sleep(500);
                    }
                }

                timer.Start();

                currentState = btn.Read();

                //if button is pressed
                if (currentState && !lastState)
                {
                    clicks++;

                    //flash led twice to start
                    while(flashes < 4)
                    {
                        led.Write(!ledOn);
                        Thread.Sleep(500);
                        ledOn = !ledOn;
                        flashes++;
                    }

                    if(clicks > 0)
                    {
                        timer.Stop();
                        timer.Reset();
                        timer.Start();
                    }
                }

                lastState = currentState;
            }
        }
Esempio n. 10
0
 public static void GetEndByte(InputPort digitalIn)
 {
     //Better be a 0
     if (digitalIn.Read())
     {
         Thread.Sleep(sleep);
         //And still a 0
         if (digitalIn.Read())
         {
             Thread.Sleep(sleep);
             state = TokenState.READ;
             return;
         }
         state = TokenState.LISTEN;
     }
     state = TokenState.LISTEN;
 }
Esempio n. 11
0
 public static void GetListenByte(InputPort digitalIn)
 {
     while (true)
     {
         //Found our first one...now wait for a 0
         if (!digitalIn.Read())
         {
             while (digitalIn.Read())
             {
                 //noop
             }
         }
         state = TokenState.STARTBYTE;
         Thread.Sleep(sleep);
         break;
     }
 }
Esempio n. 12
0
 public static void Main()
 {
     InputPort inputPort = new InputPort(Cpu.Pin.GPIO_Pin2, false, Port.ResistorMode.PullDown);
     while (true)
     {
         bool state = inputPort.Read(); //polling of port state
         Debug.Print("GPIO input port at pin " + inputPort.Id + " is " + (state ? "high" : "low"));
         Thread.Sleep(10); //enable device to sleep or emulator to react to Visual Studio
     }
 }
Esempio n. 13
0
        public static void Main()
        {
            OutputPort led = new OutputPort(Pins.ONBOARD_LED, false);
            InputPort button = new InputPort(Pins.ONBOARD_SW1, false, Port.ResistorMode.Disabled);
            bool buttonState = false;

            while (true)
            {
                buttonState = button.Read();
                led.Write(!buttonState);
            }
        }
Esempio n. 14
0
        public void Run()
        {
            InputPort D0 = new InputPort(Pins.GPIO_PIN_D0, false, Port.ResistorMode.Disabled);
            InputPort D1 = new InputPort(Pins.GPIO_PIN_D1, false, Port.ResistorMode.Disabled);
            InputPort D2 = new InputPort(Pins.GPIO_PIN_D2, false, Port.ResistorMode.Disabled);
            InputPort D3 = new InputPort(Pins.GPIO_PIN_D3, false, Port.ResistorMode.Disabled);
            InputPort D4 = new InputPort(Pins.GPIO_PIN_D4, false, Port.ResistorMode.Disabled);
            InputPort D5 = new InputPort(Pins.GPIO_PIN_D5, false, Port.ResistorMode.Disabled);
            InputPort D6 = new InputPort(Pins.GPIO_PIN_D6, false, Port.ResistorMode.Disabled);
            //InputPort D7 = new InputPort(Pins.GPIO_PIN_D7, false, Port.ResistorMode.Disabled);
            //InputPort D8 = new InputPort(Pins.GPIO_PIN_D8, false, Port.ResistorMode.Disabled);
            //InputPort D9 = new InputPort(Pins.GPIO_PIN_D9, false, Port.ResistorMode.Disabled);
            //InputPort D10 = new InputPort(Pins.GPIO_PIN_D10, false, Port.ResistorMode.Disabled);
            //InputPort D11 = new InputPort(Pins.GPIO_PIN_D11, false, Port.ResistorMode.Disabled);
            //InputPort D12 = new InputPort(Pins.GPIO_PIN_D12, false, Port.ResistorMode.Disabled);
            //InputPort D13 = new InputPort(Pins.GPIO_PIN_D13, false, Port.ResistorMode.Disabled);

            //OutputPort D0 = new OutputPort(Pins.GPIO_PIN_D0, false);
            //OutputPort D1 = new OutputPort(Pins.GPIO_PIN_D1, false);
            //OutputPort D2 = new OutputPort(Pins.GPIO_PIN_D2, false);
            //OutputPort D3 = new OutputPort(Pins.GPIO_PIN_D3, false);
            //OutputPort D4 = new OutputPort(Pins.GPIO_PIN_D4, false);
            //OutputPort D5 = new OutputPort(Pins.GPIO_PIN_D5, false);
            //OutputPort D6 = new OutputPort(Pins.GPIO_PIN_D6, false);
            OutputPort D7 = new OutputPort(Pins.GPIO_PIN_D7, false);
            OutputPort D8 = new OutputPort(Pins.GPIO_PIN_D8, false);
            OutputPort D9 = new OutputPort(Pins.GPIO_PIN_D9, false);
            OutputPort D10 = new OutputPort(Pins.GPIO_PIN_D10, false);
            OutputPort D11 = new OutputPort(Pins.GPIO_PIN_D11, false);
            OutputPort D12 = new OutputPort(Pins.GPIO_PIN_D12, false);
            OutputPort D13 = new OutputPort(Pins.GPIO_PIN_D13, false);

            bool buttonState = true;

            while (true)
            {
                buttonState = D0.Read();
                D7.Write(!buttonState);
                //buttonState = D1.Read();
                //D8.Write(!buttonState);
                //buttonState = D2.Read();
                //D9.Write(!buttonState);
                //buttonState = D3.Read();
                //D10.Write(!buttonState);
                //buttonState = D4.Read();
                //D11.Write(!buttonState);
                //buttonState = D5.Read();
                //D12.Write(!buttonState);
                //buttonState = D6.Read();
                //D13.Write(!buttonState);
            }
        }
        public static void Main()
        {
            OutputPort led = new OutputPort(Pins.GPIO_PIN_D0, false);
            InputPort button = new InputPort(Pins.GPIO_PIN_D1, false, Port.ResistorMode.PullUp);

            bool buttonState = false;

            while (true)
            {
                buttonState = !button.Read();
                led.Write(buttonState);
            }
        }
Esempio n. 16
0
        public static void Main()
        {
            var led = new OutputPort(Pins.GPIO_PIN_D13, false);

            var button = new InputPort(Pins.GPIO_PIN_D2, false, Port.ResistorMode.Disabled);
            while (true)
            {
                if (!button.Read())
                {
                    led.Write(!led.Read());
                    Thread.Sleep(1000);
                }
            }
        }
Esempio n. 17
0
        public static void Main()
        {
            OutputPort LED;
            InputPort Button;

            //Read the status of the button and pass state to LED. LED turns off when button is pressed.
            LED = new OutputPort((Cpu.Pin)FEZ_Pin.Digital.LED, true);
            Button = new InputPort((Cpu.Pin)FEZ_Pin.Digital.LDR, false, Port.ResistorMode.PullUp);

            while (true)
            {
                LED.Write(!Button.Read());
                Thread.Sleep(10);
            }
        }
Esempio n. 18
0
 public static void Main()
 {
     // write your code here 
     var led=new OutputPort(Pins.ONBOARD_LED, false);
     
     var button = new InputPort(Pins.ONBOARD_SW1, false, Port.ResistorMode.Disabled);
     while (true)
     {
         if (!button.Read())
         {
             led.Write(!led.Read());
             Thread.Sleep(300);
         }
     }
 }
Esempio n. 19
0
        static void inputButton(OutputPort[] leds)
        {
            var button = new InputPort(ButtonPin, true, Port.ResistorMode.Disabled);
            var led = new OutputPort(UserPin, false);
            (new Thread(() =>
            {
                while (true)
                {
                    var isPressed = !button.Read();

                    led.Write(isPressed);
                    Thread.Sleep(100);
                }
            })).Start();
        }
Esempio n. 20
0
        public void Run()
        {
            OutputPort led = new OutputPort(Pins.ONBOARD_LED, false);
            InputPort button = new InputPort(Pins.ONBOARD_SW1, false, Port.ResistorMode.Disabled);
            InputPort button2 = new InputPort(Pins.GPIO_PIN_A0, false, Port.ResistorMode.Disabled);

            bool buttonState = false;
            while (true)
            {

                buttonState = button.Read() || button2.Read();
                led.Write(buttonState);

            }
        }
Esempio n. 21
0
        /// <summary>
        /// View pictures stored on local SD card.
        /// </summary>
        static void PictureViewerTimer_Tick(object temp)
        {
            FileStream fileStream = null;

            byte[] data;
            Bitmap myPic;

            GHI.Glide.UI.Image image;

            int joystickLevel = analogLinearScale(steeringWheelAnalog.Read(), 0, 255);

            if (joystickLevel > 200)
            {
                try
                {
                    picCounter = (picCounter + 1) % sdCardJpgFileNames.Length;
                    fileStream = new FileStream(sdCardJpgFileNames[picCounter], FileMode.Open);

                    //load the data from the stream
                    data = new byte[fileStream.Length];
                    fileStream.Read(data, 0, data.Length);

                    myPic = new Bitmap(data, Bitmap.BitmapImageType.Jpeg);

                    image = (GHI.Glide.UI.Image)pictureWindow.GetChildByName("imgPicture");
                    //image.Bitmap = Resources.GetBitmap(Resources.BitmapResources.logo);
                    image.Bitmap.DrawImage(0, 0, myPic, 0, 0, 320, 240);

                    fileStream.Close();


                    image.Invalidate();
                }
                catch { }

                Thread.Sleep(500);
            }
            else if (!rightJoystickSelect.Read())  //button select pressed equals false
            {
                PictureViewerTimer.Change(-1, -1); //stop timer
                Thread.Sleep(100);
                Tween.SlideWindow(_mainWindow, pictureWindow, GHI.Glide.Direction.Up);
                Glide.MainWindow = _mainWindow;

                RoverJoystickControlTimer.Change(0, RoverJoystickTimerPeriod);
                UpdateMainWindowTimer.Change(0, UpdateMainWindowTimerPeriod);
            }
        }
Esempio n. 22
0
        public void Run()
        {
            Debug.Print("Starting");

            InputPort button = new InputPort(Pins.ONBOARD_SW1, false, Port.ResistorMode.Disabled);
            button = new InputPort(Pins.GPIO_PIN_D2, false, Port.ResistorMode.Disabled);
            OutputPort led = new OutputPort(Pins.ONBOARD_LED, false);

            while (true)
            {
                bool state = !button.Read();
                Debug.Print(state ? "On" : "   Off");
                led.Write(state);
                Thread.Sleep(5);
            }
        }
Esempio n. 23
0
        public static void Main()
        {
            // write your code here
            OutputPort led = new OutputPort(Pins.ONBOARD_LED, false);
            InputPort button = new InputPort(Pins.ONBOARD_SW1, false, Port.ResistorMode.Disabled);
            bool buttonState = false;

            while (true)
            {
                buttonState = button.Read();
                led.Write(!buttonState);
                //Thread.Sleep(700);
                //led.Write(buttonState);

            }
        }
Esempio n. 24
0
        public static void Main()
        {
            var addressSetting = new InputPort((Cpu.Pin) FEZ_Pin.Digital.Di52, false, Port.ResistorMode.Disabled);
            var address = addressSetting.Read() ? 2 : 1;

            var storage = new PersistentStorage("SD");
            storage.MountFileSystem();

            var receiver = new SerialReceiver("COM1", 115200, (byte)address);
            var handler = new CommandHandler(FEZ_Pin.Digital.Di8);

            receiver.CommandReceived += handler.HandleCommand;

            while(true)
                Thread.Sleep(1000);
        }
Esempio n. 25
0
 public static void Main()
 {
     LED ledonboard = new LED{Acceso = true, led = new OutputPort((Cpu.Pin)FEZ_Pin.Digital.LED, true)}; //Dichiarazione di un led ( in questo cas oon Board)
      InputPort portaBottone = new InputPort((Cpu.Pin)FEZ_Pin.Digital.LDR, true, Port.ResistorMode.PullUp); //Dichiarazione di una porta input che gestisce un bottone.
      bool statoBottone; //V ariabile booleana dello stato attuale del bottone
      bool statoPrecedente = ledonboard.GetState(); //Variabile booleana che memorizza i valori precedenti del bottone
      while (true)
      {
         statoBottone = portaBottone.Read();
         if(statoBottone == false && statoBottone != statoPrecedente) //Controllo del bottone: false premuto, true a riposo.
         {
             ledonboard.TurnedOnForTime(); ; //Inverte lo stato attuale del bottone.
         }
         statoPrecedente = statoBottone;
     }
 }
Esempio n. 26
0
        private void OldMain()
        {
            OutputPort led = new OutputPort(SecretLabs.NETMF.Hardware.Netduino.Pins.GPIO_PIN_D9, true);
            InputPort button = new InputPort(SecretLabs.NETMF.Hardware.Netduino.Pins.GPIO_PIN_D1, true, Port.ResistorMode.PullUp);

            while (true)
            {
                if (button.Read() == false)
                {
                    led.Write(false);
                    Thread.Sleep(200);
                    led.Write(true);
                    Thread.Sleep(200);

                }
            }
        }
Esempio n. 27
0
 public static void Main()
 {
     #region BlinkingLed
     InputPort sw1 = new InputPort(Pins.ONBOARD_SW1, false,Port.ResistorMode.Disabled);
     OutputPort led = new OutputPort(Pins.ONBOARD_LED, false);
     OutputPort[] ports = new OutputPort[14];
     ports[0] = new OutputPort(Pins.GPIO_PIN_D0, false);
     ports[1] = new OutputPort(Pins.GPIO_PIN_D1, false);
     ports[2] = new OutputPort(Pins.GPIO_PIN_D2, false);
     ports[3] = new OutputPort(Pins.GPIO_PIN_D3, false);
     ports[4] = new OutputPort(Pins.GPIO_PIN_D4, false);
     ports[5] = new OutputPort(Pins.GPIO_PIN_D5, false);
     ports[6] = new OutputPort(Pins.GPIO_PIN_D6, false);
     ports[7] = new OutputPort(Pins.GPIO_PIN_D7, false);
     ports[8] = new OutputPort(Pins.GPIO_PIN_D8, false);
     ports[9] = new OutputPort(Pins.GPIO_PIN_D9, false);
     ports[10] = new OutputPort(Pins.GPIO_PIN_D10, false);
     ports[11] = new OutputPort(Pins.GPIO_PIN_D11, false);
     ports[12] = new OutputPort(Pins.GPIO_PIN_D12, false);
     ports[13] = new OutputPort(Pins.GPIO_PIN_D13, false);
     int index = 0;
     bool newValue=false;
     DateTime expectedTime = DateTime.Now.AddSeconds(1);
     while (true)
     {
         bool state = sw1.Read();
         led.Write(state);
         if (DateTime.Now < expectedTime)
         {
             continue;
         }
         expectedTime = DateTime.Now.AddSeconds(1);
         newValue = !newValue;
         ports[index].Write(newValue);
         if (newValue)
             continue;
         else
         {
             index++;
             if (index > 13)
                 index = 0;
         }
     }
     #endregion
 }
Esempio n. 28
0
        public static void Main()
        {
            _random = new Random(DateTime.Now.Millisecond);
            _ingestTimer = new Timer(new TimerCallback(SendTelemetry), null, 0, 1000);

            OutputPort led = new OutputPort(Pins.ONBOARD_LED, false);
            InputPort button = new InputPort(Pins.ONBOARD_SW1, false, Port.ResistorMode.Disabled);
            bool buttonState = false;

            while (true)
            {
                buttonState = button.Read();
                if (buttonState)
                    _enableSendTelemetry = !_enableSendTelemetry;

                led.Write(!buttonState);
            }
        }
Esempio n. 29
0
        public static void Main()
        {
            // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
            // !  W A R N I N G   W A R N I N G   W A R N I N G    W A R N I N G   W A R N I N G   W A R N I N G  !
            // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
            // ! The Joystick Shield analog ports are connected to 5V since it's originally designed for Arduino. !
            // ! The Netduino analog inputs work on 3.3V. Herefor a modification to the shield is required.       !
            // ! See http://netmftoolbox.codeplex.com/wikipage?title=Joystick%20Shield  for more details.         !
            // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

            // The thumb joystick is connected to analog pins 0 and 1, and digital pin 2
            // On the Joystick shield, the thumb stick is rotated by 90° so we need to invert the horizontal value
            ThumbJoystick Joystick = new ThumbJoystick(new Netduino.ADC(Pins.GPIO_PIN_A0), new Netduino.ADC(Pins.GPIO_PIN_A1), Pins.GPIO_PIN_D2, true);

            // The other buttons are connected to digital pins 3, 4, 5 and 6
            // The shield doesn't have pull-up resistors so we use the internal ones from the Netduino
            InputPort ButtonRight = new InputPort(Pins.GPIO_PIN_D3, false, Port.ResistorMode.PullUp);
            InputPort ButtonUp = new InputPort(Pins.GPIO_PIN_D4, false, Port.ResistorMode.PullUp);
            InputPort ButtonDown = new InputPort(Pins.GPIO_PIN_D5, false, Port.ResistorMode.PullUp);
            InputPort ButtonLeft = new InputPort(Pins.GPIO_PIN_D6, false, Port.ResistorMode.PullUp);

            // Infinite loop; so far Analog ports can't handle interrupts, so the Joystick driver can't as well
            while (true)
            {
                // Lets start with an empty string
                string OutputText = "";
                // Add the values of the thumb stick
                OutputText = "Horizontal: " + Joystick.HorizontalValue.ToString();
                OutputText += " Vertical: " + Joystick.VerticalValue.ToString();
                if (Joystick.PushValue) OutputText += " Thumbstick pushed";

                // Add button states to the output text (inverted with the ! because of the pull-up resistor)
                if (!ButtonDown.Read()) OutputText += " Button Down";
                if (!ButtonUp.Read()) OutputText += " Button Up";
                if (!ButtonLeft.Read()) OutputText += " Button Left";
                if (!ButtonRight.Read()) OutputText += " Button Right";

                // Displays the output text to the debug window
                Debug.Print(OutputText);

                // Wait 100ms to read the pins again
                Thread.Sleep(100);
            }
        }
Esempio n. 30
0
        public static void Main()
        {
            bool currentState = false, lastState = false;
            led = new OutputPort(Pins.ONBOARD_LED, false);
            btn = new InputPort(Pins.ONBOARD_BTN, false, Port.ResistorMode.Disabled);

            int clicks = 0;

            StartApp(false);

            while (true)
            {
                timer.Stop();

                currentState = btn.Read();

                //if button is pressed
                if (currentState && !lastState)
                {
                    clicks++;
                    timer.Reset();
                    timer.Start();
                }

                //if finished entering number
                else if (timer.ElapsedMilliseconds > 3000)
                {
                    bool isp = IsPrime(clicks);
                    Debug.Print(clicks.ToString() + " > " + isp);

                    timer.Reset();

                    if (IsPrime(clicks))
                        FlashLed(6, true);
                    else
                        FlashLed(1, false);

                    clicks = 0;
                }

                lastState = currentState;
            }
        }
        static void Main(string[] args)
        {
            OutputPort o = new OutputPort(Cpu.Pin.GPIO_Pin17, true);
            for (int i = 0; i < 5; i++)
            {
                o.Write(true);
                Console.WriteLine("Read: " + o.Read());
                Thread.Sleep(500);
                o.Write(false);
                Console.WriteLine("Read: " + o.Read());
                Thread.Sleep(500);
            }
            o.Dispose();

            InputPort input = new InputPort(Cpu.Pin.GPIO_Pin17, true, Port.ResistorMode.Disabled);
            Console.WriteLine("Read: " + input.Read());
            input.Dispose();
            Console.WriteLine("Finishing");
        }
Esempio n. 32
0
 public override bool Read()
 {
     return(_port.Read());
 }