|
|||||||||||||||||
|
Modifications to the Simple 7-Segment Display driver that counts to 10Circuit 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: Serial.begin(9600); 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); outputPotValue(sensorValue); // 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) // print the results to the serial monitor: |
||||||||||||||||
Last Updated:
February 12, 2012 8:03 PM
Webmaster: Stuart Baker Email Stuart |