首页 > 解决方案 > 是否可以通过 Arduino 的模拟输出控制两个 7 段显示器?

问题描述

我正在玩arduino,我正在尝试构建东西。在我的项目中添加越来越多的内容时,我发现了一些困难。由于我的 LCD,我的数字引脚用完了,我想控制 2 个 7 段显示器以从温度传感器投射一些数字。

我创建了这个示意图来告诉你我在哪里:

在此处输入图像描述

// 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)。我从这个线程中得到了一些想法。我认为原理图还可以。

标签: arduinomultiplexing

解决方案


推荐阅读