How do I compare each successive char in a char array with given criteria?
i'm working on project in take given message , convert morse code, in turn arduino spits out beeps. first, tried convert given message (a string) char array using tochararray(). think did wrong; of documentation lingo went on head.
however, still need know how take take each successive character in array , compare each letter of alphabet, can convert proper letter proper sequence of beeps. here's code:
you idea. plan incorporate equalsignorecase later on, it's not crowded.
but can replace
however, still need know how take take each successive character in array , compare each letter of alphabet, can convert proper letter proper sequence of beeps. here's code:
code: [select]
string message = "ad e dac"; //this message anything
const int optopin = 2;
void setup() {
pinmode(optopin, output);
}
void loop() {
morsecode(message.tochararray(char[], 20));
delay(5000);
}
void pressbutton(string ditdaw) { //this part irrelevant now
if(ditdaw == "dit") {
digitalwrite(optopin, high);
delay(100);
digitalwrite(optopin, low);
delay(100);
}
else if(ditdaw == "daw") {
digitalwrite(optopin, high);
delay(300);
digitalwrite(optopin, low);
delay(100);
}
}
void morsecode(char message[20]) {
for(int x = 0; x < 20; x++) {
if(message[x] == " ") {
delay(200);
}
else [b]if(message[x] == "a"[/b]) {
pressbutton(dit);
pressbutton(daw);
}
else if(message[x] == "a") {
pressbutton(dit);
pressbutton(daw);
}
else if(message[x] == "b") {
pressbutton(daw);
pressbutton(dit);
pressbutton(dit);
pressbutton(dit);
}
else if(message[x] == "b") {
pressbutton(daw);
pressbutton(dit);
pressbutton(dit);
pressbutton(dit);
}
else if(message[x] == "c") {
pressbutton(daw);
pressbutton(dit);
pressbutton(daw);
pressbutton(dit);
}
else if(message[x] == "c") {
pressbutton(daw);
pressbutton(dit);
pressbutton(daw);
pressbutton(dit);
}
else if(message[x] == "d") {
pressbutton(daw);
pressbutton(dit);
pressbutton(dit);
}
else if(message[x] == "d") {
pressbutton(daw);
pressbutton(dit);
pressbutton(dit);
}
}
you idea. plan incorporate equalsignorecase later on, it's not crowded.
but can replace
code: [select]
if(message[x] == "a"
make each character in array compared alphabet? , how tochararray() work?
why don't use char array intead of string object? seams easiest way.
Arduino Forum > Using Arduino > Programming Questions > How do I compare each successive char in a char array with given criteria?
arduino
Comments
Post a Comment