public static void Main() { OutputPort led = new OutputPort(Pins.ONBOARD_LED, false); led.Write(true); VoltageDivider voltageReader = new VoltageDivider(Pins.GPIO_PIN_A1, 470000, 4700); Acs712 currentReader = new Acs712(Pins.GPIO_PIN_A2, Acs712.Range.ThirtyAmps); EmonCmsProxy.Start(); MpptOptimizer.Start(); led.Write(false); led.Dispose(); GC.WaitForPendingFinalizers(); //Random r = new Random((int) DateTime.Now.Ticks); while (true) { double current = //r.NextDouble() / double.MaxValue * 10; currentReader.Read(); double voltage = //r.NextDouble() / double.MaxValue * 3; voltageReader.Read(); EmonCmsProxy.Push(current, voltage); MpptOptimizer.Push(current, voltage); Thread.Sleep(50); } }
public static void PowerUpDisplay() { // Ensure that the GPIO pin in low to prevent the display module to start in bootloader mode var goBusGPIO = new OutputPort(Pins.GPIO_PIN_D8, false); // Power up the display module PowerTransistor.Write(false); // Always wait 250ms after power-up to ensure that the display module is fully initialized before sending commands Thread.Sleep(250); goBusGPIO.Dispose(); }
private void Dispose(bool fDisposing) { if (!m_disposed) { try { HardwareProvider hwProvider = HardwareProvider.HwProvider; if (hwProvider != null) { Cpu.Pin msk; Cpu.Pin miso; Cpu.Pin mosi; hwProvider.GetSpiPins(m_config.SPI_mod, out msk, out miso, out mosi); if (msk != Cpu.Pin.GPIO_NONE) { Port.ReservePin(msk, false); } if (miso != Cpu.Pin.GPIO_NONE) { Port.ReservePin(miso, false); } if (mosi != Cpu.Pin.GPIO_NONE) { Port.ReservePin(mosi, false); } } if (m_config.ChipSelect_Port != Cpu.Pin.GPIO_NONE) { m_cs.Dispose(); } } finally { m_disposed = true; } } }
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"); }
static void Main(string[] args) { SPI SPIport = new Microsoft.SPOT.Hardware.SPI(new Microsoft.SPOT.Hardware.SPI.Configuration(Cpu.Pin.GPIO_NONE, false, 0, 0, false, true, 2000, SPI.SPI_module.SPI1)); OutputPort nCE = new OutputPort(Cpu.Pin.GPIO_Pin2, true); InterruptPort nINT = new InterruptPort(Cpu.Pin.GPIO_Pin4, false, Port.ResistorMode.PullUp, Port.InterruptMode.InterruptEdgeLow); NRF24L01Plus n = new NRF24L01Plus(); n.Initialize(SPIport, nCE, nINT); byte[] address = n.GetAddress(AddressSlot.Zero, 5); Console.WriteLine("First Address: " + ByteArrayToHexString(address)); byte[] b = new byte[] { 0x04, 0x09, 0x02, 0x03, 0x04 }; n.SetAddress(AddressSlot.Zero, b, false); address = n.GetAddress(AddressSlot.Zero, 5); Console.WriteLine("Second Address: " + ByteArrayToHexString(address)); nCE.Dispose(); nINT.Dispose(); }
//public static void Main() //{ // using (var a1 = new AnalogInput(Cpu.AnalogChannel.ANALOG_1)) // { // var last = 0.0d; // while (Debugger.IsAttached) // { // var reading = a1.Read(); // if (reading != last) // { // Debug.Print(reading.ToString()); // last = reading; // } // } // } //} public static void Main() { var wiiChuck = new WiiChuck(true); var debugMode = Debugger.IsAttached; _redLed = new OutputPort(Pins.GPIO_PIN_D13, false); _greenLed = new OutputPort(Pins.GPIO_PIN_A0, false); _pot = new AnalogInput(Cpu.AnalogChannel.ANALOG_1); //_speaker = new PWM(Pins.GPIO_PIN_D9); //_speakerThread = new Thread(PlaySound); //_speakerThread.Start(); //_servo1 = new ServoController(Mshield.Servo1, 600, 2400, startDegree: 90); _robot = new TankRobot(); while (!debugMode || Debugger.IsAttached) { // try to read the data from nunchucku if (wiiChuck.GetData()) { CheckButtons(wiiChuck.CButtonDown, wiiChuck.ZButtonDown); if (Recording) { _iteration++; SetMotorSpeed(_robot, wiiChuck); } else if (PlayingBack) { if (_currentPlaybackIndex >= _record.Count) { PlayingBack = false; _currentPlaybackIndex = 0; } else { _iteration++; var record = (DataPoint) _record[_currentPlaybackIndex]; if (record.Iterations == _iteration) { _currentPlaybackIndex++; _robot.Move(record.LeftSpeed, record.RightSpeed); } } } else { SetMotorSpeed(_robot, wiiChuck); } //var degrees = ((int) (90+(-90*wiiChuck.AccelerationXGs))/2)*2; //if (degrees < 0) // degrees = 0; //else if (degrees > 180) // degrees = 180; //_servo1.Rotate(degrees); //Debug.Print("AccelX = " + wiiChuck.AccelerationXGs + " AccelY=" + wiiChuck.AccelerationYGs); } } wiiChuck.Dispose(); _robot.Dispose(); //_speaker.Dispose(); //_speaker = null; //_servo1.Dispose(); _redLed.Dispose(); _greenLed.Dispose(); _pot.Dispose(); }
public override void Dispose() { _port.Dispose(); }
/// <summary> /// Actually starts the demo /// </summary> /// <param name="Server">Reference to the Telnet Server</param> public static void Start(TelnetServer Server) { // Configures the onboard button. If this fails, it's probably already in use by another app. InputPort Button = null; try { Button = new InputPort(ONBOARD_SW1, false, Port.ResistorMode.Disabled); } catch (Exception e) { Server.Color(TelnetServer.Colors.LightRed); Server.Print("Exception " + e.Message + " given. Were the onboard Button already configured?"); Server.Color(TelnetServer.Colors.White); return; } // Configures the onboard LED. If this fails, it's probably already in use by another app. OutputPort Led = null; try { Led = new OutputPort(ONBOARD_LED, false); } catch (Exception e) { Button.Dispose(); // The button is already defined Server.Color(TelnetServer.Colors.LightRed); Server.Print("Exception " + e.Message + " given. Were the onboard LED already configured?"); Server.Color(TelnetServer.Colors.White); return; } // Disables echoing of keypresses Server.EchoEnabled = false; // Clears the screen Server.ClearScreen(); // Draws a Netduino Plus in ANSI/ASCII art Server.Print("\xda\xc4\xc4\xc4\xc4\xc4\xc4\xc4\xc4\xc4\xc4\xc4\xc4\xc4\xc4\xc4\xc4\xc4\xc4\xc4\xc4\xc4\xc4\xc4\xc4\xc4\xc4\xc4\xc4\xc4\xc4\xbf"); Server.Print("\xb3 \xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe \xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xb3"); Server.Print("\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb \xdc \xb3"); Server.Print("\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb NETDUINO \xb3"); Server.Print("\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb\xdb PLUS \xb3"); Server.Print("\xb3 ..\xb3"); Server.Print("\xdb\xdb \xdb\xdb ::\xb3"); Server.Print("\xb3 \xdb\xdb\xdb\xdb\xdb\xdb \xb3"); Server.Print("\xdb\xdb\xdb\xdb\xdb \xdb\xdb\xdb\xdb\xdb\xdb \xb3"); Server.Print("\xdb\xdb\xdb\xdb\xdb \xdb\xdb\xdb\xdb\xdb\xdb \xfe\xfe\xfe\xfe\xfe\xfe \xfe\xfe\xfe\xfe\xfe\xfe\xb3"); Server.Print("\xc0\xc4\xc4\xc4\xc4\xc4\xc4\xc4\xdb\xdb\xdb\xdb\xdb\xdb\xc4\xc4\xc4\xc4\xc4\xc4\xc4\xc4\xc4\xc4\xc4\xc4\xc4\xc4\xc4\xc4\xc4\xd9"); Server.Print("", true); Server.Print("Push the Netduino Plus onboard button, or press a key to close this app"); // We only update the screen if the LastState is different from the current state bool LastState = false; while (Server.IsConnected && Server.Input(1, false) == "") { // We need to update if (Button.Read() == LastState) { // Lets record the last state LastState = !Button.Read(); Led.Write(LastState); // Draws the button if (LastState) Server.Color(TelnetServer.Colors.HighIntensityWhite); else Server.Color(TelnetServer.Colors.Gray); Server.Locate(7, 26, true); Server.Print("\xdb\xdb", true, true); // Draws the LED if (LastState) Server.Color(TelnetServer.Colors.LightBlue); else Server.Color(TelnetServer.Colors.Gray); Server.Locate(3, 29, true); Server.Print("\xdc", true); // Brings back the cursor to the last line Server.Locate(14, 1); } } // Releases the pins Button.Dispose(); Led.Dispose(); // Enables echo again and clears the screen if (Server.IsConnected) { Server.EchoEnabled = true; Server.ClearScreen(); } }
private bool m_disposed; // Whether or not the driver is disposed //--// /// <summary> /// Creates a new instance of PromiSDBTDriver by initializing /// the Serial connection and checking if the SD is present. /// </summary> /// <param name="comNum"> /// Number of the COM port to use /// </param> /// <param name="baudRate"> /// Baud rate of the COM port to use /// </param> /// <param name="powerPin"> /// GPIO to turn the bluetooth power off /// </param> /// <remarks> /// GPIO pin for the N6D should be GPIO22_VTU_TIO3A, if there is no GPIO for power control /// then use GPIO_NONE. /// </remarks> public PromiSDBTDriver(string com, BaudRate baud, Cpu.Pin powerPin) { bool success = false; m_com = com; m_baud = baud; try { if (!CreateSerialConnection(m_com, m_baud)) throw new SystemException("Error booting SD"); m_power = (powerPin == Cpu.Pin.GPIO_NONE) ? null : new OutputPort(powerPin, false); m_powerState = PowerState.Off; m_state = BTDeviceState.OFF; PowerState state = PowerState.On; if (!SetPowerState(ref state) || !CheckDevicePresent()) throw new SystemException("Error booting SD"); success = true; UpdateDeviceStatus(); m_disposed = false; } finally { if (!success) { if (null != m_power) { m_power.Dispose(); m_power = null; } m_disposed = true; } } }