Project 3.02 ASCIIbet Soup
In this project, we translate the potentiometer reading into a value between 65 and 90. This range of values corresponds with the upper-case letters in the ASCII table. To make things more interesting, we make the letters further along in the alphabet appear farther from the left-hand side of the serial monitor. Upload this sketch, wait a moment, and then open the serial monitor and start rotating the thumbwheel potentiometer.
Concepts: ADC, ASCII, analogRead, map function, voltage divider
Circuits:
Concepts: ADC, ASCII, analogRead, map function, voltage divider
Circuits:
We read the potentiometer and then use the map function to rescale its value between 65 and 90. This range of numbers corresponds to the the upper-case letters in the ASCII table (65 = ‘A’, 90 = ‘Z’):
potRead = analogRead(POT1);
letter = map(potRead,0,1023,65,90);
To make things more interesting, we control where each letter appears in the serial monitor. We add a number of spaces equal to the position of the letter in the alphabet. This makes the letter ‘A’ appear in the first column in the serial monitor and the letter ‘Z’ appear in the 26th column:
letter = map(potRead,0,1023,65,90);
for(int k = letter; k > 65; k--){
Serial.print(" ");
}
In a previous project, we initialized a char variable and then assigned it a numeric value. The Arno knew to translate the numeric value into a character from the ASCII table. In this project, we cast a int variable into a character within the Serial.println statement:
Serial.println(char(letter));
And that’s it. The code is simple but it creates something that’s visually interesting. Show it to a friend and see if they catch on to the underlying logic of how the letters move with the potentiometer.
potRead = analogRead(POT1);
letter = map(potRead,0,1023,65,90);
To make things more interesting, we control where each letter appears in the serial monitor. We add a number of spaces equal to the position of the letter in the alphabet. This makes the letter ‘A’ appear in the first column in the serial monitor and the letter ‘Z’ appear in the 26th column:
letter = map(potRead,0,1023,65,90);
for(int k = letter; k > 65; k--){
Serial.print(" ");
}
In a previous project, we initialized a char variable and then assigned it a numeric value. The Arno knew to translate the numeric value into a character from the ASCII table. In this project, we cast a int variable into a character within the Serial.println statement:
Serial.println(char(letter));
And that’s it. The code is simple but it creates something that’s visually interesting. Show it to a friend and see if they catch on to the underlying logic of how the letters move with the potentiometer.