Clear Filters
Clear Filters

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!

4 views (last 30 days)
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 Comments
Stephen23
Stephen23 on 21 Sep 2017
@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.

Sign in to comment.

Accepted Answer

Stephen23
Stephen23 on 16 Sep 2016
Edited: Stephen23 on 16 Sep 2016
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
Note that using tic and toc is not the same as running a timer object.

More Answers (0)

Tags

No tags entered yet.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!