Lab 1: Space Invaders The Introduction
Welcome to Lab! Feel free to get started until we start talking! The lab document is located on course website: https://users.wpi.edu/~sjarvis/ece2049_smj/ Be sure your lab board has the 4 LED jumpers (i.e. the 4 multicolored LEDs worked in Lab 0 Ask a member of the course staff if not We will come around checking your pre-labs after we introduce the lab. BOTH lab partners need to submit THEIR OWN Prelab If you didn't have a partner for Lab 0 you probably will want one for this lab Let us know if you have any questions!
Space Invaders Basic requirements: Aliens falling from screen Press numbered keys to kill them Multiple levels, increasing difficulty, etc. YOU HAVE ALL THE I/O FUNCTIONS YOU NEED IN THE DEMO PROJECT You simply need to write a new main() You can make this as complex as you want Have fun with it!
The Important Parts A data structure to store the aliens Arrays, 2D arrays, structs you decide! You may NOT hard-code the positions of the aliens with lots of if statements! (Why is this bad?) Support for making the aliens fall down the screen, while being able to press a button to kill them You can t use a software delay for this, why? It's better to enter a Polling Loop and check for key presses a certain number of times (like ~10000 times) Think about how you will do this during lab today ask us if you need help!
How to start a new lab You should start each lab with a fresh copy of the template demo project (Instructions follow) If you started with a blank workspace, import the template again using the menus: Project Menu > Importing Existing CCS Project Select Archive File and then select the template project
Starting a new project 1. Copy your project Right-click on the project 1. (Opens the Project Menu ) 2. Select Copy
Starting a new project (cont d.) 2. Paste! 1. Open the Project Menu again 2. Select Paste 3. Enter a new project name 4. Click OK. This will create a new project called lab 1 for you to use!
Clearing out the demo project You can clear out all of the code from lab 0, except the following code // Don t remove any #include statements void main(void) { WDCTL = WDTPW WDTHOLD; // Stop watchdog timer // Useful code starts here initleds(); configdisplay(); configkeypad(); // Your setup code goes here! // (Initialize variables, configure things, etc.) } while(1) { // Your code goes here! } Note: This is the bare minimum. You should refer back to Lab 0 for examples of how to use the display, LEDs, keypad, etc. (Read the comments!)
How to start Don t try to write the whole lab at once! Instead, build small parts and test them Focus on The Important Parts today (Which you started thinking about for your pre-lab, right?) How to make aliens fall from the screen and using the keys to kill them You may want to use a state machine for this How to represent the aliens Review your pre-lab with your partner and decide how to proceed Feel free to ask us questions, too!
Code Smarter, Not Harder A big part of this lab is learning how to use control flow effectively This means how you use if and switch-case statements, for and while loops, etc. Spend time thinking about HOW to structure your code This kitty is frustrated by poor control flow. Good control flow makes your code easy to debug. This will save you time!
Code Smarter, Not Harder If you find yourself using any of the following Lots of nested loops or if statements (> 3 is probably bad practice) Copy/pasting blocks of code and changing it slightly Code that gets stuck in certain places Lots of global variables that modify your program s state you should rethink your control flow: Feel free to ask us for help on HOW to approach a problem It is MUCH easier for everyone if you ask for help here, rather than trying to debug your code later!
Example state machine The program looks at the variable state on each iteration of the while loop Before leaving each state, we define the next state At the end of a state, the loop restarts and we enter the next state (This code waits until dothing() returns 0, without using a separate while loop!) Bonus Questions What happens if you miss a break statement? Why should state NOT be global?
When things don t work try to use the debugger to help you! How far does your program get when it stops working? Does it ever reach state X? Set a break-point at the start of a state Does it make certain decisions correctly? Set breakpoints at critical if statements, etc. Examine variables (watch/expressions windows) to see if information is what you expect Debugging is an important skill. Try to narrow down the problem on your own, but feel free to ask for help!
Saving your work All of your work is saved on your network drive Log into any lab machine to access your workspace and projects If you want to save a copy of your code, see the instructions to save as a zip file Good for making a backup copy or to send to your partner!
Saving your work Please do NOT use the following methods to save your work: Directly copying files (You will miss settings files) Pasting code into an email, Word, or Google doc (super gross) Snapchat (No.) A public Github repository (Other people will steal it!)
Submitting your code online When you submit your lab report, you will also submit your code on Canvas for grading See instructions in Lab document Do not forget this step, or you won t get graded! Only one submission per team is required Be SURE to follow ALL of the instructions or it makes grading difficult for us
Good luck and have fun! Feel free to ask us if you have questions we re here to help! These slides will be posted for you to view later See instructions for submitting your code when you are done with the lab! Be sure to look at the Frequently Asked Questions! Thank you for listening!
How to submit your code 1. RENAME your CCS project You MUST do this to submit your code online! You MUST do this from CCS! (Renaming just the project folder won t work!) 1. Open the Project Menu again You re not done renaming yet see the next slide! 2. Select Rename
Naming your project for submission To submit online, you project must have a name in this format: ece2049a17_lab1_username1_username2 Fill in the USERNAMES of you and your partner NOT your full name NOT your nickname Failure to do this properly may cause problems when grading!
Exporting your Lab These steps will create an archive (a zip file) of your whole CCS project This is useful for submitting your code or creating a backup copy of your project 1. Open the Project Menu 2. Select Export
Exporting your Lab 1. Select Archive File 2. Click Next
Exporting your Lab Your project and all its files should already be checked 2. Click Finish This creates the zip file, which you can upload to Canvas 1. Click Browse and find a location to save your file. Give the zip file THE SAME NAME as your project.
Frequently Asked Questions (1/?) Help! I lost a window in CCS! Reset all of your windows to defaults, go to : View > Reset Perspective I have the warning Function declared implicitly Make sure you aren t missing any #include statements (rand() is in stdlib.h) If the warning is for one of your own functions, you are missing a function prototype. Google function prototypes for help!
Frequently Asked Questions I have a vague error saying Errors exist in project or Errors encountered during linking Look in the Console for the full output during compilation. If you scroll up a few lines, you may see some more information about the error. See the next slide for more info
Frequently Asked Questions Why does this variable have a value of.? This is because CCS is trying to show it as an ASCII character, but it has a value that isn t a character. You can change the format like this: Right click on the variable here Pick a format to display it here
Frequently Asked Questions Using the graphics library See lab 0 for examples especially the comments You can draw lines and shapes See the Graphics Library User Guide on the course website for examples You can also draw bitmaps (pixel art) Some examples are on the local machine at: C:\ti\ccsv5\ccs_base\msp430\msp430ware_1_40_00_26\examples\grlib\MSP- EXP430F5529_Grlib_Example\images We use a black and which screen, so all images should use 1bit/pixel resolution This is an advanced topic. If you want to do it, you re on your own.