Presentation is loading. Please wait.

Presentation is loading. Please wait.

Flii Programming Workshop Marissa Milne Science Communication Officer.

Similar presentations


Presentation on theme: "Flii Programming Workshop Marissa Milne Science Communication Officer."— Presentation transcript:

1

2 Flii Programming Workshop Marissa Milne Science Communication Officer

3 Overview *.X Project MPLAB X ICD 3 Docking Station PIC Microcontroller LEDs LCD Screen Switches

4 The Wiki Download Flii Source V2.0 Open the ZIP file drag the folder inside it onto the Desktop Open Flii Library V2.0 Function Descriptions

5 MPLAB X Open MPLABX IDE Go to File  Open Project Find Flii Hex and open it Under Project, expand the Source Files and open Functions.c

6 Things To Remember Case sensitivity –MyVariable is not the same as myvariable Underlined things = syntax errors –Using the wrong variable name –Using the wrong function Check if you’re using BufferWriteString(…) or BufferWriteMessage(…) –Missing brackets, semi-colons, etc

7 Programming the Flash Screen Find the WriteFlashScreen() function and work out what is happening! What is WriteBufferToScreen() doing? –A buffer temporarily holds data before it is processed. –Here, we put the information for the graphic into a buffer in the memory of the PIC chip first, then the buffer is written to screen.

8 Task: Show a welcome message between the flash screen and the menu display Programming the Flash Screen

9 Task: Add a graphic to our welcome screen Step 1: Design your graphic! –Use your grid to design a simple image –Make sure it won’t overlap your text Step 2: Turn your graphic into code –Use BufferWritePixel(x,y,PIXEL_ON); –Only write code for the pixels you want to turn on –Hint #1: Copy, paste & adjust! –Hint #2: Group the code for each line by leaving a blank line in between Challenge: Can you create a short animation?

10 Difficulty Levels in Pong Open Pong.c and inspect it – what’s happening? –Starts with EASY difficulty and a score of 0 –PongInit() is called first, sets the game up –UpdatePongGameState() is called every 20ms This is where the action happens! Update line 27 so your game starts at EASY difficulty: unsigned char PONG_DIFFICULTY = EASY_DIFFICULTY; Find line 249. Add an instruction so your game reverts to easy difficulty when it resets.

11 Task: Modify the program so that it increases in difficulty when a certain score is reached At the top of UpdatePongGameState() use an if statement to check the score. Increase difficulty level if needed. if(SCORE >= ??? && PONG_DIFFICULTY != NORMAL_DIFFICULTY){ // set difficulty level PONG_DIFFICULTY = NORMAL_DIFFICULTY; // initialise new level PongInit() } Difficulty Levels in Pong

12 Task: Modify the program so that the LED lights flash when a new difficulty level is reached Step 1: If you add LED function calls to Pong.c you will see an error about particular variables being undefined. To fix this: Add an extra #include line at the top of Pong.c: #include "Board_defs.h" Difficulty Levels in Pong

13 Task: Modify the program so that the LED lights flash when a new difficulty level is reached Modify your existing if statement to include LED instructions: if(SCORE >= 5 && PONG_DIFFICULTY != NORMAL_DIFFICULTY){ // set difficulty level PONG_DIFFICULTY = NORMAL_DIFFICULTY; //level up! LED1On(); LED2On(); DelayMs(500); LED1Off(); LED2Off(); //initialise new level PongInit(); } Difficulty Levels in Pong

14 Challenge: Modify your game so it progresses from EASY  NORMAL  HARD modes Challenge: Modify your level up behaviour so it shows a message and/or graphic on screen Challenge: What can change to make pong more difficult? –Ball speed (modify ball_Xvel and ball_Yvel) –Paddle speed (modify SENSITIVITY_EASY, etc in Pong.h) –Paddle size (modify right_paddle_sections) –Ball size (modify BufferWriteBall(char x, char y)) Hint #1: Change ONE thing at a time then TEST it! Hint #2: Use if statements to match changes with levels Difficulty Levels in Pong

15


Download ppt "Flii Programming Workshop Marissa Milne Science Communication Officer."

Similar presentations


Ads by Google