Hello, it's me again. Sorry for making multiple posts so close together.
For an assignment in my introductory microprocessors class, I have to create a program that reads a phrase typed into the serial monitor and prints how many vowels are in said string.
I've seen a lot of examples online about how to do this with integers, but I can't seem to figure out how to make it work with letters.
Please let me know if you have any ideas. Thank you!
/* HW 3: Vowel Count
* Adapted from https://www.arduino.cc/en/Serial/Read
*/
char input = 0;
int count = 0;
int countA = 0;
int countE = 0;
int countI = 0;
int countO = 0;
int countU = 0;
int counta = 0;
int counte = 0;
int counti = 0;
int counto = 0;
int countu = 0;
void setup()
{
   Â
Serial.begin( 9600 );
}
void loop()
{
   count = 0;
    while ( Serial.available() == 0 )
    {
     input = Serial.read();
     delay ( 3000 );
     Serial.print (input);
     Serial.print (" ");
     if ( input = 65 )
    {
     count = count++;
    }
     if ( input = 69 )
    {
     count = count++;
    }
     if ( input = 73 )
    {
     count = count++;
    }
     if ( input = 79 )
    {
     count = count++;
    }
     if ( input = 85 )
    {
     count = count++;
    }
     if ( input = 97 )
    {
     count = count++;
    }
     if ( input = 101 )
    {
     count = count++;
    }
     if ( input = 105 )
    {
     count = count++;
    }
     if ( input = 111 )
    {
     count = count++;
    }
     if ( input = 117 )
    {
     count = count++;
    }
   Â
    }                                     Â
   if (count > 0)
   {
   Serial.print (count);
   Serial.println (" vowel(s)");
   delay (200);
   }
  Â
}
Well, first of all, you have a "phrase" of unknown length coming to the Serial port, yet you allow for only a single character to be moved from the buffer to your 'input". You must have storage for the entire phrase.
hint 1: watch your "=" vs "==" !
hint 2: in C, a single ascii character inside single quotes has an integer value equal to the ascii value of the character.
So "if (input == 97)" can be written as "if (input == 'a')"
If you need to print how many vowels you have you only need 1 count, and just check any incoming char against the vowels (small caps or not - what about Y?). Print the result when you receive ‘\n’ for example
What are those for then
int countA = 0;
int countE = 0;
int countI = 0;
int countO = 0;
int countU = 0;
int counta = 0;
int counte = 0;
int counti = 0;
int counto = 0;
int countu = 0;
This - in plain English -
while ( Serial.available() == 0 )
    {
     input = Serial.read();
would read as « while I don’t have anything to read, try to read it anyway ».... how successful do you think that is likely to be?
int count = 0;
int countA = 0;
int countE = 0;
int countI = 0;
int countO = 0;
int countU = 0;
int counta = 0;
int counte = 0;
int counti = 0;
int counto = 0;
int countu = 0;
you reset count to 0 every time loop runs. So it can never go past 1.
you only run this when there's nothing to read. Replace the while line with:
if (Serial.available()) {
This will run the block when you have something on the Serial buffer: read the character and process it.
if ( input = 65 )
And this one of course.
If you don't care about which vowel but just want to count them all you can do this in a single if statement:
if (input == 'a' || input == 'e' || input == 'i') { // fill in the rest
count++;
}
if (input == '\n') { // newline character terminates the input.
Serial.print("Vowels counted in this input: ");
Serial.println(count);
count = 0;
}