SlideShare uma empresa Scribd logo
1 de 67
Baixar para ler offline
MzTEK Programming - Part 1
WHAT WILL WE COVER?
• Howcomputers work and the tools we can use to make them
 do what we want

• The   core components of a program

  • Data types
  • Control structures
  • Functions

• Understanding   code someone else has written

• Look at programming for the Arduino and Processing
 environments
INTRODUCTIONS


• Describe   your experience with programming

• What   is something you want to be able to do? a dream project?
PAIRED PROGRAMMING


• Find   a partner with similar experience as you

• You    will share a computer and take turns typing

• All   exercises will be done in pairs
WHAT ARE PROGRAMS AND
WHY DO WE NEED THEM?
COMPUTERS ARE STUPID
Code You’ve        Instructions for
 Written      ?       Computer

                  Executable Program
                   (e.g. .exe or .app)
Code You’ve               Instructions for
 Written         ?           Computer

              Compiler   Executable Program
                 +        (e.g. .exe or .app)
               Linker
                 +
               Loader
Interactive
       Development
     Environment (IDE)


Code You’ve                     Instructions for
 Written                 ?         Computer

                    Compiler   Executable Program
                       +        (e.g. .exe or .app)
                     Linker
                       +
                     Loader
Think of idea




                Write code




                               Run
                             program
Think of idea




         Break down problem
            into tiny steps


                        Write code for
                          one step


                                           Run
                                         program
EXERCISE
Write out the steps to either:

• Knit   a scarf

• Make    mashed potatoes

Identify the variables and break down steps to simplest
instructions. What gets repeated?

What would you need to do to increase the length or increase
the number of servings?
WHY DO WE NEED TO
COMPILE PROGRAMS?
Interactive
       Development
     Environment (IDE)


Code You’ve                     Instructions for
 Written                 ?         Computer

                    Compiler   Executable Program
                       +        (e.g. .exe or .app)
                     Linker
                       +
                     Loader
An IDE like Processing
or Arduino includes

• text   editor

• compiler   and linker

• other   tools to help
 you
Compiler
      • Translate your text into a language
        (symbols) that a computer
        understands
    Linker
       • Combine the compiled output of
         what you’ve written with what

?        other people have written such as
         libraries
    Loader
      • On the Arduino chip, the program
        needs to be moved from your
        computer to the chip. With
        Processing, your computer is
        running the program, so it doesn’t
        need to be moved.
BRIEF HISTORY OF ARDUINO

• Arduino   means a piece of hardware, a programming language, and
 an IDE

• The
    hardware is a microcontroller plus surrounding circuitry and is
 completely open - you can build your own board if you want to!

• Language
         is based on Wiring which is based on Processing and
 C++ (a very common language)

• IDEis written in Java and derived from Processing IDE and Wiring
 Project
BRIEF HISTORY OF PROCESSING

• Processing     is a set of libraries and a development environment

• Initially   developed to teach programming through visuals

• The Processing Development Environment uses Java (another
  very common programming language)

• Can use the Processing libraries outside of the Processing
  Development Environment
EXERCISE
Hook up Arduino board to       /*
computer and open the            Blink
                                 Turns on an LED on for one second, then off
Arduino IDE.                   for one second, repeatedly.

                                 This example code is in the public domain.
How do you choose the           */

compiler settings? How do      void setup() {
                                 // initialize the digital pin as an output.
you set up the loader?           // Pin 13 has an LED connected on most Arduino
                               boards:
                                 pinMode(13, OUTPUT);
                               }
Open the blink example and
                               void loop() {
save as a new sketch             digitalWrite(13, HIGH);   //   set the LED on
                                 delay(1000);              //   wait for a second
                                 digitalWrite(13, LOW);    //   set the LED off
Change blink time so the LED   }
                                 delay(1000);              //   wait for a second

stays on for 5 seconds.
HOW DO WE STORE DATA?
         -OR-

 WHAT ARE VARIABLES?
2 tbsp olive oil or sun-dried tomato oil
            from the jar                                        1 tsp dried oregano or a small handful of
                                                                fresh leaves, chopped
            6 rashers of smoked streaky bacon,
            chopped                                             1 tsp dried thyme or a small handful of
                                                                fresh leaves, chopped
            2 large onions, chopped
                                                                Drizzle balsamic vinegar
            3 garlic cloves, crushed
                                                                12-14 sun-dried tomato halves, in oil
            1kg/2¼lb lean minced beef
                                                                Salt and freshly ground black pepper
            2 large glasses of red wine
                                                                A good handful of fresh basil leaves, torn
            2x400g cans chopped tomatoes                        into small pieces
            1x290g jar antipasti marinated                      800g-1kg/1¾-2¼lb dried spaghetti
            mushrooms, drained
                                                                Lots of freshly grated parmesan, to serve
            2 fresh or dried bay leaves

     Heat the oil in a large, heavy-based saucepan and fry the bacon until golden over a medium heat.
     Add the onions and garlic, frying until softened. Increase the heat and add the minced beef. Fry it
     until it has browned, breaking down any chunks of meat with a wooden spoon. Pour in the wine and
     boil until it has reduced in volume by about a third. Reduce the temperature and stir in the tomatoes,
     drained mushrooms, bay leaves, oregano, thyme and balsamic vinegar.
1. Either blitz the sun-dried tomatoes in a small blender with a little of the oil to loosen, or just finely chop
   before adding to the pan. Season well with salt and pepper. Cover with a lid and simmer the
   Bolognese sauce over a gentle heat for 1-1½ hours until it's rich and thickened, stirring occasionally.
   At the end of the cooking time, stir in the basil and add any extra seasoning if necessary.
2. Remove from the heat to 'settle' while you cook the spaghetti in plenty of boiling salted water (for the
   time stated on the packet). Drain and divide between warmed plates. Scatter a little parmesan over the
   spaghetti before adding a good ladleful of the Bolognese sauce, finishing with a scattering of more
   cheese and a twist of black
   http://www.bbc.co.uk/food/recipes/spaghettibolognese_67868
2 tbsp olive oil or sun-dried tomato oil
            from the jar                                        1 tsp dried oregano or a small handful of
                                                                fresh leaves, chopped
            6 rashers of smoked streaky bacon,
            chopped                                             1 tsp dried thyme or a small handful of
                                                                fresh leaves, chopped
            2 large onions, chopped
                                                                Drizzle balsamic vinegar
            3 garlic cloves, crushed
                                                                12-14 sun-dried tomato halves, in oil
            1kg/2¼lb lean minced beef
                                                                Salt and freshly ground black pepper
            2 large glasses of red wine
                                                                A good handful of fresh basil leaves, torn
            2x400g cans chopped tomatoes                        into small pieces
            1x290g jar antipasti marinated                      800g-1kg/1¾-2¼lb dried spaghetti
            mushrooms, drained
                                                                Lots of freshly grated parmesan, to serve
            2 fresh or dried bay leaves

     Heat the oil in a large, heavy-based saucepan and fry the bacon until golden over a medium heat.
     Add the onions and garlic, frying until softened. Increase the heat and add the minced beef. Fry it
     until it has browned, breaking down any chunks of meat with a wooden spoon. Pour in the wine and
     boil until it has reduced in volume by about a third. Reduce the temperature and stir in the tomatoes,
     drained mushrooms, bay leaves, oregano, thyme and balsamic vinegar.
1. Either blitz the sun-dried tomatoes in a small blender with a little of the oil to loosen, or just finely chop
   before adding to the pan. Season well with salt and pepper. Cover with a lid and simmer the
   Bolognese sauce over a gentle heat for 1-1½ hours until it's rich and thickened, stirring occasionally.
   At the end of the cooking time, stir in the basil and add any extra seasoning if necessary.
