Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I have the following code in C for a project for an arduino nano, at this point, this code displays a pacman eating letther in

I have the following code in C for a project for an arduino nano, at this point, this code displays a pacman eating letther in an specifc direction, for the first row it goes to the right and for the second it goes to the left.

#asm .equ __lcd_port=0x0B .equ __lcd_EN=3 .equ __lcd_RS=2 .equ __lcd_D4=4 .equ __lcd_D5=5 .equ __lcd_D6=6 .equ __lcd_D7=7 #endasm

#include #include #include #include

unsigned char PacMan1[8]={0x0E,0x1D,0x1E,0x1C,0x1E,0x1F,0x0E,0x00}; unsigned char PacMan2[8]={0x0E,0x1D,0x1F,0x1E,0x1F,0x1F,0x0E,0x00}; unsigned char PacMan3[8]={0x0C,0x16,0x1F,0x0F,0x1F,0x1F,0x0E,0x00}; unsigned char PacMan4[8]={0x0C,0x16,0x0F,0x07,0x0F,0x1F,0x0E,0x00};

signed char i;

void delayPacMan() { delay_ms(200); }

void main(void) { CLKPR=0x80; CLKPR=0x04; //Arduino Nano works at 1MHz SetupLCD(); CreateChar(0,PacMan1); //Pacman animation that goes to the right CreateChar(1,PacMan2); //Pacman animation that goes to the right CreateChar(2,PacMan3); //Pacman animation that goes to the left CreateChar(3,PacMan4); //Pacman animation that goes to the left while (1) { MoveCursor(5,0); StringLCD("Hello"); MoveCursor(3,1); StringLCD("Mr. PacMan"); for (i=0;i=0;i--) { MoveCursor(i,1); //P1 CharLCD(2); //P2 delayPacMan(); MoveCursor(i,1); //P3 CharLCD(3); //P4 delayPacMan(); MoveCursor(i,1); //P5 CharLCD(' '); //P6 }

} } image text in transcribed

image text in transcribed

But now I want that when I press th switch, the pacman changes direction whenever I press it. How can I do that?

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Driven Web Sites

Authors: Joline Morrison, Mike Morrison

2nd Edition

? 061906448X, 978-0619064488

More Books

Students also viewed these Databases questions

Question

Identify three types of physicians and their roles in health care.

Answered: 1 week ago

Question

Compare the types of managed care organizations (MCOs).

Answered: 1 week ago