Learn Arduino with Olympia Circuits
Learn Arduino
  • Home
    • Get Started
    • How to Use This Site
  • Electronics
    • The Basics
    • Electricity Flows like Water
    • Electronic Components
    • The Arno Board
  • Programming
    • The Basics
    • setup and loop Blocks
    • Variables and Arrays
    • Connecting with the Pins
    • Flow Control >
      • if Statement
      • Loops
      • Delays
    • Functions
    • Serial Communication
    • USB
    • Some Thoughts
  • Projects
    • Projects 1 >
      • 1.01: Blink
      • 1.02 Blink x2
      • 1.03 Blink Faster
      • 1.04 LED Chase!
      • 1.05 Wait To Blink
      • 1.06 Blink a Little Faster Now
      • 1.07 LED Fade
      • 1.08 RGB Blink
      • 1.09 Change RGB Color with SW1
      • 1.10 Fade RGB Colors
      • 1.11 Reaction Time Game
    • Projects 2 >
      • 2.01 Hello World
      • 2.02 Talk Back
      • 2.03 ASCII Values
      • 2.04 Ski Game
      • 2.05 Demonstration of the String Object
    • Projects 3 >
      • 3.01 Read the Potentiometer
      • 3.02 ASCIIbet Soup
      • 3.03 Potentiometer sets LED Brightness
      • 3.04 Potentiometer Sets Blink Rate
      • 3.05 LED Chase, Part II
    • Projects 4 >
      • 4.01 Bringing the Piezo to Life
      • 4.02 Controlling the Piezo with a Function
      • 4.03 Piezo C Major
      • 4.04 Piezo Greensleaves
      • 4.05 Piezo Metronome
      • 4.06 Piezo as an Input
      • 4.07 Piezo as an Input 2
      • 4.08 Metronome II
      • 4.09 Piezo Playback
      • 4.10 Piezo Fireworks
      • 4.11 Piezo Mosquito
    • Projects 5 >
      • 5.01 The Phototransistor
      • 5.02 Light and Sound
      • 5.03 Light and Sound II
    • Projects 6 >
      • 6.01 EEPROM
      • 6.02 I2C Address Scan
      • 6.03 Read the I2C Temperature Sensor
      • 6.04 High Temperature Alarm
    • Projects 7 >
      • 7.01 Arno Phone Home
      • 7.02 Keyboard Alphabet
      • 7.03 Move Mouse
      • 7.04 Draw Squares
    • Special Projects >
      • Bike Light Demo
  • References
    • Arno Pin Key
    • Arno Schematic
    • Project Index

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:
  • Circuit 7


  • Select Sketch

    ///////////////////////////////////////////////////
    //Project 3.02 ASCIIbet Soup
    int POT1 = A0;
    int potRead = 0;
    int letter = 0;
    void setup(){
    Serial.begin(9600);
    pinMode(POT1,INPUT);
    }
    void loop(){
    potRead = analogRead(POT1);
    letter = map(potRead,0,1023,65,90);
    for(int k = letter; k > 65; k--){
    Serial.print( );
    }
    Serial.println(char(letter));
    delay(200);
    }
    ///////////////////////////////////////////////////

    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.

    Back to Projects 3

    Copyright Olympia Circuits LLC 2014. All Rights Reserved.