Question
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
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 }
} }
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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started