Recap of Characters
What We’ve Covered So Far
Declaring a character variable:
char twizzle; // an empty character variable named twizzle for use later
Changing a character variable:
twizzle = 'a'; // twizzle character variable changed to 'a'
Declaring and assigning a character variable at the same time:
char twizzle = 'b'; // character variable named twizzle with a value of 'b'
Doing math with a character variable:
twizzle = twizzle + 15; // addition twizzle = twizzle - 15; // subtraction twizzle = twizzle * 5; //multiplication twizzle = twizzle / 2; //division twizzle ++; //add one to distance twizzle --; //subtract one from distance
ASCII values: Each character value has a special integer called an ASCII value that corresponds to the character.
Questions and Activities to Try
1. See if you can use the image characters to write a simple story. For example-
2. Using the LCD code we covered try using the command sparki.print( ) instead of sparki.println( ). See if you can spell your name out by creating a bunch of different character variables with letter stored in them. What about doing it with ASCII values inside the sparki.print( ) commands instead of letters? (Hint, you’ll need to change the numbers in to characters kind of like how we changed the characters into a number above. An example of that code is shown below.)
sparki.print(char(2)); // this will code print out a smiley face
3. How about writing your name using just one character variable? You’ll need to do math to the variable between each time you use the sparki.print( ) commands, unless your name only has one letter!
Next Step-
But characters don’t sound very useful on their own. To spell things, we need to have more than one of them in a row and there must be an easier way using a whole bunch of sparki.print( ) commands. How do we do that? With Arrays!