Presentation is loading. Please wait.

Presentation is loading. Please wait.

Intro to Programming and Microcontrollers. Activity Group into pairs and sit back-to-back. Pick one person who is going to draw. The other person will.

Similar presentations


Presentation on theme: "Intro to Programming and Microcontrollers. Activity Group into pairs and sit back-to-back. Pick one person who is going to draw. The other person will."— Presentation transcript:

1 Intro to Programming and Microcontrollers

2 Activity Group into pairs and sit back-to-back. Pick one person who is going to draw. The other person will describe any object to the drawer only using geometrical terms. – Demo

3 Recap Instructions need to be specific. A computer does everything you tell it to, but only what you tell it to do.

4 Computer Programming 101 Computer programs are written in a language that a computer can understand. – I have five apples. – apples = 5; You can also use mathematical operators with computers. – I have 10 total pieces of fruit, 6 apples, and 4 oranges. apples = 6; oranges = 4; fruit = apples + oranges; There are rules in both language and programming that must be followed in order to be understood. Computers take everything literally.

5 Arduinos

6 Turn on an LED int ledPin = 13; // LED connected to digital // pin 13 void setup() { // initialize the digital pin as an output: pinMode(ledPin, OUTPUT); } // the loop() function runs over and over again, // as long as the Arduino has power void loop() { digitalWrite(ledPin, HIGH); // set the LED on } 1.Define all of your variables – Later, when we write ‘ledPin’, we really mean 13. – 13 is an integer, so we have to tell the computer “int” 2.Use the setup function – Have to write “void” before it, because the Arduino doesn’t send a message back to us after it completes the task – Define WHICH pin we will use – SEND INFORMATION = OUTPUT 3.Put the instructions inside a loop, so the computer repeats 4.Tell the LED to turn on – use function digitalWrite – set the pin (which pin??) to HIGH

7 Grammar - What did you notice? Each statement ends in a semicolon – int ledPin = 13; If a statement starts with ‘//’, the computer program won’t notice it! – // set the LED on – Comments are used in programs to explain what it does – in English Each FUNCTION has brackets around it { } loop() { digitalWrite(ledPin, HIGH); // set the LED on }

8 Key Functions setup() The setup() function is called when a sketch starts. Use it to initialize variables, pin modes, start using libraries, etc. The setup function will only run once, after each powerup or reset of the Arduino board. Example: int buttonPin = 3; int ledPin = 13; void setup() { pinMode(buttonPin, INPUT); pinMode(ledPin,OUTPUT); }

9 Key Functions loop() – After creating a setup() function, which initializes and sets the initial values, the loop() function does precisely what its name suggests, and loops consecutively, allowing your program to change and respond. Use it to actively control the Arduino board. delay(number_of_ms) – Pauses for the amount of time specified. Example: loop(){ digitalWrite(ledPin,HIGH); delay(1000); digitalWrite(ledPin,LOW); delay(1000); }

10 Practice Design a stoplight controller that will sequentially turn on 3 LEDs (Green, Yellow, Red). Choose appropriate delays so that the lights are each on for the proper portion of time during the cycle. Remember to connect the LEDs through a resistor (250 – 1000 Ω) from the output pin to ground.


Download ppt "Intro to Programming and Microcontrollers. Activity Group into pairs and sit back-to-back. Pick one person who is going to draw. The other person will."

Similar presentations


Ads by Google