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
main.cpp
- Committer:
- lolopo008
- Date:
- 2015-12-05
- Revision:
- 3:054a677aca64
- Parent:
- 2:8b6312dbfd2f
- Child:
- 4:3605c624b64f
File content as of revision 3:054a677aca64:
#include "mbed.h"
SPI DataPack(SPI_MOSI, SPI_MISO, SPI_SCK);
DigitalOut Latch(D10);
AnalogIn VR0(A0);
AnalogIn VR1(A1);
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 main()
{
DataPack.frequency(100000);
DataPack.format(8,0);
x=2;
way=0;
Count();
while(1) {
for(y=2; y<7; y++) {
if(x>6||x<1) {
way=way*-1;
}
x=x+way;
for(t=0; t<800; t++) {
BaseUnder(2);
up=BaseUpper(2);
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;
}
}
if(x==0) {
if(up>1) {
break;
}
way=1;
}
if(x==1) {
if(up>2) {
break;
} else if(up==1) {
way=0;
} else way=-1;
}
if(x==2) {
if(up>3) {
break;
} else if(up==1) {
way=1;
} else if(up==2) {
way=0;
} else way=-1;
}
if(x==3) {
if(up<2||up>4) {
break;
} else if(up==2) {
way=1;
} else if(up==3) {
way=0;
} else way=-1;
}
if(x==4) {
if(up<3||up>5) {
break;
} else if(up==3) {
way=1;
} else if(up==4) {
way=0;
} else way=-1;
}
if(x==5) {
if(up<4) {
break;
} else if(up==4) {
way=1;
} else if(up==5) {
way=0;
} else way=-1;
}
if(x==6) {
if(up<5) {
break;
} else if(up==5) {
way=1;
} else way=0;
}
if(x==7) {
if(up<6) {
break;
}
way=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(2);
BaseUpper(2);
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;
}
}
if(x==0) {
if(down>1) {
break;
}
way=1;
}
if(x==1) {
if(down>2) {
break;
} else if(down==1) {
way=0;
} else way=-1;
}
if(x==2) {
if(down>3) {
break;
} else if(down==1) {
way=1;
} else if(down==2) {
way=0;
} else way=-1;
}
if(x==3) {
if(down<2||down>4) {
break;
} else if(down==2) {
way=1;
} else if(down==3) {
way=0;
} else way=-1;
}
if(x==4) {
if(down<3||down>5) {
break;
} else if(down==3) {
way=1;
} else if(down==4) {
way=0;
} else way=-1;
}
if(x==5) {
if(down<4) {
break;
} else if(down==4) {
way=1;
} else if(down==5) {
way=0;
} else way=-1;
}
if(x==6) {
if(down<5) {
break;
} else if(down==5) {
way=1;
} else way=0;
}
if(x==7) {
if(down<6) {
break;
}
way=1;
}
}
}