I am trying to create beep sound from characters in the string. Here is the code:
/*
* Buzzer connected to Arduino uno digital pin 13
* Switch connected to digital pin 2
*/
#include <avr/io.h>
#include <util/delay.h>
const int TBEEP = 1000;
const int TBEEEEP = 3500;
const int TGAP = 500;
const int TGAPLETTER = 2000;
int portb = 0x20;
void beep() {
PORTB = ~portb; _delay_ms(TGAP);
PORTB = portb; _delay_ms(TBEEP);
PORTB = ~portb; _delay_ms(TGAP);
}
void beeeep() {
PORTB = ~portb; _delay_ms(TGAP);
PORTB = portb; _delay_ms(TBEEEEP);
PORTB = ~portb; _delay_ms(TGAP);
}
void gapLetter() {
PORTB = ~portb; _delay_ms(TGAPLETTER);
}
void morse_S() {
beep(); beep(); beep();
gapLetter();
}
void morse_M() {
beeeep(); beeeep();
gapLetter();
}
void morse_SMS() {
morse_S(); morse_M(); morse_S();
}
void morse(char theString[]) {
for (int i = 0; theString[i] != '\0'; i++)
{
if(&theString[i] == "S")
morse_S();
else if(&theString[i] == "M")
morse_M();
}
}
int main (void)
{
DDRB = 0xFF;
DDRD = 0x00;
PORTD = 0x04;
while (1) {
if (PIND & 0x04) {
PORTB = ~0x20;
} else {
//morse_SMS(); // it works
morse("SMS"); // this one doesnt work like morse_SMS() PLEASE HELP!
}
}
return 0;
}
In function void morse(char theString[]) {...}
, I want to produce beep sound from every character in the string "SMS". Unfortunately, only the last character can make it.
I am using Atmel Studio 6. When I build solution (F7) there is no error but warning which I dont understand (sorry for being such a total noob)
comparison with string literal results in unspecified behavior [-Waddress]
How to force every character to beep one after another?