1 of 20

First Gadgeteer Project

2 of 20

Where are you?

  • Making a VS project
  • Parts of a C# program
  • Basics of C# syntax
  • Debugging in VS

  • Questions?

3 of 20

Gadgeteer Assignments

  • Each of you will be assigned a kit.
  • You are responsible for that kit.
    • Make sure all parts are there
    • Make sure kit is returned to appropriate numeric order in storage
    • Missing parts or kits will be assessed as a fine.

  • Checking out kits:
    • By seating order at the beginning of lab.
    • Can not just get them

  • Checking in kits:
    • By seating order – at the end of lab.
    • Need to maintain numeric order
    • Do we need assigned a kit monitor?

4 of 20

Creating a Gadgeteer Project

  • Start with ‘New Project …’
  • Select the Gadgeteer template
  • Name it ‘’FirstGadgeteerApp’
  • ‘OK’

5 of 20

This brings up ‘the wizard’

6 of 20

Important Points

  • Get modules from the toolbox
  • You always need a (red) power module
  • Right Click -> Connect all modules
  • Note the connections and names of the modules

7 of 20

Wizard ready to generate code

8 of 20

Step #1

  • Create a Gadgeteer project named:
    • FirstGadgeteerApp
  • Add
    • A red power module (USBClientDP)
    • A Potentiometer (aka the Knob)
    • A LED7R
  • Right Click - Connect the modules
  • Raise your hand when you are done or if you have a problem

9 of 20

Physically Connecting up the Gadgeteer modules

10 of 20

Solution Explorer

11 of 20

Connecting up the Gadgeteer

  • Connect to the same connectors that you used in the wizard.
  • Forgot what connectors you used?
    • Lost connections demo

12 of 20

Step #2

  • Connect the knob, lED7R, and USBClient modules (In the right places)
    • The connectors are ‘keyed’ so they will only go in the right way
    • Don’t force anything
  • Connect the USB cable to the red module and to your machine
  • Raise you hand when you are done

13 of 20

Adding some code

14 of 20

Step 3 – Adding the code

  • void ProgramStarted()
  • {
  • {

  • double percent; // this variable holds the output from the potentiometer. This ia a value between 0 and 1

  • int intensity; // this variable holds the level of the intensity that the led will be set to. This is a value between 0 and 255

  • Debug.Print("Program Started");
  • while (true) // this loop goes on forever since the condition is always true
  • {

  • percent = potentiometer.ReadPotentiometerPercentage(); // read the current potentiometer value into the variable

  • intensity = (int)(percent * 255); // convert the percentage ( double 0-1) to intensity (integer 0-255)

  • Debug.Print("Integer = " + intensity.ToString()); // write the intensity that we are setting to the output window for comparison

  • System.Threading.Thread.Sleep(50); //slow the loop down a bit by waiting 50 mS between iterations

  • }

  • }

  • }
  • }

15 of 20

Important Points in Adding Code

  • IntelliSense – use the ‘Tab’ key to let it do the typing.
  • Replace the ‘Not Implemented’ exception in the event handler

‘Exception’ == Error event and message

16 of 20

Step #3

  • Add the code to your application
    • Use IntelliSense
  • Do you have any Syntax errors?
    • Fix them
  • Build Solution
    • Build Succeeded?

  • Raise your hand when you are done

17 of 20

Deploying your application

18 of 20

Step #4

  • Deploying your Application
    • Your device is connected to the USB port on your laptop
    • Hit ‘F5’ or ‘Debug->StartDebugging
    • Immediate Window shows ‘Program Started’
      • This may take a bit – the program is rebuilt, sent to the device, and the device is restarted.
    • Press the button on your device

19 of 20

Important Points

  • F5 to deploy
  • Watch the build status
  • Lots of output you don’t need to worry about in the Immediate window – just the last bit
  • Your application is running on the micro processor on the mainboard

20 of 20

Assignment #4

  • Deploy and test your app.

  • Raise you hand when you have change numbers of the knob’s value in the console.
  • Raise your hand if you get an error