2. Remove from the heat to 'settle' while you cook the spaghetti in plenty of boiling salted water (for the
   time stated on the packet). Drain and divide between warmed plates. Scatter a little parmesan over the
   spaghetti before adding a good ladleful of the Bolognese sauce, finishing with a scattering of more
   cheese and a twist of black
   http://www.bbc.co.uk/food/recipes/spaghettibolognese_67868
2 tbsp olive oil or sun-dried tomato oil
            from the jar                                        1 tsp dried oregano or a small handful of
                                                                fresh leaves, chopped
            6 rashers of smoked streaky bacon,
            chopped                                             1 tsp dried thyme or a small handful of
                                                                fresh leaves, chopped
            2 large onions, chopped
                                                                Drizzle balsamic vinegar
            3 garlic cloves, crushed
                                                                12-14 sun-dried tomato halves, in oil
            1kg/2¼lb lean minced beef
                                                                Salt and freshly ground black pepper
            2 large glasses of red wine
                                                                A good handful of fresh basil leaves, torn
            2x400g cans chopped tomatoes                        into small pieces
            1x290g jar antipasti marinated                      800g-1kg/1¾-2¼lb dried spaghetti
            mushrooms, drained
                                                                Lots of freshly grated parmesan, to serve
            2 fresh or dried bay leaves

     Heat the oil in a large, heavy-based saucepan and fry the bacon until golden over a medium heat.
     Add the onions and garlic, frying until softened. Increase the heat and add the minced beef. Fry it
     until it has browned, breaking down any chunks of meat with a wooden spoon. Pour in the wine and
     boil until it has reduced in volume by about a third. Reduce the temperature and stir in the tomatoes,
     drained mushrooms, bay leaves, oregano, thyme and balsamic vinegar.
1. Either blitz the sun-dried tomatoes in a small blender with a little of the oil to loosen, or just finely chop
   before adding to the pan. Season well with salt and pepper. Cover with a lid and simmer the
   Bolognese sauce over a gentle heat for 1-1½ hours until it's rich and thickened, stirring occasionally.
   At the end of the cooking time, stir in the basil and add any extra seasoning if necessary.
2. Remove from the heat to 'settle' while you cook the spaghetti in plenty of boiling salted water (for the
   time stated on the packet). Drain and divide between warmed plates. Scatter a little parmesan over the
   spaghetti before adding a good ladleful of the Bolognese sauce, finishing with a scattering of more
   cheese and a twist of black
   http://www.bbc.co.uk/food/recipes/spaghettibolognese_67868
2 tbsp olive oil or sun-dried tomato oil
            from the jar                                             1 tsp dried oregano or a small handful of
            6 rashers of smoked streaky bacon,
                                                                 We would be very irritated if
                                                                     fresh leaves, chopped
            chopped                                             there was an ingredient needed,
                                                                     1 tsp dried thyme or a small handful of
                                                                     fresh leaves, chopped
            2 large onions, chopped
            3 garlic cloves, crushed
                                                                   that wasn’t included here.
                                                                     Drizzle balsamic vinegar
                                                                     12-14 sun-dried tomato halves, in oil
            1kg/2¼lb lean minced beef
                                                                     Salt and freshly ground black pepper
            2 large glasses of red wine
                                                                     A good handful of fresh basil leaves, torn
            2x400g cans chopped tomatoes                             into small pieces
            1x290g jar antipasti marinated                           800g-1kg/1¾-2¼lb dried spaghetti
            mushrooms, drained
                                                                     Lots of freshly grated parmesan, to serve
            2 fresh or dried bay leaves

     Heat the oil in a large, heavy-based saucepan and fry the bacon until golden over a medium heat.
     Add the onions and garlic, frying until softened. Increase the heat and add the minced beef. Fry it
     until it has browned, breaking down any chunks of meat with a wooden spoon. Pour in the wine and
     boil until it has reduced in volume by about a third. Reduce the temperature and stir in the tomatoes,
     drained mushrooms, bay leaves, oregano, thyme and balsamic vinegar.
1. Either blitz the sun-dried tomatoes in a small blender with a little of the oil to loosen, or just finely chop
   before adding to the pan. Season well with salt and pepper. Cover with a lid and simmer the
   Bolognese sauce over a gentle heat for 1-1½ hours until it's rich and thickened, stirring occasionally.
   At the end of the cooking time, stir in the basil and add any extra seasoning if necessary.
2. Remove from the heat to 'settle' while you cook the spaghetti in plenty of boiling salted water (for the
   time stated on the packet). Drain and divide between warmed plates. Scatter a little parmesan over the
   spaghetti before adding a good ladleful of the Bolognese sauce, finishing with a scattering of more
   cheese and a twist of black
   http://www.bbc.co.uk/food/recipes/spaghettibolognese_67868
2 tbsp olive oil or sun-dried tomato oil
            from the jar                                             1 tsp dried oregano or a small handful of
            6 rashers of smoked streaky bacon,
                                                                 We would be very irritated if
                                                                     fresh leaves, chopped
            chopped                                             there was an ingredient needed,
                                                                     1 tsp dried thyme or a small handful of
                                                                     fresh leaves, chopped
            2 large onions, chopped
            3 garlic cloves, crushed
                                                                   that wasn’t included here.
                                                                     Drizzle balsamic vinegar
                                                                     12-14 sun-dried tomato halves, in oil
            1kg/2¼lb lean minced beef
                                                                     Salt and freshly ground black pepper
          The units used to describe the amount
            2 large glasses of red wine
                                                                     A good handful of fresh basil leaves, torn
            2x400g cans chopped tomatoes
           of the ingredients varies according to
            1x290g jar antipasti marinated
                                                                     into small pieces
                                                                     800g-1kg/1¾-2¼lb dried spaghetti
            the culture of the person cooking.
            mushrooms, drained
                                                                     Lots of freshly grated parmesan, to serve
            2 fresh or dried bay leaves

     Heat the oil in a large, heavy-based saucepan and fry the bacon until golden over a medium heat.
     Add the onions and garlic, frying until softened. Increase the heat and add the minced beef. Fry it
     until it has browned, breaking down any chunks of meat with a wooden spoon. Pour in the wine and
     boil until it has reduced in volume by about a third. Reduce the temperature and stir in the tomatoes,
     drained mushrooms, bay leaves, oregano, thyme and balsamic vinegar.
1. Either blitz the sun-dried tomatoes in a small blender with a little of the oil to loosen, or just finely chop
   before adding to the pan. Season well with salt and pepper. Cover with a lid and simmer the
   Bolognese sauce over a gentle heat for 1-1½ hours until it's rich and thickened, stirring occasionally.
   At the end of the cooking time, stir in the basil and add any extra seasoning if necessary.
2. Remove from the heat to 'settle' while you cook the spaghetti in plenty of boiling salted water (for the
   time stated on the packet). Drain and divide between warmed plates. Scatter a little parmesan over the
   spaghetti before adding a good ladleful of the Bolognese sauce, finishing with a scattering of more
   cheese and a twist of black
   http://www.bbc.co.uk/food/recipes/spaghettibolognese_67868
2 tbsp olive oil or sun-dried tomato oil
              from the jar                                             1 tsp dried oregano or a small handful of
              6 rashers of smoked streaky bacon,
                                                                   We would be very irritated if
                                                                       fresh leaves, chopped
              chopped                                             there was an ingredient needed,
                                                                       1 tsp dried thyme or a small handful of
                                                                       fresh leaves, chopped
              2 large onions, chopped
              3 garlic cloves, crushed
                                                                     that wasn’t included here.
                                                                       Drizzle balsamic vinegar
                                                                       12-14 sun-dried tomato halves, in oil
              1kg/2¼lb lean minced beef
                                                                       Salt and freshly ground black pepper
            The units used to describe the amount
              2 large glasses of red wine
                                                                       A good handful of fresh basil leaves, torn
              2x400g cans chopped tomatoes
             of the ingredients varies according to
              1x290g jar antipasti marinated
                                                                       into small pieces
                                                                       800g-1kg/1¾-2¼lb dried spaghetti
              the culture of the person cooking.
              mushrooms, drained
                                                                       Lots of freshly grated parmesan, to serve
              2 fresh or dried bay leaves

       Heat the oil in a large, heavy-based saucepan and fry the bacon until golden over a medium heat.
       Add the onions and garlic, frying until softened. Increase the heat and add the minced beef. Fry it
       until it has browned, breaking down any chunks of meat with a wooden spoon. Pour in the wine and
       boil until it has reduced in volume by about a third. Reduce the temperature and stir in the tomatoes,
                          It’s easier to follow the directions when
       drained mushrooms, bay leaves, oregano, thyme and balsamic vinegar.
