Treenut Home | projects | Arduino

Modifications to the Simple 7-Segment Display driver that counts to 10

Circuit additions:

Add a simple voltage divider (potentiometer) between the +5 V and Ground. Connect the wiper to one of the analog inputs and use this voltage reading as the delay variable in the counter program.

    Source Code Listing changes

    Add some code lines to the variable and constant definition block.

    // Analog variables:

    const int sensorPin = 0; // select the input pin for the potentiometer
    long sensorValue = 0; // variable to store the value coming from the sensor

    Add the following initialization line to the Setup() function:

    // initialize serial communications at 9600 bps:

    Add the following lines at the beginning of the Loop() function to read the voltage from the potentiometer and assign it to the delay counter:

    sensorValue = analogRead(sensorPin);
    // assign to current interval for blink speed
    interval = sensorValue;

    That's all you need to control the delay between displaying the digits on the display.

    I added the following function at the end of the program to allow me to monitor the actual value being read from the potentiometer. The Arduino chip sends this serial output back through the USB port connection to the computer and the Arduino SDK software creates a window to display these print commands.

    int outputPotValue(int sensorValue)
    // map it to the range of the analog out:
    outputValue = map(sensorValue, 0, 1023, 0, 255);

    // print the results to the serial monitor:
    Serial.print("sensor = " );
    Serial.print("\t output = ");