// This is called when a board is plugged into the computer. static void TreehopperUSB_BoardAdded(TreehopperManager sender, TreehopperUSB board) { Board = board; Console.WriteLine("Board found:"); Console.WriteLine(board.Description); Board.Open(); Board.Pin8.MakeDigitalOutput(); Board.Pin8.DigitalValue = false; Board.Pin2.Pwm.IsEnabled = true; //while(true) //{ // Board.Pin2.ToggleOutput(); // Thread.Sleep(1000); //} //timer.Start(); while(true) { for (int i = 100; i > 0; i--) { Board.Pin2.Pwm.DutyCycle = i / 100.0; Thread.Sleep(10); } for (int i = 0; i < 100; i++) { Board.Pin2.Pwm.DutyCycle = i / 100.0; Thread.Sleep(10); } } }
internal Pin5(TreehopperUSB device) : base(device, 5) { ioName = "RC6"; AnalogIn = new AnalogIn(this); Pwm = new Pwm(this); }
// This is called when a board is plugged into the computer. static void TreehopperUSB_BoardAdded(TreehopperManager sender, TreehopperUSB board) { Board = board; Console.WriteLine("Board found:"); Console.WriteLine(board.Description); Board.Open(); Board.Pin8.MakeDigitalOutput(); Board.Pin8.DigitalValue = false; Board.Pin2.Pwm.IsEnabled = true; //while(true) //{ // Board.Pin2.ToggleOutput(); // Thread.Sleep(1000); //} //timer.Start(); while (true) { for (int i = 100; i > 0; i--) { Board.Pin2.Pwm.DutyCycle = i / 100.0; Thread.Sleep(10); } for (int i = 0; i < 100; i++) { Board.Pin2.Pwm.DutyCycle = i / 100.0; Thread.Sleep(10); } } }
// This is called when a board is plugged into the computer. static void TreehopperUSB_BoardAdded(TreehopperManager sender, TreehopperUSB board) { Board = board; Console.WriteLine("Board found:"); Console.WriteLine(board.Description); Board.Open(); timer.Start(); }
private void MainWindow_Closing(object sender, System.ComponentModel.CancelEventArgs e) { CloseCommandExecute(); if (SelectedBoard != null) { SelectedBoard.Dispose(); } else { TreehopperUSB.UsbExit(); } }
// When the display powers up, it is configured as follows: // // 1. Display clear // 2. Function set: // DL = 1; 8-bit interface data // N = 0; 1-line display // F = 0; 5x8 dot character font // 3. Display on/off control: // D = 0; Display off // C = 0; Cursor off // B = 0; Blinking off // 4. Entry mode set: // I/D = 1; Increment by 1 // S = 0; No shift // // Note, however, that resetting the Arduino doesn't reset the LCD, so we // can't assume that its in that state when a sketch starts (and the // LiquidCrystal ructor is called). public I2cCharLcd(TreehopperUSB board, int lcd_Addr, int lcd_cols, int lcd_rows) { _I2C = board.I2C; _Addr = lcd_Addr; _cols = lcd_cols; _rows = lcd_rows; _backlightval = LCD_NOBACKLIGHT; _I2C.Start(); _displayfunction = LCD_4BITMODE | LCD_1LINE | LCD_5x8DOTS; begin(_cols, _rows); }
void manager_BoardRemoved(object sender, TreehopperUSB board) { Board = null; if (serialLabel.InvokeRequired) { if (IsHandleCreated) { serialLabel.Invoke((MethodInvoker) delegate { serialLabel.Text = "No boards connected"; }); } } else { serialLabel.Text = "No boards connected"; } }
void manager_BoardAdded(object sender, TreehopperUSB board) { Board = board; if (serialLabel.InvokeRequired) { if (IsHandleCreated) { serialLabel.Invoke((MethodInvoker) delegate { serialLabel.Text = board.Description; }); } } else { serialLabel.Text = board.Description; } }
static void Main(string[] args) { TreehopperUSB Board = TreehopperUSB.First(); // Get a reference to the first TreehopperUSB board connected if (Board != null) // Our reference is null if we couldn't find a board { Console.WriteLine("Found board: " + Board); Board.Open(); // You must explicitly open a board before communicating with it while (Board.IsConnected) // repeat this block of code until we unplug the board { Board.Pin1.ToggleOutput(); // toggle pin 1's output Thread.Sleep(1000); // Wait 1 second } } else // If our reference was null, there wasn't a board attached { Console.WriteLine("No board was found when application was started"); } }
static void manager_BoardAdded(TreehopperManager sender, TreehopperUSB board) { Console.WriteLine("Board found."); board.Open(); /// One of the most powerful features of Treehopper's API is that input pins -- analog or digital -- have event-driven /// interfaces that allow them to update your application without requiring polling. This particular event only fires /// when the 10-bit ADC's value differs from the previous value. //board.Pin7.AnalogIn.VoltageChanged += AnalogIn_Changed; //board.Pin7.AnalogIn.IsEnabled = true; Ltc2305 ltc = new Treehopper.Libraries.Ltc2305(0x8, board.I2C); Ltc2305 ltc2 = new Treehopper.Libraries.Ltc2305(0x19, board.I2C); while(true) { // byte[] retVal = board.I2C.SendReceive(0x80, new byte[] { }, 1); //Debug.WriteLine("Device 1, channel 0: " + ltc.Read(Ltc2305Channels.Channel0)); //Debug.WriteLine("Device 1, channel 1: " + ltc.Read(Ltc2305Channels.Channel1)); Debug.WriteLine("Device 2, channel 0: " + ltc2.Read(Ltc2305Channels.Channel0)); Debug.WriteLine("Device 2, channel 1: " + ltc2.Read(Ltc2305Channels.Channel1)); Thread.Sleep(100); } }
static void manager_BoardAdded(TreehopperManager sender, TreehopperUSB board) { Console.WriteLine("Board found."); board.Open(); /// One of the most powerful features of Treehopper's API is that input pins -- analog or digital -- have event-driven /// interfaces that allow them to update your application without requiring polling. This particular event only fires /// when the 10-bit ADC's value differs from the previous value. //board.Pin7.AnalogIn.VoltageChanged += AnalogIn_Changed; //board.Pin7.AnalogIn.IsEnabled = true; Ltc2305 ltc = new Treehopper.Libraries.Ltc2305(0x8, board.I2C); Ltc2305 ltc2 = new Treehopper.Libraries.Ltc2305(0x19, board.I2C); while (true) { // byte[] retVal = board.I2C.SendReceive(0x80, new byte[] { }, 1); //Debug.WriteLine("Device 1, channel 0: " + ltc.Read(Ltc2305Channels.Channel0)); //Debug.WriteLine("Device 1, channel 1: " + ltc.Read(Ltc2305Channels.Channel1)); Debug.WriteLine("Device 2, channel 0: " + ltc2.Read(Ltc2305Channels.Channel0)); Debug.WriteLine("Device 2, channel 1: " + ltc2.Read(Ltc2305Channels.Channel1)); Thread.Sleep(100); } }
static void TreehopperUSB_BoardRemoved(TreehopperManager sender, TreehopperUSB board) { Board.Close(); timer.Stop(); }
internal Pin8(TreehopperUSB device) : base(device, 8) { ioName = "RB7"; }
void manager_BoardAdded(object sender, TreehopperUSB board) { Board = board; if(serialLabel.InvokeRequired) { if(IsHandleCreated) serialLabel.Invoke((MethodInvoker)delegate{ serialLabel.Text = board.Description; }); } else { serialLabel.Text = board.Description; } }
internal Pin4(TreehopperUSB device) : base(device, 4) { ioName = "RC3"; AnalogIn = new AnalogIn(this); }
internal Pin2(TreehopperUSB device) : base(device, 2) { ioName = "RC5"; Pwm = new Pwm(this); }
internal Pin13(TreehopperUSB device) : base(device, 13) { ioName = "RC0"; AnalogIn = new AnalogIn(this); }
internal Pin11(TreehopperUSB device) : base(device, 11) { ioName = "RB6"; }
internal Pin(TreehopperUSB board, byte pinNumber) { this.board = board; this.PinNumber = pinNumber; interruptMode = PinInterruptMode.NoInterrupt; SoftPwm = new SoftPwm(Board, this); }
void manager_BoardAdded(object sender, TreehopperUSB board) { myBoard = board; myBoard.Open(); colorSensor = new ColorSensor_ADJDS311(board.I2C, board.Pin1); }
internal SoftPwm(TreehopperUSB board, Pin pin) { this.Board = board; this.Pin = pin; }
internal Pin3(TreehopperUSB device) : base(device, 3) { ioName = "RC4"; }
internal Pin1(TreehopperUSB device) : base(device, 1) { ioName = "RA4"; AnalogIn = new AnalogIn(this); }
internal Pin9(TreehopperUSB device) : base(device, 9) { ioName = "RB5"; AnalogIn = new AnalogIn(this); }
internal SoftPwmManager(TreehopperUSB board) { this.board = board; pins = new Dictionary<int, SoftPwmPinConfig>(); }
internal Pin12(TreehopperUSB device) : base(device, 12) { ioName = "RC1"; AnalogIn = new AnalogIn(this); }
internal AnalogOut(TreehopperUSB board) { Board = board; }
internal Pin14(TreehopperUSB device) : base(device, 14) { ioName = "RA5"; }
internal Spi(TreehopperUSB device) { this.device = device; }
void manager_BoardRemoved(object sender, TreehopperUSB board) { Board = null; if (serialLabel.InvokeRequired) { if (IsHandleCreated) serialLabel.Invoke((MethodInvoker)delegate { serialLabel.Text = "No boards connected"; }); } else { serialLabel.Text = "No boards connected"; } }
internal Pin6(TreehopperUSB device) : base(device, 6) { ioName = "RC7"; AnalogIn = new AnalogIn(this); }
internal Pin7(TreehopperUSB device) : base(device, 7) { ioName = "RC2"; AnalogIn = new AnalogIn(this); }
// When the display powers up, it is configured as follows: // // 1. Display clear // 2. Function set: // DL = 1; 8-bit interface data // N = 0; 1-line display // F = 0; 5x8 dot character font // 3. Display on/off control: // D = 0; Display off // C = 0; Cursor off // B = 0; Blinking off // 4. Entry mode set: // I/D = 1; Increment by 1 // S = 0; No shift // // Note, however, that resetting the Arduino doesn't reset the LCD, so we // can't assume that its in that state when a sketch starts (and the // LiquidCrystal ructor is called). public I2cCharLcd(TreehopperUSB board, int lcd_Addr,int lcd_cols,int lcd_rows) { _I2C = board.I2C; _Addr = lcd_Addr; _cols = lcd_cols; _rows = lcd_rows; _backlightval = LCD_NOBACKLIGHT; _I2C.Start(); _displayfunction = LCD_4BITMODE | LCD_1LINE | LCD_5x8DOTS; begin(_cols, _rows); }
internal Pin10(TreehopperUSB device) : base(device, 10) { ioName = "RB4"; AnalogIn = new AnalogIn(this); }
private void SetupApp(TreehopperUSB treehopperBoard) { board = treehopperBoard; display = new SevenSegSpi(board.SPI, board.Pin1); IsConnected = true; }