我有Arduino Morse Code Translator的工作代码。闪烁并发出任何写入串行监视器的信号并将其输入串行监视器。我想要添加的是代码,也可以将Arduino闪回的字母/标点符号移回到#34; Text to Speech"程序我有(简单TTS阅读器)。有可能吗?
`//Sketch 5_05WORKS Morse Interpreter including punctuation
int ledPin = 13;
int dotDelay = 250; //set the delay to a quarter second
char ch;
byte newch; //transposed punctuation values
char* letters[] = // Letters A-Z
{
".-", "-...", "-.-.", "..", ".",
"..-.", "--.", "....", "..",
".---", "-.-", ".-..", "--", "-.",
"---", ".--.", "--.-", ".-.",
"...", "-", "..-", "...-", ".--",
"-..-", "-.--", "--.."
};
char* numbers[] = // numbers 0-9
{
"-----", ".----", "..---", "...--", "....-",
".....", "-....", "--...", "---..", "----."
};
char* punct[] = // punctuation marks
{
".-.-.-", "--..--", ".----.", "..--..", // . , ' ?
"-.--.", "-.--.-", "-.-.--", "-.-.-.", // ( ) ! ;
"---...", ".-..-.", ".--.-.", "-....-", // : " @ -
"..--.-", ".-.-.", "...-..-", "-...-", // _ + $ =
".-..." // &
".-.-.-", "--..--", "..--..", ".----.", // (punctuation marks) . , ? '
"-.-.--", "-.--.", "-.--.-", ".-...", // ! ( ) &
"---...", "-.-.-.", "-...-", ".-.-.", // : ; = +
"-....-", "..--.-", ".-..-.", "...-..-", // - _ " $
".--.-." // @
};
void setup()
{
pinMode(ledPin, OUTPUT);
Serial.begin(9600);
Serial.println("To send text to be displayed in Morse Code, type words above and press Send");
}
void loop()
{
if (Serial.available() > 0)
{
ch = Serial.read(); //read a single letter
if (ch >= 'a' && ch <= 'z') // is it lower case letter?
{
flashSequence(letters [ch - 'a']);
}
else if (ch >= 'A' && ch <= 'Z') // is it a capital letter?
{
flashSequence(letters [ch - 'A']);
}
else if (ch >= '0' && ch <= '9') // is it a number?
{
flashSequence (numbers[ch - '0']);
}
else if (ch >= 33 && ch <= 95) // is it punctuation?
{
punctuationTranspose();
flashSequence (punct[newch]);
}
else if (ch == ' ') // is it a blank space?
{
delay(dotDelay * 4); //gap between words
}
{
Serial.print(ch);
}
}
}
void flashSequence (char* sequence)
{
int i = 0;
while (sequence[i] != NULL)
{
flashDotOrDash(sequence[i]);
i++;
}
delay(dotDelay * 3); //gap between letters
}
void flashDotOrDash (char dotOrDash)
{
digitalWrite(ledPin, HIGH);
if (dotOrDash == '.')
{
delay (dotDelay);
}
else // must be a -
{
delay (dotDelay *2);
}
digitalWrite(ledPin, LOW);
delay(dotDelay); //gap between flashes
}
byte punctuationTranspose()
{
switch(ch)
{
case 1:
ch=='.';
newch= 0;
break;
case 2:
ch==',';
newch= 1;
break;
case 3:
ch==39;
newch= 2;
break;
case 4:
ch=='?';
newch= 3;
break;
case 5:
ch=='(';
newch= 4;
break;
case 6:
ch==')';
newch= 5;
break;
case 7:
ch=='!';
newch= 6;
break;
case 8:
ch==';';
newch= 7;
break;
case 9:
ch==':';
newch= 8;
break;
case 10:
ch=='"';
newch= 9;
break;
case 11:
ch=='@';
newch= 10;
break;
case 12:
ch=='-';
newch= 11;
break;
case 13:
ch=='_';
newch= 12;
break;
case 14:
ch=='+';
newch= 13;
break;
case 15:
ch=='$';
newch= 14;
break;
case 16:
ch=='=';
newch= 15;
break;
case 17:
ch=='&';
newch= 16;
break;
return newch;
}
}`
答案 0 :(得分:0)
是的,有可能。一种方法是将Processing与these TTS methods之一一起使用。
答案 1 :(得分:0)
是的,实际上很有可能! TTS非常基础(关于这样的项目),你必须对c语言有足够的了解才能将一些库连接到你的Arduino输出:http://www.devfactor.net/2014/09/22/ship-sinking-and-all-you-have-is-an-arduino-make-your-arduino-blink-s-o-s/