Joypad-Game-Snake
From Microduino Wiki
ContentsOutlineWe adopt Microduino-Joypad-Game to play the game of Snake. Bill of Material
DownloadTFT library:https://github.com/Microduino/Microduino_Tutorials/tree/master/Microduino_Libraries/_01_Microduino_TFT_ST7735 Joypad lib.:https://github.com/Microduino/Microduino_Tutorials/tree/master/Microduino_Libraries/_08_Microduino_Shield_Joypad Code: Microduino_JoyPad_Game Debuging
if(Joypad.readButton(CH_SWITCH_R))
{
if(Joypad.readButton(CH_SWITCH_2)==0)
Joy=3;
else if(Joypad.readButton(CH_SWITCH_4)==0)
Joy=2;
if(Joypad.readButton(CH_SWITCH_1)==0)
Joy=1;
else if(Joypad.readButton(CH_SWITCH_3)==0)
Joy=4;
else if(Joypad.readButton(CH_SWITCH_1)==1&&Joypad.readButton(CH_SWITCH_2)==1&&Joypad.readButton(CH_SWITCH_3)==1&&Joypad.readButton(CH_SWITCH_4)==1)
Joy=0;
}
else
{
if(x>280||x1>280)
Joy=2;//
else if(x<-280||x1<-280)
Joy=3;//
else if(y<-280||y1<-280)
Joy=1;
else if(y>280||y1>280)
Joy=4;
else
Joy=0;
} Button control is the default setting by turning the right switches to the top. Users can change the way of switch.
Joypad.motor(0);//Close
Joypad.motor(X);//0-255 The vibration is adjustable.
Step 5: Compile the code and select the right board and COM port for download after successful compiling.
|