public async Task IMU_NeoPixel(int val) { INeoPixel neopixel = metawear.GetModule <INeoPixel>(); IStrand strand = neopixel.InitializeStrand(1, ColorOrdering.WS2811_GRB, StrandSpeed.Slow, 0, 3); strand = neopixel.LookupStrand(1); if (val == 0) { strand.Hold(); strand.SetRgb(0, 0, 0, 0); strand.SetRgb(1, 0, 0, 0); strand.SetRgb(2, 0, 0, 0); strand.Release(); } else if (val == 1) { strand.Hold(); strand.SetRgb(0, 0, 20, 0); strand.SetRgb(1, 0, 20, 0); strand.SetRgb(2, 0, 20, 0); strand.Release(); } else if (val == 2) { strand.Hold(); strand.SetRgb(0, 0, 0, 20); strand.SetRgb(1, 0, 0, 20); strand.SetRgb(2, 0, 0, 20); strand.Release(); } else if (val == 3) { strand.Hold(); strand.SetRgb(0, 0, 0, 0); strand.SetRgb(1, 0, 0, 0); strand.SetRgb(2, 0, 0, 0); strand.Release(); } else if (val == 4) { strand.Hold(); strand.SetRgb(0, 0, 0, 0); strand.SetRgb(1, 0, 0, 0); strand.SetRgb(2, 0, 0, 0); strand.Release(); } else if (val == 5) { strand.Hold(); strand.SetRgb(0, 0, 0, 0); strand.SetRgb(1, 0, 0, 0); strand.SetRgb(2, 0, 0, 0); strand.Release(); } }
///------------------------------------------ IMU Initialise FUNCTION ---------------------------------------------------------- private async Task IMU_initialize(NavigationEventArgs e) { try { // Sensor Configuration metawear = MbientLab.MetaWear.Win10.Application.GetMetaWearBoard(e.Parameter as BluetoothLEDevice); //ILed led = metawear.GetModule<ILed>(); //led.EditPattern(Color.Green, duration: 500, highTime: 250, high: 16, low: 0, count: 50); //led.Play(); // ## Reset Neopixel to Off (if on before) INeoPixel neopixel = metawear.GetModule <INeoPixel>(); IStrand strand = neopixel.InitializeStrand(1, ColorOrdering.WS2811_GRB, StrandSpeed.Slow, 0, 3); strand = neopixel.LookupStrand(1); strand.Hold(); strand.SetRgb(0, 0, 0, 0); strand.SetRgb(1, 0, 0, 0); strand.SetRgb(2, 0, 0, 0); strand.Release(); //strand.Hold(); //strand.SetRgb(0, 20, 0, 0); //strand.SetRgb(1, 0, 20, 0); //strand.SetRgb(2, 0, 0, 20); //strand.Release(); //strand.Rotate(RotationDirection.Away, 500); //await progranScheduleRead(); //IScheduledTask mwTask; //if ((mwTask = metawear.LookupScheduledTask((byte)0)) != null) //{ // // start the task // mwTask.Start(); // // stop the task // mwTask.Stop(); // // remove the task, id 0 no longer valid id // mwTask.Remove(); //} //// Run a motor for 1000ms at 50% strength //metawear.GetModule<IHaptic>().StartMotor(1000, 100f); //metawear.GetModule<IHaptic>().StartMotor(1000, 95f); //metawear.GetModule<IHaptic>().StartMotor(1000, 90f); //metawear.GetModule<IHaptic>().StartMotor(1000, 85f); //metawear.GetModule<IHaptic>().StartMotor(1000, 80f); //metawear.GetModule<IHaptic>().StartMotor(1000, 75f); //metawear.GetModule<IHaptic>().StartMotor(1000, 70f); //metawear.GetModule<IHaptic>().StartMotor(1000, 65f); //metawear.GetModule<IHaptic>().StartMotor(1000, 60f); //metawear.GetModule<IHaptic>().StartMotor(1000, 55f); //metawear.GetModule<IHaptic>().StartMotor(1000, 50f); //metawear.GetModule<IHaptic>().StartMotor(1000, 45f); //metawear.GetModule<IHaptic>().StartMotor(1000, 40f); //metawear.GetModule<IHaptic>().StartMotor(1000, 35f); //metawear.GetModule<IHaptic>().StartMotor(1000, 30f); //metawear.GetModule<IHaptic>().StartMotor(1000, 25f); //// turn off leds from index [0, 59] (60 leds) //strand.Clear(0, 59); //// free //strand.Free(); sensorfusion = metawear.GetModule <ISensorFusionBosch>(); sensorfusion.Configure(mode: Mode.Ndof, ar: AccRange._2g, gr: GyroRange._500dps); ISettings settings = metawear.GetModule <ISettings>(); settings.EditBleConnParams(maxConnInterval: 7.5f); await settings.Battery.AddRouteAsync(source => source.Stream(data => Console.WriteLine("battery = " + data.Value <BatteryState>()))); settings.Battery.Read(); IMacro macro = metawear.GetModule <IMacro>(); func_IMU_init_success = true; await sensorfusion.EulerAngles.AddRouteAsync(source => source.Stream(async data => { var value = data.Value <EulerAngles>(); imu_data = data; //set time_base to false to reset time_base if (time_base_set == false) { time_base_ms = data.Timestamp.Millisecond; time_base_sec = data.Timestamp.Second; time_base_min = data.Timestamp.Minute; time_base_hour = data.Timestamp.Hour; base_elapsed_millisec = time_base_ms + (1000 * time_base_sec) + (1000 * 60 * time_base_min) + (1000 * 60 * 60 * time_base_hour); time_base_set = true; } //Calculate elapsed time time_current_ms = data.Timestamp.Millisecond; time_current_sec = data.Timestamp.Second; time_current_min = data.Timestamp.Minute; time_current_hour = data.Timestamp.Hour; current_elapsed_millisec = time_current_ms + (1000 * time_current_sec) + (1000 * 60 * time_current_min) + (1000 * 60 * 60 * time_current_hour); trial_time_ms = current_elapsed_millisec - base_elapsed_millisec; angle_maze = value.Heading; if (data_save_en == true & trial_active == true) { saveToCSV(data, false); //Start this } if (func_IMU_euler_init_already_trig == false) { func_IMU_euler_init_success = true; func_IMU_euler_init_already_trig = true; } })); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine("IMU init error" + ex.Message); } }