Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
Fork of Project_PokPakGame by
main.cpp
- Committer:
- lolopo008
- Date:
- 2015-12-05
- Revision:
- 4:3605c624b64f
- Parent:
- 3:054a677aca64
- Child:
- 5:7041c827932b
File content as of revision 4:3605c624b64f:
#include "mbed.h" #include "time.h" SPI DataPack(SPI_MOSI, SPI_MISO, SPI_SCK); DigitalOut Latch(D10); AnalogIn VR0(A0); AnalogIn VR1(A1); AnalogIn ran(A2); DigitalIn UnderButton(D7); DigitalIn UpperButton(D6); float VR_value0,VR_value1; int Base[6][3][3]= { //[6]=[0]_base1,[1]_base2,[2]_base3,[3]_base4,[4]_base5,[5]_base6 //[3]=[0]_red,[1]_yello,[2]_green {{0x1F,0xFF,0xFF},{0x1F,0x1F,0xFF},{0xFF,0x1F,0xFF}} , {{0x8F,0xFF,0xFF},{0x8F,0x8F,0xFF},{0xFF,0x8F,0xFF}} , {{0xC7,0xFF,0xFF},{0xC7,0xC7,0xFF},{0xFF,0xC7,0xFF}} , {{0xE3,0xFF,0xFF},{0xE3,0xE3,0xFF},{0xFF,0xE3,0xFF}} , {{0xF1,0xFF,0xFF},{0xF1,0xF1,0xFF},{0xFF,0xF1,0xFF}} , {{0xF8,0xFF,0xFF},{0xF8,0xF8,0xFF},{0xFF,0xF8,0xFF}} }; int Row[8]= {1,2,4,8,16,32,64,128}; int Col[8]= {127,191,223,239,247,251,253,254}; int x,y,up,down,t,way,c; void Count() { //3 for(c=0; c<3000; c++) { Latch=0; DataPack.write(0xFF); wait_us(1); DataPack.write(0x1F); wait_us(1); DataPack.write(0x1F); wait_us(1); DataPack.write(0x40); wait_us(1); Latch=1; Latch=0; DataPack.write(0xFF); wait_us(1); DataPack.write(0x78); wait_us(1); DataPack.write(0x78); wait_us(1); DataPack.write(0x28); wait_us(1); Latch=1; Latch=0; DataPack.write(0xFF); wait_us(1); DataPack.write(0x1E); wait_us(1); DataPack.write(0x1E); wait_us(1); DataPack.write(0x14); wait_us(1); Latch=1; Latch=0; DataPack.write(0xFF); wait_us(1); DataPack.write(0xF8); wait_us(1); DataPack.write(0xF8); wait_us(1); DataPack.write(0x02); wait_us(1); Latch=1; } //2 for(c=0; c<2200; c++) { Latch=0; DataPack.write(0xFF); wait_us(1); DataPack.write(0x1F); wait_us(1); DataPack.write(0x1F); wait_us(1); DataPack.write(0x40); wait_us(1); Latch=1; Latch=0; DataPack.write(0xFF); wait_us(1); DataPack.write(0xD8); wait_us(1); DataPack.write(0xD8); wait_us(1); DataPack.write(0x20); wait_us(1); Latch=1; Latch=0; DataPack.write(0xFF); wait_us(1); DataPack.write(0x1E); wait_us(1); DataPack.write(0x1E); wait_us(1); DataPack.write(0x10); wait_us(1); Latch=1; Latch=0; DataPack.write(0xFF); wait_us(1); DataPack.write(0x78); wait_us(1); DataPack.write(0x78); wait_us(1); DataPack.write(0x08); wait_us(1); Latch=1; Latch=0; DataPack.write(0xFF); wait_us(1); DataPack.write(0x1B); wait_us(1); DataPack.write(0x1B); wait_us(1); DataPack.write(0x04); wait_us(1); Latch=1; Latch=0; DataPack.write(0xFF); wait_us(1); DataPack.write(0xF8); wait_us(1); DataPack.write(0xF8); wait_us(1); DataPack.write(0x02); wait_us(1); Latch=1; } //1 for(c=0; c<4000; c++) { Latch=0; DataPack.write(0xFF); wait_us(1); DataPack.write(0xBF); wait_us(1); DataPack.write(0xBF); wait_us(1); DataPack.write(0x40); wait_us(1); Latch=1; Latch=0; DataPack.write(0xFF); wait_us(1); DataPack.write(0xBD); wait_us(1); DataPack.write(0xBD); wait_us(1); DataPack.write(0x3C); wait_us(1); Latch=1; Latch=0; DataPack.write(0xFF); wait_us(1); DataPack.write(0xFD); wait_us(1); DataPack.write(0xFD); wait_us(1); DataPack.write(0x02); wait_us(1); Latch=1; } } void BaseColorUnder(int a,int b) { Latch=0; DataPack.write(Base[a][b][0]); wait_us(1); DataPack.write(Base[a][b][1]); wait_us(1); DataPack.write(Base[a][b][2]); wait_us(1); DataPack.write(0x01); wait_us(1); Latch=1; } void BaseColorUpper(int a,int b) { Latch=0; DataPack.write(Base[a][b][0]); wait_us(1); DataPack.write(Base[a][b][1]); wait_us(1); DataPack.write(Base[a][b][2]); wait_us(1); DataPack.write(0x80); wait_us(1); Latch=1; } //color >> red=0 , yello=1 , green=2 int BaseUnder(int color) { VR_value0 = VR0.read(); VR_value0 = VR_value0*6; if(VR_value0<=1) { //base1 BaseColorUnder(0,color); return 1; } else if(VR_value0>1&&VR_value0<=2) { //base2 BaseColorUnder(1,color); return 2; } else if(VR_value0>2&&VR_value0<=3) { //base3 BaseColorUnder(2,color); return 3; } else if(VR_value0>3&&VR_value0<=4) { //base4 BaseColorUnder(3,color); return 4; } else if(VR_value0>4&&VR_value0<=5) { //base5 BaseColorUnder(4,color); return 5; } else if(VR_value0>5&&VR_value0<=6) { //base4 BaseColorUnder(5,color); return 6; } } //color >> red=0 , yello=1 , green=2 int BaseUpper(int color) { VR_value1 = VR1.read(); VR_value1 = VR_value1*6; if(VR_value1<=1) { //base1 BaseColorUpper(0,color); return 1; } else if(VR_value1>1&&VR_value1<=2) { //base2 BaseColorUpper(1,color); return 2; } else if(VR_value1>2&&VR_value1<=3) { //base3 BaseColorUpper(2,color); return 3; } else if(VR_value1>3&&VR_value1<=4) { //base4 BaseColorUpper(3,color); return 4; } else if(VR_value1>4&&VR_value1<=5) { //base5 BaseColorUpper(4,color); return 5; } else if(VR_value1>5&&VR_value1<=6) { //base4 BaseColorUpper(5,color); return 6; } } int UnderStart(int color) { down=BaseUnder(color); Latch=0; DataPack.write(Col[down]); wait_us(1); DataPack.write(0xFF); wait_us(1); DataPack.write(Col[down]); wait_us(1); DataPack.write(Row[1]); wait_us(1); Latch=1; if(UnderButton==1) { x=down; return 1; } else return 0; } int UpperStart(int color) { up=BaseUpper(color); Latch=0; DataPack.write(Col[up]); wait_us(1); DataPack.write(0xFF); wait_us(1); DataPack.write(Col[up]); wait_us(1); DataPack.write(Row[6]); wait_us(1); Latch=1; if(UpperButton==1) { x=up; return 1; } else return 0; } void uplose(int x) { Latch=0; DataPack.write(0xFF); wait_us(1); DataPack.write(0xFF); wait_us(1); DataPack.write(Col[x]); wait_us(1); DataPack.write(0x80); wait_us(1); Latch=1; wait_ms(500); } void downlose(int x) { Latch=0; DataPack.write(0xFF); wait_us(1); DataPack.write(0xFF); wait_us(1); DataPack.write(Col[x]); wait_us(1); DataPack.write(0x01); wait_us(1); Latch=1; wait_ms(500); } int main() { DataPack.frequency(100000); DataPack.format(8,0); way=0; srand(time(NULL)); int chk,lifeup=2,lifeun=2; chk=ran.read()*1000; chk=chk%2; //Count(); while(1) { while(1) { if(chk==0) { if(UnderStart(lifeun)==1) { break; } BaseUpper(lifeup); } if(chk==1) { if(UpperStart(lifeup)==1) { break; } BaseUnder(lifeun); } } while(1) { if(chk==0) { for(y=2; y<7; y++) { if(x>6||x<1) { way=way*-1; } x=x+way; for(t=0; t<800; t++) { BaseUnder(lifeun); up=BaseUpper(lifeup); Latch=0; DataPack.write(Col[x]); wait_us(1); DataPack.write(0xFF); wait_us(1); DataPack.write(Col[x]); wait_us(1); DataPack.write(Row[y]); wait_us(1); Latch=1; } } chk=1; } if(x==0) { if(up>1) { lifeup=lifeup-1; uplose(x); break; } way=-1; } if(x==1) { if(up>2) { lifeup=lifeup-1; uplose(x); break; } else if(up==1) { way=0; } else way=-1; } if(x==2) { if(up>3) { lifeup=lifeup-1; uplose(x); break; } else if(up==1) { way=1; } else if(up==2) { way=0; } else way=-1; } if(x==3) { if(up<2||up>4) { lifeup=lifeup-1; uplose(x); break; } else if(up==2) { way=1; } else if(up==3) { way=0; } else way=-1; } if(x==4) { if(up<3||up>5) { lifeup=lifeup-1; uplose(x); break; } else if(up==3) { way=1; } else if(up==4) { way=0; } else way=-1; } if(x==5) { if(up<4) { lifeup=lifeup-1; uplose(x); break; } else if(up==4) { way=1; } else if(up==5) { way=0; } else way=-1; } if(x==6) { if(up<5) { lifeup=lifeup-1; uplose(x); break; } else if(up==5) { way=1; } else way=0; } if(x==7) { if(up<6) { lifeup=lifeup-1; uplose(x); break; } way=1; } if(chk==1) { for(y=5; y>0; y--) { if(x>6||x<1) { way=way*-1; } x=x+way; for(t=0; t<800; t++) { down=BaseUnder(lifeun); BaseUpper(lifeup); Latch=0; DataPack.write(Col[x]); wait_us(1); DataPack.write(0xFF); wait_us(1); DataPack.write(Col[x]); wait_us(1); DataPack.write(Row[y]); wait_us(1); Latch=1; } } chk=0; } if(x==0) { if(down>1) { lifeun=lifeun-1; downlose(x); break; } way=-1; } if(x==1) { if(down>2) { lifeun=lifeun-1; downlose(x); break; } else if(down==1) { way=0; } else way=-1; } if(x==2) { if(down>3) { lifeun=lifeun-1; downlose(x); break; } else if(down==1) { way=1; } else if(down==2) { way=0; } else way=-1; } if(x==3) { if(down<2||down>4) { lifeun=lifeun-1; downlose(x); break; } else if(down==2) { way=1; } else if(down==3) { way=0; } else way=-1; } if(x==4) { if(down<3||down>5) { lifeun=lifeun-1; downlose(x); break; } else if(down==3) { way=1; } else if(down==4) { way=0; } else way=-1; } if(x==5) { if(down<4) { lifeun=lifeun-1; downlose(x); break; } else if(down==4) { way=1; } else if(down==5) { way=0; } else way=-1; } if(x==6) { if(down<5) { lifeun=lifeun-1; downlose(x); break; } else if(down==5) { way=1; } else way=0; } if(x==7) { if(down<6) { lifeun=lifeun-1; downlose(x); break; } way=1; } } if(lifeup<0) { while(UnderButton==0&&UpperButton==0) { } lifeup=2; lifeun=2; } if(lifeun<0) { while(UnderButton==0&&UpperButton==0) { } lifeup=2; lifeun=2; } } }