Beispiel #1
0
        // 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);
                }
            }
        }
Beispiel #2
0
 internal Pin5(TreehopperUSB device)
     : base(device, 5)
 {
     ioName   = "RC6";
     AnalogIn = new AnalogIn(this);
     Pwm      = new Pwm(this);
 }
Beispiel #3
0
        // 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);
                }
            }
        }
Beispiel #4
0
 // 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();
 }
Beispiel #5
0
 // 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();
 }
Beispiel #6
0
 private void MainWindow_Closing(object sender, System.ComponentModel.CancelEventArgs e)
 {
     CloseCommandExecute();
     if (SelectedBoard != null)
     {
         SelectedBoard.Dispose();
     }
     else
     {
         TreehopperUSB.UsbExit();
     }
 }
Beispiel #7
0
        // 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);
        }
Beispiel #8
0
 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";
     }
 }
Beispiel #9
0
 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;
     }
 }
Beispiel #10
0
        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");
            }
        }
Beispiel #11
0
        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);
            }
        }
Beispiel #12
0
        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);
            }
        }
Beispiel #13
0
 static void TreehopperUSB_BoardRemoved(TreehopperManager sender, TreehopperUSB board)
 {
     Board.Close();
     timer.Stop();
 }
Beispiel #14
0
 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;
     }
 }
Beispiel #16
0
 internal Pin4(TreehopperUSB device)
     : base(device, 4)
 {
     ioName   = "RC3";
     AnalogIn = new AnalogIn(this);
 }
Beispiel #17
0
 internal Pin2(TreehopperUSB device)
     : base(device, 2)
 {
     ioName = "RC5";
     Pwm    = new Pwm(this);
 }
Beispiel #18
0
 internal Pin13(TreehopperUSB device)
     : base(device, 13)
 {
     ioName   = "RC0";
     AnalogIn = new AnalogIn(this);
 }
Beispiel #19
0
 internal Pin11(TreehopperUSB device)
     : base(device, 11)
 {
     ioName = "RB6";
 }
Beispiel #20
0
 internal Pin2(TreehopperUSB device)
     : base(device, 2)
 {
     ioName =  "RC5";
     Pwm = new Pwm(this);
 }
Beispiel #21
0
 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);
 }
Beispiel #23
0
 internal SoftPwm(TreehopperUSB board, Pin pin)
 {
     this.Board = board;
     this.Pin   = pin;
 }
Beispiel #24
0
 internal Pin3(TreehopperUSB device)
     : base(device, 3)
 {
     ioName =  "RC4";
 }
Beispiel #25
0
 internal Pin1(TreehopperUSB device)
     : base(device, 1)
 {
     ioName =  "RA4";
     AnalogIn = new AnalogIn(this);
 }
Beispiel #26
0
 internal Pin9(TreehopperUSB device)
     : base(device, 9)
 {
     ioName =  "RB5";
     AnalogIn = new AnalogIn(this);
 }
Beispiel #27
0
 internal SoftPwm(TreehopperUSB board, Pin pin)
 {
     this.Board = board;
     this.Pin = pin;
 }
Beispiel #28
0
 internal Pin5(TreehopperUSB device)
     : base(device, 5)
 {
     ioName =  "RC6";
     AnalogIn = new AnalogIn(this);
     Pwm = new Pwm(this);
 }
 internal SoftPwmManager(TreehopperUSB board)
 {
     this.board = board;
     pins = new Dictionary<int, SoftPwmPinConfig>();
 }
Beispiel #30
0
 internal Pin12(TreehopperUSB device)
     : base(device, 12)
 {
     ioName   = "RC1";
     AnalogIn = new AnalogIn(this);
 }
Beispiel #31
0
 internal AnalogOut(TreehopperUSB board)
 {
     Board = board;
 }
Beispiel #32
0
 internal Pin14(TreehopperUSB device)
     : base(device, 14)
 {
     ioName = "RA5";
 }
Beispiel #33
0
 internal Pin14(TreehopperUSB device)
     : base(device, 14)
 {
     ioName = "RA5";
 }
Beispiel #34
0
 internal Pin3(TreehopperUSB device)
     : base(device, 3)
 {
     ioName = "RC4";
 }
Beispiel #35
0
 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";
     }
 }
Beispiel #37
0
 internal Pin6(TreehopperUSB device)
     : base(device, 6)
 {
     ioName =  "RC7";
     AnalogIn = new AnalogIn(this);
 }
Beispiel #38
0
 internal Pin13(TreehopperUSB device)
     : base(device, 13)
 {
     ioName =  "RC0";
     AnalogIn = new AnalogIn(this);
 }
Beispiel #39
0
 internal Pin7(TreehopperUSB device)
     : base(device, 7)
 {
     ioName =  "RC2";
     AnalogIn = new AnalogIn(this);
 }
 void manager_BoardAdded(object sender, TreehopperUSB board)
 {
     myBoard = board;
     myBoard.Open();
     colorSensor = new ColorSensor_ADJDS311(board.I2C, board.Pin1);
 }
Beispiel #41
0
 static void TreehopperUSB_BoardRemoved(TreehopperManager sender, TreehopperUSB board)
 {
     Board.Close();
     timer.Stop();
 }
Beispiel #42
0
        // 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);
        }
Beispiel #43
0
 internal Pin8(TreehopperUSB device)
     : base(device, 8)
 {
     ioName = "RB7";
 }
Beispiel #44
0
 internal Pin12(TreehopperUSB device)
     : base(device, 12)
 {
     ioName = "RC1";
     AnalogIn = new AnalogIn(this);
 }
Beispiel #45
0
 internal Pin9(TreehopperUSB device) : base(device, 9)
 {
     ioName   = "RB5";
     AnalogIn = new AnalogIn(this);
 }
Beispiel #46
0
 internal Pin11(TreehopperUSB device)
     : base(device, 11)
 {
     ioName =  "RB6";
 }
Beispiel #47
0
 internal Pin10(TreehopperUSB device)
     : base(device, 10)
 {
     ioName   = "RB4";
     AnalogIn = new AnalogIn(this);
 }
Beispiel #48
0
 internal Pin6(TreehopperUSB device) : base(device, 6)
 {
     ioName   = "RC7";
     AnalogIn = new AnalogIn(this);
 }
Beispiel #49
0
 internal Pin4(TreehopperUSB device)
     : base(device, 4)
 {
     ioName =  "RC3";
     AnalogIn = new AnalogIn(this);
 }
Beispiel #50
0
 private void SetupApp(TreehopperUSB treehopperBoard)
 {
     board       = treehopperBoard;
     display     = new SevenSegSpi(board.SPI, board.Pin1);
     IsConnected = true;
 }
Beispiel #51
0
 internal Pin7(TreehopperUSB device) : base(device, 7)
 {
     ioName   = "RC2";
     AnalogIn = new AnalogIn(this);
 }