My question, how do i write code to shield base digital i/o pin 4?
Output leds = new output(pins_gpio_pin_5,false)<== I'm not sure if this write to shield base
Shield Base connected to sck5 of NGo..
Thank.

  | ||||||||||||||
How to write Shield Base Digital I/O
Started by supra, Oct 02 2012 03:05 PM
14 replies to this topic
#1Posted 02 October 2012 - 03:05 PM
Since I got Shield base 1 mnth ago, but haven't play around yet. On breadboard, I have common cathode connected to Power GND and 330 ohms with anode's led connected to digital i/o pin 4 of shield base.
My question, how do i write code to shield base digital i/o pin 4? Output leds = new output(pins_gpio_pin_5,false)<== I'm not sure if this write to shield base Shield Base connected to sck5 of NGo.. Thank. #2Posted 02 October 2012 - 03:14 PM
Hi supra,
To blink an LED attached to pin D4 on the Shield Base: // NOTE: be sure to add Microsoft.SPOT.Hardware.dll and NetduinoGo.ShieldBase.dll as references to your project. // use the Shield Base on socket 5 (nothing else plugged into sockets 6-8 for the moment) NetduinoGo.ShieldBase shieldBase = new NetduinoGo.ShieldBase(GoSockets.Socket5); Microsoft.SPOT.Hardware.OutputPort ledPort = new Microsoft.SPOT.Hardware.OutputPort(shieldBase.Pins.GPIO_PIN_D4, false); while (true) { ledPort.Write(!ledPort.Read()); System.Threading.Thread.Sleep(250); }Chris #3Posted 02 October 2012 - 03:18 PM
Thank. I try today after gym. #4Posted 03 October 2012 - 02:55 PM
How do i turn led1 on and led2 off and turn led1 off and turn led2 on?
NetduinoGo.ShieldBase sb = new NetduinoGo.ShieldBase(GoSockets.Socket5); Microsoft.SPOT.Hardware.OutputPort ledPort = new Microsoft.SPOT.Hardware.OutputPort(sb.Pins.GPIO_PIN_D6, false); Microsoft.SPOT.Hardware.OutputPort ledprt5 = new Microsoft.SPOT.Hardware.OutputPort(sb.Pins.GPIO_PIN_D5, false); while (true) { // ledPort.Write(!ledPort.Read()); //ledprt5.Write(!ledprt5.Read()); ledPort.Write(ledPort.Read()); Thread.Sleep(1000); ledprt5.Write(!ledPort.Read()); Thread.Sleep(1000); ledPort.Write(!ledPort.Read()); Thread.Sleep(1000); ledprt5.Write(!ledPort.Read()); Thread.Sleep(1000); } #5Posted 03 October 2012 - 02:58 PM
Hi supra,
I think that what you're trying to do is invert the state of ledprt5. To do that, you'll need to read the value of ledprt5. Instead of this... ledprt5.Write(!ledPort.Read());Do this... ledprt5.Write(!ledprt5.Read());Chris #6Posted 03 October 2012 - 03:24 PM
Seems that he only want to toggle those two leds, so:
bool x = false; while (true) { ledPort.Write(!x); ledprt5.Write(x); x=!x; Thread.Sleep(1000); } I guess there is no need to do an read, since it is an output port? -- #7Posted 03 October 2012 - 03:48 PM
Sorry. It was my mistaken. I just copy and paste it. But i didn't realize in parameter. Finally, I got knight rider working. I been struggled for 1 hrs. Here is code: public static void Main() { // write your code here NetduinoGo.ShieldBase sb = new NetduinoGo.ShieldBase(GoSockets.Socket5); Microsoft.SPOT.Hardware.OutputPort ledPort = new Microsoft.SPOT.Hardware.OutputPort(sb.Pins.GPIO_PIN_D6, true); Microsoft.SPOT.Hardware.OutputPort ledprt5 = new Microsoft.SPOT.Hardware.OutputPort(sb.Pins.GPIO_PIN_D5, true); while (true) { ledprt5.Write(!ledprt5.Read()); Thread.Sleep(1000); ledPort.Write(!ledPort.Read()); } #8Posted 03 October 2012 - 03:56 PM
@Gutwork:
Thank you very much. I appreciated ur helping. Here is code: Sub Main() ' write your code here Dim sb As NetduinoGo.ShieldBase = New NetduinoGo.ShieldBase(GoSockets.Socket5) Dim ledport As Microsoft.SPOT.Hardware.OutputPort = New Microsoft.SPOT.Hardware.OutputPort(sb.Pins.GPIO_PIN_D4, False) While True ledport.Write(True) Thread.Sleep(1000) ledport.Write(False) Thread.Sleep(5000) End While End Sub Btw, I'm going to try knight rider. Also will be moving on to 8x8 dotmatrix(bicolor). Thank for helping supra. #9Posted 03 October 2012 - 04:10 PM
U got 6 lines and i got 3 lines. So mine is better while (true) { ledprt5.Write(!ledprt5.Read()); Thread.Sleep(1000); ledPort.Write(!ledPort.Read()); } I will try ur code today. #10Posted 03 October 2012 - 04:15 PM
short or not short, It depends on what read is doing, if it reads an internal variable it should be ok, if it goes out and smells the pin, one can wonder, since it still is an output port that you defined..
-- #11Posted 03 October 2012 - 04:15 PM
@Chris
What voltage we getting frm Shield Base? It is 3.3V or 5V? #12Posted 03 October 2012 - 04:48 PM The Shield Base outputs 3.3V digital outputs. Chris #13Posted 03 October 2012 - 05:35 PM
regarding questions like that, you have this spec page for the Go, but none for the shieldbase ?
http://www.netduino....inogo/specs.htm
-- #14Posted 03 October 2012 - 05:59 PM
Hi neslekkim,
That's a good idea. Today we have an accessories page, and details on the Wiki pages. We should create specs pages for each module. Chris #15Posted 05 October 2012 - 09:05 AM
Thank for NGO catalog. But still awaitng for gadgeteer adapter 0 user(s) are reading this topic0 members, 0 guests, 0 anonymous users | ||||||||||||||
|
||||||||||||||
This webpage is licensed under a Creative Commons Attribution-ShareAlike License. | ||||||||||||||