1.   Either blitz the sun-dried tomatoes in a small blender with a little of the oil to loosen, or just finely chop
     before adding to the pan. Season well with salt and pepper. Cover with a lidof simmer the
                            you don’t have to list the amounts and
                                ingredients within the directions.
     Bolognese sauce over a gentle heat for 1-1½ hours until it's rich and thickened, stirring occasionally.
     At the end of the cooking time, stir in the basil and add any extra seasoning if necessary.
2. Remove from the heat to 'settle' while you cook the spaghetti in plenty of boiling salted water (for the
   time stated on the packet). Drain and divide between warmed plates. Scatter a little parmesan over the
   spaghetti before adding a good ladleful of the Bolognese sauce, finishing with a scattering of more
   cheese and a twist of black
     http://www.bbc.co.uk/food/recipes/spaghettibolognese_67868
int   x;
int   y;
int   width;
int   height;

size(200, 200);

x = 150;
y = 100;
width = 90;
height = 80;

ellipse(x, y, width, height);
int   x;
int   y;
int   width;
                  ingredients or variables
int   height;

size(200, 200);

x = 150;
y = 100;
width = 90;
height = 80;

ellipse(x, y, width, height);
int   x;
int   y;
int   width;
                  ingredients or variables
int   height;

size(200, 200);

x = 150;
y = 100;          directions or algorithm
width = 90;
height = 80;

ellipse(x, y, width, height);
data type

  int   x;
  int   y;
  int   width;
                    ingredients or variables
  int   height;

  size(200, 200);

  x = 150;
  y = 100;          directions or algorithm
  width = 90;
  height = 80;

  ellipse(x, y, width, height);
data type    variable name
  int   x;
  int   y;
  int   width;
                    ingredients or variables
  int   height;

  size(200, 200);

  x = 150;
  y = 100;          directions or algorithm
  width = 90;
  height = 80;

  ellipse(x, y, width, height);
Cooking uses units of weight or volume, computers use bytes.
Cooking uses units of weight or volume, computers use bytes.
                     A bit is a 0 or a 1.

                         0         1
Cooking uses units of weight or volume, computers use bytes.
                     A bit is a 0 or a 1.

                         0         1

                  A byte is eight 0s or 1s.
Cooking uses units of weight or volume, computers use bytes.
                      A bit is a 0 or a 1.

                          0         1

                   A byte is eight 0s or 1s.



      0s and 1s are used to represent things like numbers.
    It’s up to the programming language (and hardware) to
    determine what kinds of things 0s and 1s can represent.
PRIMITIVE DATA TYPES
   (FOR BOTH PROCESSING AND ARDUINO UNLESS NOTED OTHERWISE)


                   boolean is true or false
                   boolean running = false;
                   In Arduino, byte is an unsigned number (no
                   negative numbers)
                   can be 0 to 255, 8-bits (2^8)
Arduino Only       B is put in front to indicate numbers are
                   binary
                   byte b = B10010;

                   In Processing, byte is a number
                   can be 127 to -128, 8-bits (2^8)
Processing Only    byte b = -125;
PRIMITIVE DATA TYPES
(FOR BOTH PROCESSING AND ARDUINO UNLESS NOTED OTHERWISE)




            int is an integer ranging from -32,768 to 32,767
            int i = 23456;




            long is a large integer ranging from -2,147,483,648
            to 2,147,483,647
            long g = 1239382345L;
PRIMITIVE DATA TYPES
(FOR BOTH PROCESSING AND ARDUINO UNLESS NOTED OTHERWISE)



                float is a number with a decimal point
                ranging from -3.40282347E+38 to
                3.40282347E+38
                float f = -234.56;



                char is a single letter (or symbol like “.”)
                char myChar = 'A';

                unsigned char is a number 0 to 255, it is better
                to use the byte data type instead
                unsigned char myChar = 240;
PRIMITIVE DATA TYPES
   (FOR BOTH PROCESSING AND ARDUINO UNLESS NOTED OTHERWISE)




                   word is the same as unsigned int is a
                   number without a decimal point ranging
                   from 0 to 65,535 (2^16) - 1)
Arduino Only       word w = 55424;

                   unsigned int is a number without a decimal
                   point ranging from 0 to 65,535 (2^16) - 1)
                   unsigned int ui = 55424;

                   unsigned long is a large integer ranging
                   from 0 to 4,294,967,295 (2^32 - 1), so no
                   negative numbers
                   long g = 4239382345ul;
RULES FOR NAMING VARIABLES
RULES FOR NAMING VARIABLES
 $3%^   Don’t start with a character besides a letter
RULES FOR NAMING VARIABLES
 $3%^   Don’t start with a character besides a letter


abc123 Only use numbers and letters and “_”
RULES FOR NAMING VARIABLES
 $3%^      Don’t start with a character besides a letter


abc123 Only use numbers and letters and “_”


 if, for   Can’t use words that hold meaning to the compiler
RULES FOR NAMING VARIABLES
 $3%^         Don’t start with a character besides a letter


abc123 Only use numbers and letters and “_”


 if, for      Can’t use words that hold meaning to the compiler


 rectHeight   Be descriptive
RULES FOR NAMING VARIABLES
 $3%^         Don’t start with a character besides a letter


abc123 Only use numbers and letters and “_”


 if, for      Can’t use words that hold meaning to the compiler


 rectHeight   Be descriptive


   aA         Case is important
EXERCISE
In Processing, create a sketch which draws a green ellipse.

Use the functions listed below. Look up these functions
in the Processing documentation for more guidance.

         size(width, height)
         fill(value1, value2, value3)
         ellipse(x, y, width, height)
DECLARATION VS INITIALISATION
 As in a recipe, ingredients
 need to be listed at the top
 so you know what to buy.

 In code, it’s so the compiler
 knows how much memory
 to reserve. This is called
 declaring.
DECLARATION VS INITIALISATION
 As in a recipe, ingredients
 need to be listed at the top
 so you know what to buy.

 In code, it’s so the compiler
 knows how much memory
 to reserve. This is called
 declaring.

     int myInt;

      Reserve space for
          an int
DECLARATION VS INITIALISATION
 As in a recipe, ingredients     We don’t have to know
 need to be listed at the top    what value will be stored in
 so you know what to buy.        myInt right away.
 In code, it’s so the compiler   We can choose a value
 knows how much memory
 to reserve. This is called      later. This is called initialising.
 declaring.

     int myInt;

      Reserve space for
          an int
DECLARATION VS INITIALISATION
 As in a recipe, ingredients     We don’t have to know
 need to be listed at the top    what value will be stored in
 so you know what to buy.        myInt right away.
 In code, it’s so the compiler   We can choose a value
 knows how much memory
 to reserve. This is called      later. This is called initialising.
 declaring.

     int myInt;                      myInt = 15;

      Reserve space for             Store the value 15 in the
          an int                   space reserved for myInt

                                  15
