I cannot get the timing to work correctly(using tic and toc), I cannot get my while ~(B|R|Y|G) to work, which i need it to reiterate 4 times before it BOOM!, Last, need help with making a sound that makes 3 sharp beeps. Thanks!
조회 수: 2 (최근 30일)
이전 댓글 표시
tic
switch input('Will you cut the (R)ed, (Y)ellow,(B)lue, or (G)reen wire?-->','s')
%while ~(B|R|Y|G)
%input('Try Again -->');
case 'R'
bomb = 'DISARMED';
case 'Y'
bomb = 'BOOM!';
case 'B'
bomb = 'BOOM!';
case 'G'
tElapsed = toc;
%if (tElapsed>5)
%bomb = 'BOOM!';
end
tic
switch input('Will you cut the (R)ed, (Y)ellow, or (B)lue wire? -->','s')
case 'R'
bomb = 'DISARMED';
case 'Y'
bomb = 'BOOM!';
case 'B'
bomb = 'BOOM!';
otherwise
bomb = 'BOOM!';
tElapsed = toc;
end
otherwise
bomb = 'BOOM!';
if (tElapsed>5)
bomb = 'BOOM!';
end
end
%if bomb = ('DISARMED')
%load handel
%sound(y,Fs);
%else
%beep;beep;beep;
댓글 수: 3
Stephen23
2017년 9월 21일
@Snooping Poppet: it is not appreciated when you edit away the text of your question. Imagine if everyone did that, then this entire forum would be useless for anyone else as it would only consist of thousands of threads all reading "This post was taken down". Would you find that useful?
By deleting your question you unilaterally decided that my volunteered time helping you shall not be useful to anyone else. Do I get a say in this decision? Do you think this is why we volunteers come here and write our advice and comments?
If you want a consulting service then you will find plenty of them on them internet. This is a community forum with answers provided by volunteers.
채택된 답변
Stephen23
2016년 9월 16일
편집: Stephen23
2016년 9월 16일
Have a play around with this, you can change the logic very simply:
lim = 5;
arm = true; % is armed.
xpl = false; % is exploding.
txt = 'Will you cut the (R)ed, (Y)ellow,(B)lue, or (G)reen wire? ';
tic
while arm && ~xpl
switch upper(input(txt,'s'));
case 'R'
arm = false;
case {'Y','B'}
xpl = true;
case 'G'
xpl = toc>lim;
otherwise
disp('Try again!')
end
end
if xpl
load handel
sound(y,Fs)
elseif ~arm
beep
beep
beep
end
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Data Import and Analysis에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!