/// <summary> /// Tick every 100 milliseconds to retrieve the button's state /// but blink only every 1/2 second. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void OnTick(object sender, object e) { double x, y, z; hat.GetAcceleration(out x, out y, out z); LightTextBox.Text = hat.GetLightLevel().ToString("P2"); TempTextBox.Text = hat.GetTemperature().ToString("N2"); AccelTextBox.Text = $"({x:N2}, {y:N2}, {z:N2})"; Button18TextBox.Text = hat.IsDIO18Pressed().ToString(); Button22TextBox.Text = hat.IsDIO22Pressed().ToString(); if ((i++ % 5) == 0) { LedsTextBox.Text = next.ToString(); hat.DIO24On = next; hat.D2.Color = next ? FEZHAT.Color.White : FEZHAT.Color.Black; hat.D3.Color = next ? FEZHAT.Color.White : FEZHAT.Color.Black; next = !next; } }
/// <summary> /// FEZからデータを取得して退避する。 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void MeasureTimer_Tick(object sender, object e) { double x, y, z; _fezhat.GetAcceleration(out x, out y, out z); double temp = _fezhat.GetTemperature(); double brightness = _fezhat.GetLightLevel(); var timestamp = DateTime.Now; lock (this) { lastSensorReading.Add(new SensorReadingBuffer() { AccelX = x, AccelY = y, AccelZ = x, Temperature = temp, Brightness = brightness, Timestamp = timestamp }); } Debug.WriteLine("[" + timestamp.ToString("yyyyMMdd-hhmmss.fff") + "]T=" + temp + ",B=" + brightness + ",AccelX=" + x + ",AccelY=" + y + ",AccelZ=" + z); }
private async void _timer_Tick(object sender, object e) { if (_hat == null) { return; } //update UWP app UI double temp, light, x, y, z; temp = _hat.GetTemperature(); light = _hat.GetLightLevel(); _hat.GetAcceleration(out x, out y, out z); Temp.Text = $"{temp:N2} °C"; Light.Text = $"{light:P2}"; Accel.Text = $"x={x:N2} y={y:N2} z={z:N2}"; //create message var message = new { deviceID = "Batman", temperatureToSend = temp, lightToSend = light, xToSend = x, ytoSend = y, zToSend = z }; var messageString = JsonConvert.SerializeObject(message); var messageToSend = new Message(Encoding.UTF8.GetBytes(messageString)); //send message to IoTHub await _deviceClient.SendEventAsync(messageToSend); }