mid term review

22
Mid Term Review

Upload: vadin

Post on 06-Jan-2016

30 views

Category:

Documents


0 download

DESCRIPTION

Mid Term Review. Voltage. Voltage is a measure of the electrical energy of a circuit. It is measured in Volts . The quality of energy. Current. Current is a measure of the magnitude of the flow of electrons in a circuit. It is measured in Amperes, or Amps . How much energy is Available. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Mid Term  Review

Mid Term Review

Page 2: Mid Term  Review

Voltage

• Voltage is a measure of the electrical energy of a circuit. It is measured in Volts. The quality of energy

Page 3: Mid Term  Review

Current

• Current is a measure of the magnitude of the flow of electrons in a circuit. It is measured in Amperes, or Amps. How much energy is Available.

Page 4: Mid Term  Review

Resistors

• The resistor can be defined by it's main purpose, a device to control or limit the flow of current, hence we can say that the main parameter of a resistor is it's resistance, which is measured in Ohm's .

• they can also be used as voltage dividers to generate very precise voltages out of bigger voltages.

Page 5: Mid Term  Review

OHM’s Law

• V = voltage• I = current• R = resistance

• Ohm’s law shows how V, I and R are related

Page 6: Mid Term  Review

Parallel vs. series

• parallel • series

Page 7: Mid Term  Review

Program Structure

• Two required functions in an Arduino sketch, setup() and loop().

• setup() The function is called when your program starts. Use it to initialize your variables, pin modes, start using libraries, etc. The setup function will only run once, after each powerup or reset of the Arduino board.

• 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.

Page 8: Mid Term  Review

Variables

• Let you store a value. • Must declare variables and tell computer

what kind of value to expect.

3 types we use most:Byte, Character, Integer

Page 9: Mid Term  Review

Binary Numbering (how computers count)

If computers only know 1 and 0 how do they form complex operations?

• 128 64 32 16 8 4 2 1• 00000001 = 1• 00000010 = 2• 00000011= 3• 00000100 = 4

Page 10: Mid Term  Review

digitalRead(pin)

• Reads the value from a specified pin, it will be either HIGH or LOW.

• pin: the number of the digital pin you want to read.

• Returns either HIGH or LOW

Page 11: Mid Term  Review

Digital Input

Page 12: Mid Term  Review

Pull down resistor

• you need the connection to ground as a reference point in digital inputs. Ensures the microcontroller “sees” ) volts when not receiving an input voltage.

Page 13: Mid Term  Review

If statement

• A conditional which is used in conjunction with a comparison operator, tests whether a certain condition has been reached, such as an input being above a certain number. The format for an if test is:

if (someVariable > 50){ // do something here}

Page 14: Mid Term  Review

If…..else

if (pinInput < 500){ // action A}else{ // action B}

Page 15: Mid Term  Review

Inverted logic

• For the data transmission above, a high voltage indicates a bit value of 1, and a low voltage indicates a voltage of 0. This is known as true logic.

• Many serial protocols use inverted logic, meaning that a nigh voltage indicates a logic 0, and a low voltage indicates a logic 1. It’s important to know whether your protocol is true or inverted.

Page 16: Mid Term  Review

• synchronous serial communication: both devices share a clock.

• asynchronous serial communication: instead, both devices have their own clock and agree on a rate to which to set their clocks. Easier to implement.

Page 17: Mid Term  Review

PWMIn the graph below, we pulse our pin high for the same length of time we pulse it low. The time the pin is high (called the pulsewidth) is about half the total time it takes to go from low to high to low again. This ratio is called the duty cycle. The duty cycle is 50%,and the average voltage is about half the total voltage.

Page 18: Mid Term  Review

If we make the duty cycle less than 50% by pulsing for a shorter amount of time than we pause, we get a lower effective voltage: The pulsewidth is usually a very small time, on the order of a few microseconds or milliseconds at most.

Page 19: Mid Term  Review

Mini review:Functions to know

• pinMode(pin, mode)

• digitalWrite(pin, value)

• digitalRead(pin)

• analogRead(pin)

Page 20: Mid Term  Review

Reading Code• Given the sample code below what would I change if I wanted to make pin 12 go ON for half a second

and OFF for 2 seconds?• int ledPin = 13; • • void setup() • {• pinMode(ledPin, OUTPUT); • }• • void loop() • {• digitalWrite(ledPin, HIGH); • delay(1000); • digitalWrite(ledPin, LOW); • delay(1000); • }•

Page 21: Mid Term  Review

What does this code do?

• • int ledPin = 13; • int inPin = 2;• int val = 0; • • void setup() {• pinMode(ledPin, OUTPUT); • pinMode(inPin, INPUT); • }• • void loop(){• val = digitalRead(inPin); • if (val == HIGH) { • digitalWrite(ledPin, HIGH); • } else {• digitalWrite(ledPin, LOW); • }• }

Page 22: Mid Term  Review

What does this code do?• int potVar = 2;• • void setup() {• Serial.begin(9600);• pinMode(11, OUTPUT);• }• • void loop() {• • potVar = analogRead(0);• Serial.println(potVar, DEC);• • delay(10);• }