可以使用Arduino的模拟输出控制两个7段显示器吗?

时间:2019-05-06 23:17:57

标签: arduino multiplexing

我正在与arduino玩耍,我正在尝试制造东西。 在为我的项目增加越来越多的同时,我发现了一些困难。由于液晶显示器,我的数字引脚用完了,我想控制2个7段显示器以从温度传感器投射一些数字。

我创建了此示意图以向您展示我的位置:

enter image description here

// include the library code:
#include <LiquidCrystal.h>

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 10, 8, 7, 4);

// Temperature Pins 
const int analogIn = A1;

int RawValue= 0;
double Voltage = 0;
double tempC = 0;
double tempF = 0;

//LDR Pins
int LDR_sensor = A0; 
int LDR_value = 0;

//array to save Seven Seg pin configuration of numbers

int num_array[10][7] = {  { 1,1,1,1,1,1,0 },    // 0
                          { 0,1,1,0,0,0,0 },    // 1
                          { 1,1,0,1,1,0,1 },    // 2
                          { 1,1,1,1,0,0,1 },    // 3
                          { 0,1,1,0,0,1,1 },    // 4
                          { 1,0,1,1,0,1,1 },    // 5
                          { 1,0,1,1,1,1,1 },    // 6
                          { 1,1,1,0,0,0,0 },    // 7
                          { 1,1,1,1,1,1,1 },    // 8
                          { 1,1,1,0,0,1,1 }};   // 9

int first_digit = 0 ;
int second_digit = 0 ;

//function header
void Num_Write(int);

void setup() {
  Serial.begin(9600);
  // set up the LCD's number of columns and rows:
//  lcd.begin(16, 2);
//  lcd.clear();
//  delay(2000);
  // set pin modes


------------Here i should place the analog pins for the multiplexer
}

void loop() {
  // set the cursor to column 0, line 1
  // (note: line 1 is the second row, since counting begins with 0):
//  lcd.setCursor(0, 1);
  //Read values for the temperature sensor 
  RawValue = analogRead(analogIn);
  Voltage = (RawValue / 1023.0) * 5000; // 5000 to get millivots.
  tempC = (Voltage-500) * 0.1; // 500 is the offset 
  // Serial print the values for debug purposes
  Serial.print("Raw Value = " );  // shows pre-scaled value                    
  Serial.print(RawValue);      
  Serial.print("\t milli volts = "); // shows the voltage measured     
  Serial.print(Voltage,0); //
  Serial.print("\t Temperature in C = ");
  Serial.println(tempC);
  Serial.println(int(tempC));
  first_digit = int(tempC) / 10 ;
  Serial.print("The first digit is :  " );
  Serial.print(first_digit); // Get the first number for the seven seg display
  second_digit = int(tempC) - (first_digit * 10) ;
  Serial.print("\tThe second digit is : ");
  Serial.println(second_digit);
  Serial.println("\n");

  // Read values for the LDR sensor
  LDR_value = analogRead(LDR_sensor);
  //Print values to the LCD screen
//  lcd.setCursor(0, 0);
//  lcd.print("The value of LDR is :");
//  lcd.setCursor(0, 1);
//  lcd.print(LDR_value) ;
  delay(5000);
//  lcd.print("") ;

}

所以我的问题是,是否可以在7seg显示屏上输出2个不同的数字(first_digit和second_digit)。我从thread中得到了一些想法。我认为原理图还可以。

0 个答案:

没有答案