Need to declare before or at the same
time as initialisation.
Need to declare before or at the same
time as initialisation.
myInt = 3;
int myInt;
Need to declare before or at the same
time as initialisation.
myInt = 3;               int myInt;
int myInt;               myInt = 3;
Need to declare before or at the same
time as initialisation.
myInt = 3;                    int myInt;
int myInt;                    myInt = 3;


Can’t use a variable before it is initialised.
Need to declare before or at the same
     time as initialisation.
    myInt = 3;                     int myInt;
    int myInt;                     myInt = 3;


     Can’t use a variable before it is initialised.

int myInt;
myInt = myInt + 7;
Need to declare before or at the same
     time as initialisation.
    myInt = 3;                     int myInt;
    int myInt;                     myInt = 3;


     Can’t use a variable before it is initialised.

int myInt;                   int myInt = 3;
myInt = myInt + 7;           myInt = myInt + 7;
TO CREATE A VARIABLE
1. Decide what the data type should be. Usually the main
   decisions are between int, float and char.
                                float
                                int
                                char
TO CREATE A VARIABLE
1. Decide what the data type should be. Usually the main
   decisions are between int, float and char.
      to create a float type
                                float
                                int
                                char
TO CREATE A VARIABLE
1. Decide what the data type should be. Usually the main
   decisions are between int, float and char.
      to create a float type
                                float
       to create an int type    int
                                char
TO CREATE A VARIABLE
1. Decide what the data type should be. Usually the main
   decisions are between int, float and char.
      to create a float type
                                float
       to create an int type    int
       to create a char type    char
TO CREATE A VARIABLE
1. Decide what the data type should be. Usually the main
   decisions are between int, float and char.
      to create a float type
                                float
       to create an int type    int
       to create a char type    char
2. Decide on a name for your variable. Remember the rules.
TO CREATE A VARIABLE
1. Decide what the data type should be. Usually the main
   decisions are between int, float and char.
      to create a float type
                                float
       to create an int type    int
       to create a char type    char
2. Decide on a name for your variable. Remember the rules.
                    float scale;
                    int redValue;
                    char finalMark;
TO CREATE A VARIABLE
1. Decide what the data type should be. Usually the main
   decisions are between int, float and char.
      to create a float type
                                float
       to create an int type    int
       to create a char type    char
2. Decide on a name for your variable. Remember the rules.
                    float scale;            you get to choose
                    int redValue;               the name
                    char finalMark;
TO CREATE A VARIABLE
1. Decide what the data type should be. Usually the main
   decisions are between int, float and char.
      to create a float type
                                  float
       to create an int type      int
       to create a char type      char
2. Decide on a name for your variable. Remember the rules.
                    float scale;               you get to choose
                    int redValue;                  the name
                    char finalMark;

3. If you already know what the value of that variable is, then go
   ahead and set the value.
TO CREATE A VARIABLE
1. Decide what the data type should be. Usually the main
   decisions are between int, float and char.
      to create a float type
                                  float
       to create an int type      int
       to create a char type      char
2. Decide on a name for your variable. Remember the rules.
                    float scale;               you get to choose
                    int redValue;                  the name
                    char finalMark;

3. If you already know what the value of that variable is, then go
   ahead and set the value.
                 float scale = 0.5;
                 int redValue = 199;
                 char finalMark = ‘B’;
TO CREATE A VARIABLE
1. Decide what the data type should be. Usually the main
   decisions are between int, float and char.
       to create a float type
                                   float
       to create an int type       int
       to create a char type       char
2. Decide on a name for your variable. Remember the rules.
                     float scale;               you get to choose
                     int redValue;                  the name
                     char finalMark;

3. If you already know what the value of that variable is, then go
   ahead and set the value.                       if you don’t know the
                 float scale = 0.5;               value yet, stop at step 2.
                 int redValue = 199;               but remember to end
                 char finalMark = ‘B’;                each line with a ;
EXERCISE

In Processing, return to your sketch which draws a green
ellipse.


Replace the numbers you’ve used as arguments in the fill( )
and ellipse( ) functions with variables.


What kind of datatypes do you need to use? What are
good descriptive names for those variables?

Mais conteúdo relacionado

Último

Quantitative research methodology and survey design
Quantitative research methodology and survey designQuantitative research methodology and survey design
Quantitative research methodology and survey designBalelaBoru
 
