Display voltage on 7 segment display
sokin
Posts: 32
Hello, I am trying to display the analog to digital voltage from an activity board on a seven segment display. All I have been able to do so far is display the voltage on the serial terminal. I haven't been able to get it to display on the seven segment display. I think the code I have is the problem but if anyone knows the correct wiring for the display that would be good to confirm as well.
Thanks for the replies.
#include "simpletools.h" // Include simpletools
#include "adcDCpropab.h" // Include adcDCpropab
int main() // main function
{
adc_init(21, 20, 19, 18); // CS=21, SCL=20, DO=19, DI=18
float v2, v3; // Voltage variables
while(1) // Loop repeats indefinitely
{
v2 = adc_volts(2); // Check A/D 2
set_directions(0, 3, v2); // A/D 0...A/D 3 -> output
putChar(HOME); // Cursor -> top-left "home"
print("A/D2 = %f V%c\n", v2, CLREOL); // Display volts
set_outputs(0, 3, v2); // 0 -> 7-segment display
set_outputs(0, 3, v2); // set v2 high
pause(100); // Wait 1/10 s
}
}
Thanks for the replies.
#include "simpletools.h" // Include simpletools
#include "adcDCpropab.h" // Include adcDCpropab
int main() // main function
{
adc_init(21, 20, 19, 18); // CS=21, SCL=20, DO=19, DI=18
float v2, v3; // Voltage variables
while(1) // Loop repeats indefinitely
{
v2 = adc_volts(2); // Check A/D 2
set_directions(0, 3, v2); // A/D 0...A/D 3 -> output
putChar(HOME); // Cursor -> top-left "home"
print("A/D2 = %f V%c\n", v2, CLREOL); // Display volts
set_outputs(0, 3, v2); // 0 -> 7-segment display
set_outputs(0, 3, v2); // set v2 high
pause(100); // Wait 1/10 s
}
}
Comments
The following link (7 segment Learn tutorial) will show you how to wire a 7 segment display and suggest how to use the ADC Measure Volts example to make a program display the voltage on 7 segment displays.
Thanks
In order to display the ADC voltage you will need to determine how you want to display the information. If you have only a single 7 segment display you can only display a single digit of the voltage (at a time). You could look into using the 'round()' function to take the ADC voltage and round it to the nearest integer.
For example:
This will have the 7 segment display, display the integer part of the ADC voltage as a digit. If you don't want the voltage rounded, you will need to use something like 'int()' to obtain the integer value without rounding.
If you want to display the other digits of the ADC voltage you will need to "parse" the ADC voltage value to obtain each digit you want to display. The "parsing" could be accomplished by multiplying the ADC voltage by 10 and then subtracting 10 to get the tenths digit. If you do that in a loop you could get the digit for each successive fractional value.
Thanks
#include "simpletools.h" // Include simpletools
#include "adcDCpropab.h" // Include adcDCpropab
int main() // Main function
{
adc_init(21, 20, 19, 18); // CS=21, SCL=20, DO=19, DI=18
float v2, v3; // Voltage variables
while(1) // Loop repeats indefinitely
{
v2 = adc_volts(2); // Check A/D 2
v3 = adc_volts(3); // Check A/D 3
set_directions(15, 8, 0b11111111); // P15...P8 -> output
set_outputs(15, 8, (v3)); // v3
pause(500);
}
}
It turns out the round() function isn't completely implemented in the SimpleIDE environment.
Here is my program that I created and tested on my Propeller Activity Board using a common cathode 7 segment LED display and potentiometer as shown in the two learn examples.
My program will display all the significant digits of the measured voltage one digit at a time on the 7 segment LED display. The float2string function (simpletext.h) in the code is another possible way of dealing with numerical values by putting them into a string, which could then be used or displayed.
Take a look at my code and download the attached zip file.
NOTE: To get posted code to look like the following in the forum, use the "C" <code> format option that is in the editor toolbar.
This helps me so much. Thank you for all of your input.