// This method is run when the mainboard is powered up or reset. void ProgramStarted() { _bluetooth = new Bluetooth(4); _bluetooth.DebugPrintEnabled = true; _client = _bluetooth.ClientMode; _bluetooth.SetDeviceName("Gadgeteer"); _bluetooth.SetPinCode("1234"); _bluetooth.DataReceived += bluetooth_DataReceived; button.ButtonPressed += (sender, state) => _client.EnterPairingMode(); var monitor = new GT.Timer(500); monitor.Tick += timer => { if (_bluetooth.IsConnected) { //_client.Send("xxx"); } }; monitor.Start(); // Use Debug.Print to show messages in Visual Studio's "Output" window during debugging. Debug.Print("Program Started"); var sensePuss = new GT.Timer(1000); sensePuss.Tick += timer => { relays.Relay3 = moistureSensor.GetMoistureReading() > 500; Debug.Print(moistureSensor.GetMoistureReading().ToString()); }; sensePuss.Start(); }
void ProgramStarted() { client = bluetooth.ClientMode; //server = bluetooth.HostMode; Thread.Sleep(2000); // need a handler for state changes and data recieved. bluetooth.BluetoothStateChanged += new Bluetooth.BluetoothStateChangedHandler(bluetooth_BluetoothStateChanged); bluetooth.DataReceived += new Bluetooth.DataReceivedHandler(bluetooth_DataReceived); bluetooth.PinRequested += new Bluetooth.PinRequestedHandler(bluetooth_PinRequest); // set up bluetooth module connection parameters bluetooth.SetDeviceName("EmotionMingle"); // change this to whatever name you want bluetooth.SetPinCode("5678"); //likewise, set whatever PIN you want. Thread.Sleep(2000); // put the device in pairing mode as part of a normal execution client.EnterPairingMode(); Thread.Sleep(2000); // HSU Communication layer // MOSI/SDA (TX) --> DIGITAL 0 (RX COM1) // SCL/RX (RX) --> DIGITAL 1 (TX COM1) //IPN532CommunicationLayer commLayer = new PN532CommunicationHSU(SerialPorts.COM1); // SPI Communication layer // SCK --> DIGITAL 13 - Socket S Pin9 // MISO --> DIGITAL 12 - Socket S Pin8 // MOSI/SDA --> DIGITAL 11 - Socket S Pin7 // SCL/RX -> DIGITAL 10 - Socket S Pin6 // IRQ --> DIGITAL 8 - Socket S Pin5 //SPI.SPI_module spi = GT.Socket.GetSocket(9, true, null, null).SPIModule; //Cpu.Pin pin6 = GT.Socket.GetSocket(9, true, null, null).CpuPins[6]; //Cpu.Pin pin5 = GT.Socket.GetSocket(9, true, null, null).CpuPins[5]; //IPN532CommunicationLayer commLayer = new PN532CommunicationSPI(spi, pin6, pin5); // I2C Communication layer // MOSI/SDA --> ANALOG 4 (SDA) // SCL/RS --> ANALOG 5 (SCL) // IRQ --> DIGITAL 8 //IPN532CommunicationLayer commLayer = new PN532CommunicationI2C(Cpu.Pin.GPIO_Pin5); //nfc = new NfcPN532Reader(commLayer); //nfc.TagDetected += nfc_TagDetected; //nfc.TagLost += nfc_TagLost; //nfc.Open(NfcTagType.MifareUltralight); GT.Socket socket = GT.Socket.GetSocket(4, true, null, null); Debug.Print("SerialPortName: " + socket.SerialPortName); UART = new SerialPort(socket.SerialPortName, 4800); UART.Open(); rnd = new Random(); Debug.Print("Program Started"); }