LEAD6001 - Introduction to Advanced Stud
LEAD6001 - Introduction to Advanced StudLEAD6001 - Introduction to Advanced Stud
LEAD6001 - Introduction to Advanced StudDr. Bruce A. Johnson
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 11 THEO ĐƠN VỊ BÀI HỌC - CẢ NĂM - CÓ FILE NGHE (GLOB...
BÀI TẬP BỔ TRỢ TIẾNG ANH 11 THEO ĐƠN VỊ BÀI HỌC - CẢ NĂM - CÓ FILE NGHE (GLOB...BÀI TẬP BỔ TRỢ TIẾNG ANH 11 THEO ĐƠN VỊ BÀI HỌC - CẢ NĂM - CÓ FILE NGHE (GLOB...
BÀI TẬP BỔ TRỢ TIẾNG ANH 11 THEO ĐƠN VỊ BÀI HỌC - CẢ NĂM - CÓ FILE NGHE (GLOB...Nguyen Thanh Tu Collection
 
Pharmacology chapter No 7 full notes.pdf
Pharmacology chapter No 7 full notes.pdfPharmacology chapter No 7 full notes.pdf
Pharmacology chapter No 7 full notes.pdfSumit Tiwari
 
Certification Study Group - Professional ML Engineer Session 3 (Machine Learn...
Certification Study Group - Professional ML Engineer Session 3 (Machine Learn...Certification Study Group - Professional ML Engineer Session 3 (Machine Learn...
Certification Study Group - Professional ML Engineer Session 3 (Machine Learn...gdgsurrey
 
Dhavni Theory by Anandvardhana Indian Poetics
Dhavni Theory by Anandvardhana Indian PoeticsDhavni Theory by Anandvardhana Indian Poetics
Dhavni Theory by Anandvardhana Indian PoeticsDhatriParmar
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - HK2 (...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - HK2 (...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - HK2 (...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - HK2 (...Nguyen Thanh Tu Collection
 
DNA and RNA , Structure, Functions, Types, difference, Similarities, Protein ...
DNA and RNA , Structure, Functions, Types, difference, Similarities, Protein ...DNA and RNA , Structure, Functions, Types, difference, Similarities, Protein ...
DNA and RNA , Structure, Functions, Types, difference, Similarities, Protein ...AKSHAYMAGAR17
 
LEAD5623 The Economics of Community Coll
LEAD5623 The Economics of Community CollLEAD5623 The Economics of Community Coll
LEAD5623 The Economics of Community CollDr. Bruce A. Johnson
 
The basics of sentences session 8pptx.pptx
The basics of sentences session 8pptx.pptxThe basics of sentences session 8pptx.pptx
The basics of sentences session 8pptx.pptxheathfieldcps1
 
3.12.24 Freedom Summer in Mississippi.pptx
3.12.24 Freedom Summer in Mississippi.pptx3.12.24 Freedom Summer in Mississippi.pptx
3.12.24 Freedom Summer in Mississippi.pptxmary850239
 
VIT336 – Recommender System - Unit 3.pdf
VIT336 – Recommender System - Unit 3.pdfVIT336 – Recommender System - Unit 3.pdf
VIT336 – Recommender System - Unit 3.pdfArthyR3
 
3.14.24 Gender Discrimination and Gender Inequity.pptx
3.14.24 Gender Discrimination and Gender Inequity.pptx3.14.24 Gender Discrimination and Gender Inequity.pptx
3.14.24 Gender Discrimination and Gender Inequity.pptxmary850239
 
The OERs: Transforming Education for Sustainable Future by Dr. Sarita Anand
The OERs: Transforming Education for Sustainable Future by Dr. Sarita AnandThe OERs: Transforming Education for Sustainable Future by Dr. Sarita Anand
The OERs: Transforming Education for Sustainable Future by Dr. Sarita AnandDr. Sarita Anand
 
2024.03.16 How to write better quality materials for your learners ELTABB San...
2024.03.16 How to write better quality materials for your learners ELTABB San...2024.03.16 How to write better quality materials for your learners ELTABB San...
2024.03.16 How to write better quality materials for your learners ELTABB San...Sandy Millin
 
Alamkara theory by Bhamaha Indian Poetics (1).pptx
Alamkara theory by Bhamaha Indian Poetics (1).pptxAlamkara theory by Bhamaha Indian Poetics (1).pptx
Alamkara theory by Bhamaha Indian Poetics (1).pptxDhatriParmar
 
PHARMACOGNOSY CHAPTER NO 5 CARMINATIVES AND G.pdf
PHARMACOGNOSY CHAPTER NO 5 CARMINATIVES AND G.pdfPHARMACOGNOSY CHAPTER NO 5 CARMINATIVES AND G.pdf
PHARMACOGNOSY CHAPTER NO 5 CARMINATIVES AND G.pdfSumit Tiwari
 
EDD8524 The Future of Educational Leader
EDD8524 The Future of Educational LeaderEDD8524 The Future of Educational Leader
EDD8524 The Future of Educational LeaderDr. Bruce A. Johnson
 

Último (20)

Quantitative research methodology and survey design
Quantitative research methodology and survey designQuantitative research methodology and survey design
Quantitative research methodology and survey design
 
LEAD6001 - Introduction to Advanced Stud
LEAD6001 - Introduction to Advanced StudLEAD6001 - Introduction to Advanced Stud
LEAD6001 - Introduction to Advanced Stud
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 11 THEO ĐƠN VỊ BÀI HỌC - CẢ NĂM - CÓ FILE NGHE (GLOB...
BÀI TẬP BỔ TRỢ TIẾNG ANH 11 THEO ĐƠN VỊ BÀI HỌC - CẢ NĂM - CÓ FILE NGHE (GLOB...BÀI TẬP BỔ TRỢ TIẾNG ANH 11 THEO ĐƠN VỊ BÀI HỌC - CẢ NĂM - CÓ FILE NGHE (GLOB...
BÀI TẬP BỔ TRỢ TIẾNG ANH 11 THEO ĐƠN VỊ BÀI HỌC - CẢ NĂM - CÓ FILE NGHE (GLOB...
 
Pharmacology chapter No 7 full notes.pdf
Pharmacology chapter No 7 full notes.pdfPharmacology chapter No 7 full notes.pdf
Pharmacology chapter No 7 full notes.pdf
 
Certification Study Group - Professional ML Engineer Session 3 (Machine Learn...
Certification Study Group - Professional ML Engineer Session 3 (Machine Learn...Certification Study Group - Professional ML Engineer Session 3 (Machine Learn...
Certification Study Group - Professional ML Engineer Session 3 (Machine Learn...
 
Dhavni Theory by Anandvardhana Indian Poetics
Dhavni Theory by Anandvardhana Indian PoeticsDhavni Theory by Anandvardhana Indian Poetics
Dhavni Theory by Anandvardhana Indian Poetics
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - HK2 (...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - HK2 (...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - HK2 (...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - HK2 (...
 
DNA and RNA , Structure, Functions, Types, difference, Similarities, Protein ...
DNA and RNA , Structure, Functions, Types, difference, Similarities, Protein ...DNA and RNA , Structure, Functions, Types, difference, Similarities, Protein ...
DNA and RNA , Structure, Functions, Types, difference, Similarities, Protein ...
 
LEAD5623 The Economics of Community Coll
LEAD5623 The Economics of Community CollLEAD5623 The Economics of Community Coll
LEAD5623 The Economics of Community Coll
 
The basics of sentences session 8pptx.pptx
The basics of sentences session 8pptx.pptxThe basics of sentences session 8pptx.pptx
The basics of sentences session 8pptx.pptx
 
Least Significance Difference:Biostatics and Research Methodology
Least Significance Difference:Biostatics and Research MethodologyLeast Significance Difference:Biostatics and Research Methodology
Least Significance Difference:Biostatics and Research Methodology
 
ANOVA Parametric test: Biostatics and Research Methodology
ANOVA Parametric test: Biostatics and Research MethodologyANOVA Parametric test: Biostatics and Research Methodology
ANOVA Parametric test: Biostatics and Research Methodology
 
3.12.24 Freedom Summer in Mississippi.pptx
3.12.24 Freedom Summer in Mississippi.pptx3.12.24 Freedom Summer in Mississippi.pptx
3.12.24 Freedom Summer in Mississippi.pptx
 
VIT336 – Recommender System - Unit 3.pdf
VIT336 – Recommender System - Unit 3.pdfVIT336 – Recommender System - Unit 3.pdf
VIT336 – Recommender System - Unit 3.pdf
 
3.14.24 Gender Discrimination and Gender Inequity.pptx
3.14.24 Gender Discrimination and Gender Inequity.pptx3.14.24 Gender Discrimination and Gender Inequity.pptx
3.14.24 Gender Discrimination and Gender Inequity.pptx
 
The OERs: Transforming Education for Sustainable Future by Dr. Sarita Anand
The OERs: Transforming Education for Sustainable Future by Dr. Sarita AnandThe OERs: Transforming Education for Sustainable Future by Dr. Sarita Anand
The OERs: Transforming Education for Sustainable Future by Dr. Sarita Anand
 
2024.03.16 How to write better quality materials for your learners ELTABB San...
2024.03.16 How to write better quality materials for your learners ELTABB San...2024.03.16 How to write better quality materials for your learners ELTABB San...
2024.03.16 How to write better quality materials for your learners ELTABB San...
 
Alamkara theory by Bhamaha Indian Poetics (1).pptx
Alamkara theory by Bhamaha Indian Poetics (1).pptxAlamkara theory by Bhamaha Indian Poetics (1).pptx
Alamkara theory by Bhamaha Indian Poetics (1).pptx
 
PHARMACOGNOSY CHAPTER NO 5 CARMINATIVES AND G.pdf
PHARMACOGNOSY CHAPTER NO 5 CARMINATIVES AND G.pdfPHARMACOGNOSY CHAPTER NO 5 CARMINATIVES AND G.pdf
PHARMACOGNOSY CHAPTER NO 5 CARMINATIVES AND G.pdf
 
EDD8524 The Future of Educational Leader
EDD8524 The Future of Educational LeaderEDD8524 The Future of Educational Leader
EDD8524 The Future of Educational Leader
 

Destaque

AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Applitools
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at WorkGetSmarter
 

Destaque (20)

AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
 
ChatGPT webinar slides
ChatGPT webinar slidesChatGPT webinar slides
ChatGPT webinar slides
 
More than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike RoutesMore than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike Routes
 

MzTEK Programming - Part 1

  • 2. WHAT WILL WE COVER? • Howcomputers work and the tools we can use to make them do what we want • The core components of a program • Data types • Control structures • Functions • Understanding code someone else has written • Look at programming for the Arduino and Processing environments
  • 3. INTRODUCTIONS • Describe your experience with programming • What is something you want to be able to do? a dream project?
  • 4. PAIRED PROGRAMMING • Find a partner with similar experience as you • You will share a computer and take turns typing • All exercises will be done in pairs
  • 5. WHAT ARE PROGRAMS AND WHY DO WE NEED THEM?
  • 7. Code You’ve Instructions for Written ? Computer Executable Program (e.g. .exe or .app)
  • 8. Code You’ve Instructions for Written ? Computer Compiler Executable Program + (e.g. .exe or .app) Linker + Loader
  • 9. Interactive Development Environment (IDE) Code You’ve Instructions for Written ? Computer Compiler Executable Program + (e.g. .exe or .app) Linker + Loader
  • 10. Think of idea Write code Run program
  • 11. Think of idea Break down problem into tiny steps Write code for one step Run program
  • 12. EXERCISE Write out the steps to either: • Knit a scarf • Make mashed potatoes Identify the variables and break down steps to simplest instructions. What gets repeated? What would you need to do to increase the length or increase the number of servings?
  • 13. WHY DO WE NEED TO COMPILE PROGRAMS?
  • 14. Interactive Development Environment (IDE) Code You’ve Instructions for Written ? Computer Compiler Executable Program + (e.g. .exe or .app) Linker + Loader
  • 15. An IDE like Processing or Arduino includes • text editor • compiler and linker • other tools to help you
  • 16. Compiler • Translate your text into a language (symbols) that a computer understands Linker • Combine the compiled output of what you’ve written with what ? other people have written such as libraries Loader • On the Arduino chip, the program needs to be moved from your computer to the chip. With Processing, your computer is running the program, so it doesn’t need to be moved.
  • 17. BRIEF HISTORY OF ARDUINO • Arduino means a piece of hardware, a programming language, and an IDE • The hardware is a microcontroller plus surrounding circuitry and is completely open - you can build your own board if you want to! • Language is based on Wiring which is based on Processing and C++ (a very common language) • IDEis written in Java and derived from Processing IDE and Wiring Project
  • 18. BRIEF HISTORY OF PROCESSING • Processing is a set of libraries and a development environment • Initially developed to teach programming through visuals • The Processing Development Environment uses Java (another very common programming language) • Can use the Processing libraries outside of the Processing Development Environment
  • 19. EXERCISE Hook up Arduino board to /* computer and open the Blink Turns on an LED on for one second, then off Arduino IDE. for one second, repeatedly. This example code is in the public domain. How do you choose the */ compiler settings? How do void setup() { // initialize the digital pin as an output. you set up the loader? // Pin 13 has an LED connected on most Arduino boards: pinMode(13, OUTPUT); } Open the blink example and void loop() { save as a new sketch digitalWrite(13, HIGH); // set the LED on delay(1000); // wait for a second digitalWrite(13, LOW); // set the LED off Change blink time so the LED } delay(1000); // wait for a second stays on for 5 seconds.
  • 20. HOW DO WE STORE DATA? -OR- WHAT ARE VARIABLES?
  • 21. 2 tbsp olive oil or sun-dried tomato oil from the jar 1 tsp dried oregano or a small handful of fresh leaves, chopped 6 rashers of smoked streaky bacon, chopped 1 tsp dried thyme or a small handful of fresh leaves, chopped 2 large onions, chopped Drizzle balsamic vinegar 3 garlic cloves, crushed 12-14 sun-dried tomato halves, in oil 1kg/2¼lb lean minced beef Salt and freshly ground black pepper 2 large glasses of red wine A good handful of fresh basil leaves, torn 2x400g cans chopped tomatoes into small pieces 1x290g jar antipasti marinated 800g-1kg/1¾-2¼lb dried spaghetti mushrooms, drained Lots of freshly grated parmesan, to serve 2 fresh or dried bay leaves Heat the oil in a large, heavy-based saucepan and fry the bacon until golden over a medium heat. Add the onions and garlic, frying until softened. Increase the heat and add the minced beef. Fry it until it has browned, breaking down any chunks of meat with a wooden spoon. Pour in the wine and boil until it has reduced in volume by about a third. Reduce the temperature and stir in the tomatoes, drained mushrooms, bay leaves, oregano, thyme and balsamic vinegar. 1. Either blitz the sun-dried tomatoes in a small blender with a little of the oil to loosen, or just finely chop before adding to the pan. Season well with salt and pepper. Cover with a lid and simmer the Bolognese sauce over a gentle heat for 1-1½ hours until it's rich and thickened, stirring occasionally. At the end of the cooking time, stir in the basil and add any extra seasoning if necessary. 2. Remove from the heat to 'settle' while you cook the spaghetti in plenty of boiling salted water (for the time stated on the packet). Drain and divide between warmed plates. Scatter a little parmesan over the spaghetti before adding a good ladleful of the Bolognese sauce, finishing with a scattering of more cheese and a twist of black http://www.bbc.co.uk/food/recipes/spaghettibolognese_67868
  • 22. 2 tbsp olive oil or sun-dried tomato oil from the jar 1 tsp dried oregano or a small handful of fresh leaves, chopped 6 rashers of smoked streaky bacon, chopped 1 tsp dried thyme or a small handful of fresh leaves, chopped 2 large onions, chopped Drizzle balsamic vinegar 3 garlic cloves, crushed 12-14 sun-dried tomato halves, in oil 1kg/2¼lb lean minced beef Salt and freshly ground black pepper 2 large glasses of red wine A good handful of fresh basil leaves, torn 2x400g cans chopped tomatoes into small pieces 1x290g jar antipasti marinated 800g-1kg/1¾-2¼lb dried spaghetti mushrooms, drained Lots of freshly grated parmesan, to serve 2 fresh or dried bay leaves Heat the oil in a large, heavy-based saucepan and fry the bacon until golden over a medium heat. Add the onions and garlic, frying until softened. Increase the heat and add the minced beef. Fry it until it has browned, breaking down any chunks of meat with a wooden spoon. Pour in the wine and boil until it has reduced in volume by about a third. Reduce the temperature and stir in the tomatoes, drained mushrooms, bay leaves, oregano, thyme and balsamic vinegar. 1. Either blitz the sun-dried tomatoes in a small blender with a little of the oil to loosen, or just finely chop before adding to the pan. Season well with salt and pepper. Cover with a lid and simmer the Bolognese sauce over a gentle heat for 1-1½ hours until it's rich and thickened, stirring occasionally. At the end of the cooking time, stir in the basil and add any extra seasoning if necessary. 2. Remove from the heat to 'settle' while you cook the spaghetti in plenty of boiling salted water (for the time stated on the packet). Drain and divide between warmed plates. Scatter a little parmesan over the spaghetti before adding a good ladleful of the Bolognese sauce, finishing with a scattering of more cheese and a twist of black http://www.bbc.co.uk/food/recipes/spaghettibolognese_67868
  • 23. 2 tbsp olive oil or sun-dried tomato oil from the jar 1 tsp dried oregano or a small handful of fresh leaves, chopped 6 rashers of smoked streaky bacon, chopped 1 tsp dried thyme or a small handful of fresh leaves, chopped 2 large onions, chopped Drizzle balsamic vinegar 3 garlic cloves, crushed 12-14 sun-dried tomato halves, in oil 1kg/2¼lb lean minced beef Salt and freshly ground black pepper 2 large glasses of red wine A good handful of fresh basil leaves, torn 2x400g cans chopped tomatoes into small pieces 1x290g jar antipasti marinated 800g-1kg/1¾-2¼lb dried spaghetti mushrooms, drained Lots of freshly grated parmesan, to serve 2 fresh or dried bay leaves Heat the oil in a large, heavy-based saucepan and fry the bacon until golden over a medium heat. Add the onions and garlic, frying until softened. Increase the heat and add the minced beef. Fry it until it has browned, breaking down any chunks of meat with a wooden spoon. Pour in the wine and boil until it has reduced in volume by about a third. Reduce the temperature and stir in the tomatoes, drained mushrooms, bay leaves, oregano, thyme and balsamic vinegar. 1. Either blitz the sun-dried tomatoes in a small blender with a little of the oil to loosen, or just finely chop before adding to the pan. Season well with salt and pepper. Cover with a lid and simmer the Bolognese sauce over a gentle heat for 1-1½ hours until it's rich and thickened, stirring occasionally. At the end of the cooking time, stir in the basil and add any extra seasoning if necessary. 2. Remove from the heat to 'settle' while you cook the spaghetti in plenty of boiling salted water (for the time stated on the packet). Drain and divide between warmed plates. Scatter a little parmesan over the spaghetti before adding a good ladleful of the Bolognese sauce, finishing with a scattering of more cheese and a twist of black http://www.bbc.co.uk/food/recipes/spaghettibolognese_67868
  • 24. 2 tbsp olive oil or sun-dried tomato oil from the jar 1 tsp dried oregano or a small handful of 6 rashers of smoked streaky bacon, We would be very irritated if fresh leaves, chopped chopped there was an ingredient needed, 1 tsp dried thyme or a small handful of fresh leaves, chopped 2 large onions, chopped 3 garlic cloves, crushed that wasn’t included here. Drizzle balsamic vinegar 12-14 sun-dried tomato halves, in oil 1kg/2¼lb lean minced beef Salt and freshly ground black pepper 2 large glasses of red wine A good handful of fresh basil leaves, torn 2x400g cans chopped tomatoes into small pieces 1x290g jar antipasti marinated 800g-1kg/1¾-2¼lb dried spaghetti mushrooms, drained Lots of freshly grated parmesan, to serve 2 fresh or dried bay leaves Heat the oil in a large, heavy-based saucepan and fry the bacon until golden over a medium heat. Add the onions and garlic, frying until softened. Increase the heat and add the minced beef. Fry it until it has browned, breaking down any chunks of meat with a wooden spoon. Pour in the wine and boil until it has reduced in volume by about a third. Reduce the temperature and stir in the tomatoes, drained mushrooms, bay leaves, oregano, thyme and balsamic vinegar. 1. Either blitz the sun-dried tomatoes in a small blender with a little of the oil to loosen, or just finely chop before adding to the pan. Season well with salt and pepper. Cover with a lid and simmer the Bolognese sauce over a gentle heat for 1-1½ hours until it's rich and thickened, stirring occasionally. At the end of the cooking time, stir in the basil and add any extra seasoning if necessary. 2. Remove from the heat to 'settle' while you cook the spaghetti in plenty of boiling salted water (for the time stated on the packet). Drain and divide between warmed plates. Scatter a little parmesan over the spaghetti before adding a good ladleful of the Bolognese sauce, finishing with a scattering of more cheese and a twist of black http://www.bbc.co.uk/food/recipes/spaghettibolognese_67868
  • 25. 2 tbsp olive oil or sun-dried tomato oil from the jar 1 tsp dried oregano or a small handful of 6 rashers of smoked streaky bacon, We would be very irritated if fresh leaves, chopped chopped there was an ingredient needed, 1 tsp dried thyme or a small handful of fresh leaves, chopped 2 large onions, chopped 3 garlic cloves, crushed that wasn’t included here. Drizzle balsamic vinegar 12-14 sun-dried tomato halves, in oil 1kg/2¼lb lean minced beef Salt and freshly ground black pepper The units used to describe the amount 2 large glasses of red wine A good handful of fresh basil leaves, torn 2x400g cans chopped tomatoes of the ingredients varies according to 1x290g jar antipasti marinated into small pieces 800g-1kg/1¾-2¼lb dried spaghetti the culture of the person cooking. mushrooms, drained Lots of freshly grated parmesan, to serve 2 fresh or dried bay leaves Heat the oil in a large, heavy-based saucepan and fry the bacon until golden over a medium heat. Add the onions and garlic, frying until softened. Increase the heat and add the minced beef. Fry it until it has browned, breaking down any chunks of meat with a wooden spoon. Pour in the wine and boil until it has reduced in volume by about a third. Reduce the temperature and stir in the tomatoes, drained mushrooms, bay leaves, oregano, thyme and balsamic vinegar. 1. Either blitz the sun-dried tomatoes in a small blender with a little of the oil to loosen, or just finely chop before adding to the pan. Season well with salt and pepper. Cover with a lid and simmer the Bolognese sauce over a gentle heat for 1-1½ hours until it's rich and thickened, stirring occasionally. At the end of the cooking time, stir in the basil and add any extra seasoning if necessary. 2. Remove from the heat to 'settle' while you cook the spaghetti in plenty of boiling salted water (for the time stated on the packet). Drain and divide between warmed plates. Scatter a little parmesan over the spaghetti before adding a good ladleful of the Bolognese sauce, finishing with a scattering of more cheese and a twist of black http://www.bbc.co.uk/food/recipes/spaghettibolognese_67868
  • 26. 2 tbsp olive oil or sun-dried tomato oil from the jar 1 tsp dried oregano or a small handful of 6 rashers of smoked streaky bacon, We would be very irritated if fresh leaves, chopped chopped there was an ingredient needed, 1 tsp dried thyme or a small handful of fresh leaves, chopped 2 large onions, chopped 3 garlic cloves, crushed that wasn’t included here. Drizzle balsamic vinegar 12-14 sun-dried tomato halves, in oil 1kg/2¼lb lean minced beef Salt and freshly ground black pepper The units used to describe the amount 2 large glasses of red wine A good handful of fresh basil leaves, torn 2x400g cans chopped tomatoes of the ingredients varies according to 1x290g jar antipasti marinated into small pieces 800g-1kg/1¾-2¼lb dried spaghetti the culture of the person cooking. mushrooms, drained Lots of freshly grated parmesan, to serve 2 fresh or dried bay leaves Heat the oil in a large, heavy-based saucepan and fry the bacon until golden over a medium heat. Add the onions and garlic, frying until softened. Increase the heat and add the minced beef. Fry it until it has browned, breaking down any chunks of meat with a wooden spoon. Pour in the wine and boil until it has reduced in volume by about a third. Reduce the temperature and stir in the tomatoes, It’s easier to follow the directions when drained mushrooms, bay leaves, oregano, thyme and balsamic vinegar. 1. Either blitz the sun-dried tomatoes in a small blender with a little of the oil to loosen, or just finely chop before adding to the pan. Season well with salt and pepper. Cover with a lidof simmer the you don’t have to list the amounts and ingredients within the directions. Bolognese sauce over a gentle heat for 1-1½ hours until it's rich and thickened, stirring occasionally. At the end of the cooking time, stir in the basil and add any extra seasoning if necessary. 2. Remove from the heat to 'settle' while you cook the spaghetti in plenty of boiling salted water (for the time stated on the packet). Drain and divide between warmed plates. Scatter a little parmesan over the spaghetti before adding a good ladleful of the Bolognese sauce, finishing with a scattering of more cheese and a twist of black http://www.bbc.co.uk/food/recipes/spaghettibolognese_67868
  • 27. int x; int y; int width; int height; size(200, 200); x = 150; y = 100; width = 90; height = 80; ellipse(x, y, width, height);
  • 28. int x; int y; int width; ingredients or variables int height; size(200, 200); x = 150; y = 100; width = 90; height = 80; ellipse(x, y, width, height);
  • 29. int x; int y; int width; ingredients or variables int height; size(200, 200); x = 150; y = 100; directions or algorithm width = 90; height = 80; ellipse(x, y, width, height);
  • 30. data type int x; int y; int width; ingredients or variables int height; size(200, 200); x = 150; y = 100; directions or algorithm width = 90; height = 80; ellipse(x, y, width, height);
  • 31. data type variable name int x; int y; int width; ingredients or variables int height; size(200, 200); x = 150; y = 100; directions or algorithm width = 90; height = 80; ellipse(x, y, width, height);
  • 32. Cooking uses units of weight or volume, computers use bytes.
  • 33. Cooking uses units of weight or volume, computers use bytes. A bit is a 0 or a 1. 0 1
  • 34. Cooking uses units of weight or volume, computers use bytes. A bit is a 0 or a 1. 0 1 A byte is eight 0s or 1s.
  • 35. Cooking uses units of weight or volume, computers use bytes. A bit is a 0 or a 1. 0 1 A byte is eight 0s or 1s. 0s and 1s are used to represent things like numbers. It’s up to the programming language (and hardware) to determine what kinds of things 0s and 1s can represent.
  • 36. PRIMITIVE DATA TYPES (FOR BOTH PROCESSING AND ARDUINO UNLESS NOTED OTHERWISE) boolean is true or false boolean running = false; In Arduino, byte is an unsigned number (no negative numbers) can be 0 to 255, 8-bits (2^8) Arduino Only B is put in front to indicate numbers are binary byte b = B10010; In Processing, byte is a number can be 127 to -128, 8-bits (2^8) Processing Only byte b = -125;
  • 37. PRIMITIVE DATA TYPES (FOR BOTH PROCESSING AND ARDUINO UNLESS NOTED OTHERWISE) int is an integer ranging from -32,768 to 32,767 int i = 23456; long is a large integer ranging from -2,147,483,648 to 2,147,483,647 long g = 1239382345L;
  • 38. PRIMITIVE DATA TYPES (FOR BOTH PROCESSING AND ARDUINO UNLESS NOTED OTHERWISE) float is a number with a decimal point ranging from -3.40282347E+38 to 3.40282347E+38 float f = -234.56; char is a single letter (or symbol like “.”) char myChar = 'A'; unsigned char is a number 0 to 255, it is better to use the byte data type instead unsigned char myChar = 240;
  • 39. PRIMITIVE DATA TYPES (FOR BOTH PROCESSING AND ARDUINO UNLESS NOTED OTHERWISE) word is the same as unsigned int is a number without a decimal point ranging from 0 to 65,535 (2^16) - 1) Arduino Only word w = 55424; unsigned int is a number without a decimal point ranging from 0 to 65,535 (2^16) - 1) unsigned int ui = 55424; unsigned long is a large integer ranging from 0 to 4,294,967,295 (2^32 - 1), so no negative numbers long g = 4239382345ul;
  • 40. RULES FOR NAMING VARIABLES
  • 41. RULES FOR NAMING VARIABLES $3%^ Don’t start with a character besides a letter
  • 42. RULES FOR NAMING VARIABLES $3%^ Don’t start with a character besides a letter abc123 Only use numbers and letters and “_”
  • 43. RULES FOR NAMING VARIABLES $3%^ Don’t start with a character besides a letter abc123 Only use numbers and letters and “_” if, for Can’t use words that hold meaning to the compiler
  • 44. RULES FOR NAMING VARIABLES $3%^ Don’t start with a character besides a letter abc123 Only use numbers and letters and “_” if, for Can’t use words that hold meaning to the compiler rectHeight Be descriptive
  • 45. RULES FOR NAMING VARIABLES $3%^ Don’t start with a character besides a letter abc123 Only use numbers and letters and “_” if, for Can’t use words that hold meaning to the compiler rectHeight Be descriptive aA Case is important
  • 46. EXERCISE In Processing, create a sketch which draws a green ellipse. Use the functions listed below. Look up these functions in the Processing documentation for more guidance. size(width, height) fill(value1, value2, value3) ellipse(x, y, width, height)
  • 47. DECLARATION VS INITIALISATION As in a recipe, ingredients need to be listed at the top so you know what to buy. In code, it’s so the compiler knows how much memory to reserve. This is called declaring.
  • 48. DECLARATION VS INITIALISATION As in a recipe, ingredients need to be listed at the top so you know what to buy. In code, it’s so the compiler knows how much memory to reserve. This is called declaring. int myInt; Reserve space for an int
  • 49. DECLARATION VS INITIALISATION As in a recipe, ingredients We don’t have to know need to be listed at the top what value will be stored in so you know what to buy. myInt right away. In code, it’s so the compiler We can choose a value knows how much memory to reserve. This is called later. This is called initialising. declaring. int myInt; Reserve space for an int
  • 50. DECLARATION VS INITIALISATION As in a recipe, ingredients We don’t have to know need to be listed at the top what value will be stored in so you know what to buy. myInt right away. In code, it’s so the compiler We can choose a value knows how much memory to reserve. This is called later. This is called initialising. declaring. int myInt; myInt = 15; Reserve space for Store the value 15 in the an int space reserved for myInt 15
  • 51. Need to declare before or at the same time as initialisation.
  • 52. Need to declare before or at the same time as initialisation. myInt = 3; int myInt;
  • 53. Need to declare before or at the same time as initialisation. myInt = 3; int myInt; int myInt; myInt = 3;
  • 54. Need to declare before or at the same time as initialisation. myInt = 3; int myInt; int myInt; myInt = 3; Can’t use a variable before it is initialised.
  • 55. Need to declare before or at the same time as initialisation. myInt = 3; int myInt; int myInt; myInt = 3; Can’t use a variable before it is initialised. int myInt; myInt = myInt + 7;
  • 56. Need to declare before or at the same time as initialisation. myInt = 3; int myInt; int myInt; myInt = 3; Can’t use a variable before it is initialised. int myInt; int myInt = 3; myInt = myInt + 7; myInt = myInt + 7;
  • 57. TO CREATE A VARIABLE 1. Decide what the data type should be. Usually the main decisions are between int, float and char. float int char
  • 58. TO CREATE A VARIABLE 1. Decide what the data type should be. Usually the main decisions are between int, float and char. to create a float type float int char
  • 59. TO CREATE A VARIABLE 1. Decide what the data type should be. Usually the main decisions are between int, float and char. to create a float type float to create an int type int char
  • 60. TO CREATE A VARIABLE 1. Decide what the data type should be. Usually the main decisions are between int, float and char. to create a float type float to create an int type int to create a char type char
  • 61. TO CREATE A VARIABLE 1. Decide what the data type should be. Usually the main decisions are between int, float and char. to create a float type float to create an int type int to create a char type char 2. Decide on a name for your variable. Remember the rules.
  • 62. TO CREATE A VARIABLE 1. Decide what the data type should be. Usually the main decisions are between int, float and char. to create a float type float to create an int type int to create a char type char 2. Decide on a name for your variable. Remember the rules. float scale; int redValue; char finalMark;
  • 63. TO CREATE A VARIABLE 1. Decide what the data type should be. Usually the main decisions are between int, float and char. to create a float type float to create an int type int to create a char type char 2. Decide on a name for your variable. Remember the rules. float scale; you get to choose int redValue; the name char finalMark;
  • 64. TO CREATE A VARIABLE 1. Decide what the data type should be. Usually the main decisions are between int, float and char. to create a float type float to create an int type int to create a char type char 2. Decide on a name for your variable. Remember the rules. float scale; you get to choose int redValue; the name char finalMark; 3. If you already know what the value of that variable is, then go ahead and set the value.
  • 65. TO CREATE A VARIABLE 1. Decide what the data type should be. Usually the main decisions are between int, float and char. to create a float type float to create an int type int to create a char type char 2. Decide on a name for your variable. Remember the rules. float scale; you get to choose int redValue; the name char finalMark; 3. If you already know what the value of that variable is, then go ahead and set the value. float scale = 0.5; int redValue = 199; char finalMark = ‘B’;
  • 66. TO CREATE A VARIABLE 1. Decide what the data type should be. Usually the main decisions are between int, float and char. to create a float type float to create an int type int to create a char type char 2. Decide on a name for your variable. Remember the rules. float scale; you get to choose int redValue; the name char finalMark; 3. If you already know what the value of that variable is, then go ahead and set the value. if you don’t know the float scale = 0.5; value yet, stop at step 2. int redValue = 199; but remember to end char finalMark = ‘B’; each line with a ;
  • 67. EXERCISE In Processing, return to your sketch which draws a green ellipse. Replace the numbers you’ve used as arguments in the fill( ) and ellipse( ) functions with variables. What kind of datatypes do you need to use? What are good descriptive names for those variables?