There are four picture in my project and each of them point at different direction.
If I turn my phone the same as the direction of the picture.
It will show a picture with a smile, else it will show you an angry face.
clear all; %clear all things in work space
m = mobiledev;
swing=0;
score = 0; %set score to 0
pic=imread('start.jpeg.jpg');
image(pic)
pause(3)
while swing==0 %while loop
disp('start'); %show start to make sure it start
direction=round(3*rand(1,1))+1; %generate one randon number between 1 to 4
if direction==1
pic=imread('RIGHT.png.png'); %load the question picture
elseif direction==2
pic=imread('DOWN.jpeg.jpg'); %load the question picture
elseif direction==3
pic=imread('LEFT.jpeg.jpg'); %load the question picture
elseif direction==4
pic=imread('UP.jpeg.JPG'); %load the question picture
end
image(pic) %show the question
pause(2)
m.Logging = 1; %start getting signal from cellphone
pause(2);
m.Logging = 0; %stop getting signal from cellphone
[or, tor] = orientlog(m);
x = or(:,2);
c=x(end); %get the last signal
y = or(:,3);
d=y(end); %get the last signal
load_system('judge'); %load the simulink system
sim('judge'); %judge answer in simulink
b = dir(2,1);
if b==4
pic=imread('correct.png.PNG');
image(pic)
score = score + 1;
elseif b==1
pic=imread('correct.png.PNG');
image(pic)
score = score + 1;
elseif b==2
pic=imread('correct.png.PNG');
image(pic)
score = score + 1;
elseif b==3
pic=imread('correct.png.PNG');
image(pic)
score = score + 1;
elseif b==5
pic=imread('wrong.jpeg.jpg');
swing=1; %break the while loop
image(pic)
pause(2)
pic=imread('gameover.jpeg.jpg'); %load game over picture
image(pic) %show game over picture
disp('YOUR SCOER:') %display the score
disp(score)
pause(4)
end %end of while loop
pause(2);
end