簡體   English   中英

如何使用Arduino Uno將5個力傳感器顯示到LCD上

[英]How to display 5 force sensors reading to LCD with Arduino Uno

我正在做一個需要5個力傳感器的項目。 我在串行監視器上顯示讀數沒有問題,但是在LCD上卻遇到同樣的問題。 有人可以用代碼在16x2 LCD上連續顯示5個力傳感器的讀數來幫助我嗎? 編輯:我已經發布了我的代碼,謝謝

    int fsrVoltage;     // the analog reading converted to voltage
    int fsrVoltage1; 
    unsigned long fsrResistance;  // The voltage converted to resistance, can be very                   big so make "long"
    unsigned long fsrResistance1;
    unsigned long fsrConductance;
    unsigned long fsrConductance1; 
    long fsrForce;       // Finally, the resistance converted to force
    long fsrForce1;   

    #include <Wire.h>
    #include <Adafruit_MCP23017.h>
    #include <Adafruit_RGBLCDShield.h>

    Adafruit_RGBLCDShield lcd = Adafruit_RGBLCDShield();
    void setup()
    {

    lcd.begin(16, 2);

    Serial.begin(9600);

    }

    void loop()
    {


    int force = analogRead(A0);
    int force1 = analogRead(A1);

    fsrVoltage = map(force, 0, 1023, 0, 5000);

// The voltage = Vcc * R / (R + FSR) where R = 10K and Vcc = 5V
// so FSR = ((Vcc - V) * R) / V        yay math!
fsrResistance = 5000 - fsrVoltage;     // fsrVoltage is in millivolts so 5V = 5000mV
fsrResistance *= 10000;                // 10K resistor
fsrResistance /= fsrVoltage; 
fsrConductance = 1000000;           // we measure in micromhos so 
fsrConductance /= fsrResistance;

    fsrVoltage1 = map(force1, 0, 1023, 0, 5000);

// The voltage = Vcc * R / (R + FSR) where R = 10K and Vcc = 5V
// so FSR = ((Vcc - V) * R) / V        yay math!
fsrResistance1 = 5000 - fsrVoltage1;     // fsrVoltage is in millivolts so 5V = 5000mV
fsrResistance1 *= 10000;                // 10K resistor
fsrResistance1 /= fsrVoltage1;
fsrConductance1 = 1000000;           // we measure in micromhos so 
fsrConductance1 /= fsrResistance1;



// Use the two FSR guide graphs to approximate the force
if (fsrConductance <= 1000) 
{
  fsrForce = fsrConductance / 80;
    lcd.setCursor(0, 0);
  lcd.print("Force for 1st FSR: ");
  lcd.setCursor(0, 1);
  lcd.print(fsrForce,DEC);      
} else 
{
  fsrForce = fsrConductance - 1000;
  fsrForce /= 30;
  lcd.setCursor(0, 0);
  lcd.print("Force for 1st FSR: ");
  lcd.setCursor(0, 1);
  lcd.print(fsrForce,DEC);    
}
delay(5000);

if (fsrConductance1 <= 1000) 
{
  fsrForce1 = fsrConductance1 / 80;
  lcd.setCursor(0, 0);
  lcd.print("Force for 2nd FSR: ");
  lcd.setCursor(0, 1);
  lcd.print(fsrForce1,DEC);      
} 
else 
{
  fsrForce1 = fsrConductance1 - 1000;
  fsrForce1 /= 30;
  lcd.setCursor(0, 0);
  lcd.print("Force for 2nd FSR: ");
  lcd.setCursor(0, 1);
  lcd.print(fsrForce1,DEC);     
}
    delay(200);
      }

我想您的問題與LCD有關。 您可以從這里開始: http : //arduino.cc/en/Tutorial/LiquidCrystal

如果您需要更多幫助,則應添加更多信息。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM