1 / 22

Mid Term Review

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.

vadin
Télécharger la présentation

Mid Term Review

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Mid Term Review

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

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

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

  5. OHM’s Law • V = voltage • I = current • R = resistance • Ohm’s law shows how V, I and R are related

  6. Parallel vs. series • parallel • series

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

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

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

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

  11. Digital Input

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

  13. 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 }

  14. If…..else if (pinInput < 500) { // action A } else { // action B }

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

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

  17. PWM In 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.

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

  19. Mini review:Functions to know • pinMode(pin, mode) • digitalWrite(pin, value) • digitalRead(pin) • analogRead(pin)

  20. 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); • }

  21. 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); • } • }

  22. 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); • }

More Related