/// <summary> /// IHMSSI constructor /// </summary> /// <param name="leds">if changed PCF8574 SLA must be in [0x20, 0x27], PCF8574A in [0x38, 0x3F] and Frequency in [100kHz,400kHz]</param> /// <param name="BPs">if changed PCF8574 SLA must be in [0x20, 0x27], PCF8574A in [0x38, 0x3F] and Frequency in [100kHz,400kHz]</param> /// <param name="lcd">lcd is MIDAS(0x3A) or BATRON(0x3B), Frequency in [100kHz,400kHz]</param> /// <remarks> /// All Led => Off; Lcd => Init /// </remarks> public IHMSSI(PCF8574 leds, PCF8574 BPs, I2CLcd lcd) { this.leds = leds; this.BPs = BPs; this.lcd = lcd; d0 = new Led(false, 0, leds); d1 = new Led(false, 1, leds); d2 = new Led(false, 2, leds); d3 = new Led(false, 3, leds); d4 = new Led(false, 4, leds); d5 = new Led(false, 5, leds); d6 = new Led(false, 6, leds); d7 = new Led(false, 7, leds); bpPlus = new BP(BPs, 1); bpFleHaut = new BP(BPs, 2); bpFleBas = new BP(BPs, 4); bpMoins = new BP(BPs, 8); bpSet = new BP(BPs, 16); bpOk = new BP(BPs, 32); bpEnter = new BP(BPs, 64); bpEchap = new BP(BPs, 128); leds.Write(0xff); // Leds Off lcd.Init(); lcd.ClearScreen(); }
public static void Main() { byte Nb = 4; // Channels under test in single mode MCP342x can = new MCP342x(); PCF8574 leds = new PCF8574(); #if LCD ELCD162 lcd = new ELCD162("COM1"); lcd.Init(); lcd.ClearScreen(); lcd.CursorOff(); #endif // One Shot Conversion #if LCD lcd.PutString("One Shot Conv."); Thread.Sleep(2000); #endif can.Mode = MCP342x.ConversionMode.OneShot; can.Resolution = MCP342x.SampleRate.TwelveBits; can.Gain = MCP342x.PGA_Gain.x1; double resolution = Resolution(can.Resolution); double gain = System.Math.Pow(2, (byte)can.Gain); for (int i = 0; i < Nb; i++) { try { Debug.Print("Single on channel " + (can.CHannel + 1) + " => Tension= " + can.ReadVolts().ToString("F2") + " " + "Resol: " + resolution + "-bit " + "Gain: " + gain); can.CHannel = (MCP342x.Channel)(i + 1); } catch (System.IO.IOException ex) { #if LCD lcd.ClearScreen(); lcd.SetCursor(0, 0); lcd.PutString(ex.Message); #else Debug.Print(ex.Message); #endif } finally { Thread.Sleep(500); } } // Continuous Conversion mode #if LCD lcd.ClearScreen(); lcd.PutString("Continuous Conv."); Thread.Sleep(2000); #endif can.Mode = MCP342x.ConversionMode.Continuous; byte j = 1; bool commut = true; while (true) { if (commut) { try { leds.Write(0xF0); } catch (System.IO.IOException ex) { #if LCD lcd.ClearScreen(); lcd.SetCursor(0, 1); lcd.PutString(ex.Message); Thread.Sleep(1000); #else Debug.Print(ex.Message); #endif } finally { commut = false; can.CHannel = (MCP342x.Channel)(j - 1); j = 2; } } else { try { leds.Write(0x0F); } catch (System.IO.IOException ex) { #if LCD lcd.ClearScreen(); lcd.SetCursor(0, 1); lcd.PutString(ex.Message); Thread.Sleep(1000); #else Debug.Print(ex.Message); #endif } finally { commut = true; can.CHannel = (MCP342x.Channel)(j - 1); j = 1; } } try { #if LCD lcd.ClearScreen(); lcd.SetCursor(0, 0); lcd.PutString("Ch" + (can.CHannel + 1) + " U=" + can.ReadVolts().ToString("F2") + "V"); #else Debug.Print("Continuous on channel " + (can.CHannel + 1) + " =>Tension= " + can.ReadVolts().ToString("F2") + " " + "Resol: " + resolution + "-bit " + "Gain: " + gain); #endif } catch (System.IO.IOException ex) { #if LCD lcd.ClearScreen(); lcd.SetCursor(0, 0); lcd.PutString(ex.Message); #else Debug.Print(ex.Message); #endif } finally { Thread.Sleep(1000); } } }
public static void Main() { MLX90614 tempIR = new MLX90614(); #if Debug while (true) { try { Debug.Print("Température Air = " + tempIR.Read_TA_AsCelcius().ToString("F1") + " °C"); Debug.Print("Température IR = " + tempIR.Read_Tobj_AsCelcius().ToString("F1") + " °C"); Debug.Print("---------------------"); } catch (IOException ioEx) { Debug.Print(ioEx.Message); } finally { Thread.Sleep(500); } } #else // Test with PCF8574 and ELCD162 PCF8574 Leds = new PCF8574(0x38, 100); ELCD162 lcd = new ELCD162("COM1"); //issue on COM2 lcd.Init(); lcd.ClearScreen(); while (true) { try { Leds.Write(0xf0); Thread.Sleep(200); Leds.Write(0x0f); } catch (System.Exception ioEx) { lcd.ClearScreen(); lcd.PutString(ioEx.Message); Thread.Sleep(1000); } try { double TA = tempIR.Read_TA_AsCelcius(); double TO = tempIR.Read_Tobj_AsCelcius(); lcd.ClearScreen(); lcd.PutString("TA=" + TA.ToString("F1") + "C"); lcd.SetCursor(0, 1); lcd.PutString("TO=" + TO.ToString("F1") + "C"); } catch (IOException ioEx) { lcd.ClearScreen(); lcd.PutString(ioEx.Message); } finally { Thread.Sleep(200); } } #endif }
public static void Main() { byte Nb = 4; // Channels on MCP342x MCP342x can = new MCP342x(); PCF8574 leds = new PCF8574(); can.Gain = MCP342x.PGA_Gain.x8; can.Mode = MCP342x.ConversionMode.OneShot; can.Resolution = MCP342x.SampleRate.FourteenBits; double resolution = Resolution(can.Resolution); double gain = System.Math.Pow(2, (byte)can.Gain); // First message on graphic display BrainPad.Display.DrawLargeText(10, 10, "BrainPad", BrainPad.Color.Yellow); BrainPad.Display.DrawLargeText(25, 30, "MCP342x", BrainPad.Color.Yellow); // 1. One Shot Conversion BrainPad.Display.DrawText(5, 50, "One Shot Conversion", BrainPad.Color.Yellow); BrainPad.Display.DrawText(5, 60, "n:" + resolution + "-bit" + " Gain:" + gain + " sample:5s", BrainPad.Color.Yellow); for (int i = 0; i < Nb; i++) { try { var voltage = can.ReadVolts(); var temperature = voltage / 0.01; BrainPad.Display.DrawText(5, 80, "On channel " + (can.CHannel + 1), BrainPad.Color.Yellow); BrainPad.Display.DrawText(10, 90, "=> Voltage = " + voltage.ToString("F2") + "V", BrainPad.Color.Yellow); BrainPad.Display.DrawText(10, 100, "=> Temperature = " + temperature.ToString("F1") + "degC", BrainPad.Color.Yellow); can.CHannel = (MCP342x.Channel)(i + 1); } catch (System.IO.IOException ex) { displayErrorMessage(5, 120, ex); } finally { Thread.Sleep(5000); } } // 2. Clear screen BrainPad.Display.Clear(); BrainPad.Display.DrawLargeText(10, 10, "BrainPad", BrainPad.Color.Yellow); BrainPad.Display.DrawLargeText(25, 30, "MCP342x", BrainPad.Color.Yellow); // 3. Continuous Conversion mode BrainPad.Display.DrawText(5, 50, "Continuous Conversion", BrainPad.Color.Yellow); BrainPad.Display.DrawText(5, 60, "n:" + resolution + "-bit" + " Gain:" + gain + " sample:2s", BrainPad.Color.Yellow); can.Mode = MCP342x.ConversionMode.Continuous; uint state = 1; while (true) { switch (state) { case 1: try { leds.Write(0xFE); } catch (System.IO.IOException ex) { displayErrorMessage(5, 120, ex); } finally { can.CHannel = MCP342x.Channel.Ch1; state = 2; } break; case 2: try { leds.Write(0xFD); } catch (System.IO.IOException ex) { displayErrorMessage(5, 120, ex); } finally { can.CHannel = MCP342x.Channel.Ch2; state = 3; } break; case 3: try { leds.Write(0xFB); } catch (System.IO.IOException ex) { displayErrorMessage(5, 120, ex); } finally { can.CHannel = MCP342x.Channel.Ch3; state = 4; } break; case 4: try { leds.Write(0xF7); } catch (System.IO.IOException ex) { displayErrorMessage(5, 120, ex); } finally { can.CHannel = MCP342x.Channel.Ch4; state = 1; } break; } try { var voltage = can.ReadVolts(); var temperature = voltage / 0.01; BrainPad.Display.DrawText(5, 80, "On channel " + (can.CHannel + 1), BrainPad.Color.Yellow); BrainPad.Display.DrawText(10, 90, "=> Voltage = " + voltage.ToString("F2") + "V", BrainPad.Color.Yellow); BrainPad.Display.DrawText(10, 100, "=> Temperature = " + temperature.ToString("F1") + "degC", BrainPad.Color.Yellow); } catch (System.IO.IOException ex) { displayErrorMessage(5, 120, ex); } finally { Thread.Sleep(2000); } } }
public BP(PCF8574 buttons, byte position) { this.buttons = buttons; this.position = position; }
/// <summary> /// Constructor /// </summary> /// <param name="state">true or false</param> /// <param name="position">position 0 to 7</param> /// <param name="leds">I2C port I/O</param> public Led(bool state, byte position, PCF8574 leds) { this.state = state; this.position = position; this.leds = leds; }
/// <summary> ///IHMSSI constructor with LCD = MIDAS(0x3A); PCF8574(A) SLA are 0x3f for BP and 0x38 for Led; I2C Bus Frequency = 100kHz /// </summary> /// <param name="leds">if changed PCF8574 SLA must be in [0x20, 0x27], PCF8574A in [0x38, 0x3F] and Frequency in [100kHz,400kHz]</param> /// <param name="lcd">lcd is MIDAS(0x3A) or BATRON(0x3B)</param> /// <remarks> /// All Led => Off; Lcd => Init /// </remarks> public IHMSSI(PCF8574 leds, I2CLcd lcd) : this(leds, new PCF8574(0x3f, 100), lcd) { }