Skip to content

Files

Latest commit

b3d2038 · Oct 4, 2024

History

History
105 lines (78 loc) · 6.05 KB

File metadata and controls

105 lines (78 loc) · 6.05 KB

T2: Homework

Before you start working on your homework, remember to declare the function prototype first, please refer to the classwork instruction if you dun understand what I mean.

Q1: GPIO Configuration + Line Following Sensor Module (2)

Actually this originally is the third classwork but I doubt if I can go thru all the things so I make it as homework to make both u and my life easier.

While we oroinigally designed a simplifed ELEC 1100 Line follower, we are now simpily it and you can take a look of the original one here:

Original Homework , No Need to Do now So while we have covered you with the Pneumatic Valve as an usage of external GPIO, we designed this homework to introduce you about Line Following Sensor. Line Following Sensors commonly have two 'bulb', one to emit infrared rays (so I may say that is an IR Sensor) and another one used to received how many rays have been reflected to recognize black and white surface.

In your RDC, one of the robot you need to make would to fully auto to get something and then come back, and for the ease of you guys, we have draw lines to guide you from the starting point towards the end. Thus this task is give you a very very very brief idea how can you utilize the line.

In the board for this homework, you should find two Line Following Sensor connected in PA15 and PB15 respectively, and denote PA15 as Left Sensor and PB15 as Right Sensor. In this Homework, you are suppose to simulate a Line Following Robot with only 2 sensors. The requirement are as follow:

  • When both of your Line Following Sensor detect white, print Go Straight!!! (1)
  • When the Left Sensor detect black, print Turn Left (1)
  • When the Right Sensor detect black, print Turn Right (1)
  • When both Sensor detect black, print Stop! (1)

Please ask Seniors for board for this task specifically as we don't have enough Line Following Sensor right now. And if you don't have the Black Line with you, just use your hand the block the 'bulb' of the sensors.

Since we don't have enough Line Following Sensor, some of you might receive limit switches(it works like a button). We will treat Limit switch pressed = Line Following sensor detect black

As the objective of this homework is to give you a try on setting up new GPIO Pins, therefore now you are required to set up a GPIO on the targeted pin that pluged in a limit switch (Please ask senior if you cannot understand what pin it is)

And you should print Input Detected when the switch is pressed and print nothing when it is not pressed.

You may refer to the last notes about how to set up GPIO Pins, keep in mind that the example there is setting up GPIO Output while here you are doing GPIO_Input

Notes for Setting up Pins:

  • Please plug the limit switch to those pins on the right hand side instead of left hand side.
  • Although you may see PC6, PC7, PC8, PC9 are occiuped by CAM, but as we don't have embed camera this year, you can use them for other purpose, e.g. finish homework
    To remove a pins, you can do by simpily do like this
    1. Click the pins you want to remove, click the current functionality the pins is using:
    2. After you remove the current functionality, the pins should go grey like this:
    3. You can choose the functionality of this pins now:
    4. Follow the pins setup manual!
  • For the input mode, you should set it as "PULL-UP" instead of the "No Pull Up No Pull Down", you can change it in the panel where you name your pin in the CubeMX and also your are using GPIO Input instead of GPIO Output
    If you want to know more what is PULL UP, you can take a look to the further readong in 05-Setting-UP-GPIO.md
  • Correct Pin Naming Picture:

Q2: Tutorial 2 Homework

Before you start doing homework, You may find these defines in lcd.h useful:

#define CHAR_WIDTH 8
#define CHAR_HEIGHT 16

#define MAX_WIDTH 128
#define MAX_HEIGHT 160

#define CHAR_MAX_X_VERTICAL 16
#define CHAR_MAX_Y_VERTICAL 10

#define CHAR_MAX_X_HORIZONTAL 20
#define CHAR_MAX_Y_HORIZONTAL 8

#define CHAR_MAX_X 20  // max between CHAR_MAX_X_VERTICAL and CHAR_MAX_X_HORIZONTAL
#define CHAR_MAX_Y 10  // max between CHAR_MAX_Y_VERTICAL and CHAR_MAX_Y_HORIZONTAL

Edge Triggering vs Level Triggering

Consider 2 uses for a single button: (choose BTN1 or BTN2)

Q1 Level Triggering

  • While the button is down, print Hello, (Your name) on TFT (@1)
  • While it is not, flash the LED (at least one LED). (@1)
  • Two actions should not happen simultaneously.
  • Hints:
    • In this case every time the loop comes around, we are concerned with the current state (or level) of the buttons GPIO Pin
    • The implementation of the button reading here should be obvious and simple

Notice the green button and the green LED

Q2 Edge Triggering

  • We want to print Hello, (Your name) for 1 second when the button is pressed, but only once for each press, so holding the button does nothing more. (@1)
  • When the button is released, we want to flash the LED for 1 second, but again only once for each release. (@1)
  • The process repeats. i.e. it will print text again if you click the button. (@1)
  • Keywords:
    • The event of a signal going from low to high is called the rising edge and the opposite is the falling edge
    • The gpio_read() macro gives us the current state, but edge triggering also requires knowledge of the past state as well as some logic
  • Hints: How can we design some code that can call a function only when the button is first clicked? (Rising edge)

Bonus

  • Create a sprite in the middle of the screen. (Can be in any shape other than simple rectangle) (@1)
  • It will move to the left for one CHAR_WIDTH when BTN1 is clicked and released,
  • move to the right for one CHAR_WIDTH when BTN2 is clicked and released. (@2 for both short press)