Im trying to make may arduino play a sequence of notes using a buzzer.
code:
%arduino music
pin = 'D5';
tune = 'eefggfedccdee dd';
beats = [1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 3];
notes = ['c', 'd', 'e', 'f', 'g', ' '];
freq = [262 294 330 349 392 0];
for ii = 1:length(tune)
playTone(arduino,pin,freq(strcmp(tune(ii),notes)),0.1*beats(ii))
pause(0.1*beats(ii))
end
output:
>> musicArduino
Error using musicArduino (line 12)
Invalid parameter type. The tone frequency
value must be a scalar double between 0 and
32767 (Hz).

 Respuesta aceptada

Walter Roberson
Walter Roberson el 25 de Sept. de 2018

1 voto

You strcmp a single character from the tune to the 6 character vector formed by notes. The result will be a scalar false leading to empty freq selection.
Easiest fix is to make notes a cell array instead of a character vector. Remember that ['a', 'b'] means horzcat('a', 'b') which is 'ab'

2 comentarios

Natalio Ramirez
Natalio Ramirez el 25 de Sept. de 2018
Then the values assigned to variable freq have nothing to do with the error?
Walter Roberson
Walter Roberson el 25 de Sept. de 2018
Editada: Walter Roberson el 25 de Sept. de 2018
The values assigned to freq had nothing to do with the error. The problem was that you were ending up passing [] in the frequency location, and [] is not a scalar double .
Change
notes = ['c', 'd', 'e', 'f', 'g', ' '];
to
notes = {'c', 'd', 'e', 'f', 'g', ' '};

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre MATLAB Support Package for Arduino Hardware en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 24 de Sept. de 2018

Editada:

el 25 de Sept. de 2018

Community Treasure Hunt

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

Start Hunting!

Translated by