Matlab

Final Project
Introduce
There is a small game I create by Matlab. Because the weather is scorching hot and the summer is coming, the game is about shaking beverage.
I connect the device like IPHONE to computer and set the code. When the player shakes IPHONE just like shaking a can of soft drink, the fast the player shakes, the better score he or she gets. When the score increase to a value, the player will win the game.
Also, I use some simulink and stateflow in the code. they will make the function much shorter than before, and will easily see how the process show behind the code.
Demo Video
Simulink

Stateflow

Code
clear all
score=0;
while 1 %make the game play again until the score>5
clear [ac,tac];
clear [or, tor];
clear m;
m = mobiledev;
pic=imread('C:\Users\Meganwu\Documents\S&S\first.PNG');
image(pic);
pause(3);
m.Logging = 1; %start measure
pause(3);
m.Logging = 0; %stop measure
[or, tor] = orientlog(m); %measure orientation(azimuth, pitch, roll)
y = or(:,3); %choose roll
r=max(y); %max of roll
if r>25 %turn right
pic=imread('C:\Users\Meganwu\Documents\S&S\shake2.PNG');
image(pic);
pause(3);
elseif r<-25 %turn reft
pic=imread('C:\Users\Meganwu\Documents\S&S\shake.PNG');
image(pic);
pause(3);
end
m.Logging = 1; %start measure
pause(3);
m.Logging = 0; %stop measure
[ac,tac] = accellog(m); %measure acceleration(x, y, z)
x = ac(:,1); %choose x
k=max(x); %max of x
if k>=60 %x>=60
pic=imread('C:\Users\Meganwu\Documents\S&S\splash1.PNG');
image(pic);
pause(0.8);
elseif k>=40&&k<60 %40=<x<60
pic=imread('C:\Users\Meganwu\Documents\S&S\splash2.PNG');
image(pic);
pause(0.8);
elseif k>=25&&k<40 %25=<x<40
pic=imread('C:\Users\Meganwu\Documents\S&S\splash3.jpg');
image(pic);
pause(0.8);
elseif k>=0&&k<25 %0=<x<25
pic=imread('C:\Users\Meganwu\Documents\S&S\splash4.jpg');
image(pic);
pause(0.8);
end
load_system('final'); %simulink
sim('final');
if a==1
pic=imread('C:\Users\Meganwu\Documents\S&S\perfect.jpg');
image(pic);
pause(2);
score=score+3;
elseif a==2
pic=imread('C:\Users\Meganwu\Documents\S&S\great.jpg');
image(pic);
pause(2);
score=score+2;
elseif a==3
pic=imread('C:\Users\Meganwu\Documents\S&S\good.jpg');
image(pic);
pause(2);
score=score+1;
elseif a==4
pic=imread('C:\Users\Meganwu\Documents\S&S\soso.PNG');
image(pic);
pause(2);
score=score+0;
end
sw=0;
if score>5
sw=1;
end
if sw==1 %score>5 win the game
pic=imread('C:\Users\Meganwu\Documents\S&S\Win.jpg');
image(pic);
break;
end
end