用Tinkercad学arduino之 LCD电压电流表

项目地址:https://www.tinkercad.com/things/0k0l2s7QP3l-arduino-voltmeter-ammeter

#include <LiquidCrystal.h>

LiquidCrystal lcd(12, 11, 4, 5, 6, 7);
float voltageInput = 0.0;
float voltageReading = 0.0;
float currentReading = 0.0;
float RA = 15000.0;
float RB = 1500.0;
         
void setup()
{
  lcd.begin(16, 2);
  lcd.clear();
}

void loop ()
{
  lcd.setCursor(0,0);
  lcd.print("Napon");
  lcd.setCursor(8, 0);
  lcd.print(voltageReading);
  lcd.setCursor(14, 0);
  lcd.print("V");
  
  lcd.setCursor(0,1);
  lcd.print("Struja");
  lcd.setCursor(8, 1);
  lcd.print(currentReading);
  lcd.setCursor(14, 1);
  lcd.print("mA");
  
  voltageInput = (analogRead(A0)*5.0)/1023.0;
  voltageReading = voltageInput/(RB/(RA + RB));
  currentReading = 1000*(voltageReading/(RA+RB));
}

 

posted @ 2020-12-03 19:15  meetrice  阅读(56)  评论(0编辑  收藏