Тема: DC max
Здравствуйте.
В первой программе все работает как надо - измеритель постоянного напряжения с "hold " максимального напряжения
const int analogIn = PA7;
float U1 = 0.0;
float maxValue = 0;
int button = PB12;
#include <LiquidCrystal.h>
LiquidCrystal lcd(PA0, PA1, PA2, PA3, PA4, PA5);
float val = 0;// define the variable as value=0
void setup()
{
lcd.begin(16, 2);
pinMode(button, INPUT_PULLUP);
}
void loop()
{
val = analogRead(PA7);
U1 = (val * 3.3 / 4096.0 );
if (val > maxValue)
{
maxValue = val;
}
if (digitalRead(PB12) == LOW)
{
maxValue = 0;
}
lcd.clear();
lcd.setCursor(0,0); // Column, line
lcd.print("M1");
lcd.setCursor(0,1);
lcd.print(U1);
lcd.setCursor(9, 0);
lcd.print(maxValue* 3.3/4096.0 );
delay(200); //Wait for 200ms
}
добавил её до второй, но она не реагирует на изменение напряжения на PA7.
#include <LiquidCrystal.h>
LiquidCrystal lcd(PA0, PA1, PA2, PA3, PA4, PA5);
const int analogIn = PA7;
float U1 = 0.0;
float maxValue = 0;
float val = 0;// define the variable as value=0
int button = PB12;
int WhichScreen = 1; // This variable stores the current Screen number
boolean hasChanged = true;
int buttonState; // the current reading from the input pin
int lastButtonState = LOW; // the previous reading from the input pin
unsigned long lastDebounceTime = 0; // the last time the output pin was toggled
unsigned long debounceDelay = 50; // the debounce time; increase if the output flickers
void setup()
{
lcd.begin(16, 2);
pinMode(PB11, INPUT);
pinMode(button, INPUT_PULLUP);
}
void loop()
{
////////////
val = analogRead(PA7);
U1 = (val * 3.3 / 4096.0 );
if (val > maxValue)
{
maxValue = val;
}
if (digitalRead(PB12) == LOW)
{
maxValue = 0;
}
/*
lcd.print(" ");
lcd.setCursor(0, 0);
lcd.print(U1);
lcd.setCursor(9, 0);
lcd.print(maxValue* 3.3/4096.0 );
*/
// lcd.print(" ");
// delay(200); //Wait for 200ms
//////////////
if (hasChanged == true) {
switch (WhichScreen) {
case 1:
{
firstScreen();
}
break;
case 2:
{
secondScreen();
}
break;
case 3:
{
thirdScreen();
}
break;
case 4:
{
fourthScreen();
}
break;
case 5:
{
fifthScreen();
}
break;
case 6:
{
sixthScreen();
}
break;
case 0:
{
}
break;
}
}
//-------------------------------
// BEGIN of the switch debouncing code
int reading = digitalRead(PB11);
if (reading != lastButtonState) {
// reset the debouncing timer
lastDebounceTime = millis();
}
if ((millis() - lastDebounceTime) > debounceDelay) {
// whatever the reading is at, it's been there for longer
// than the debounce delay, so take it as the actual current state:
// if the button state has changed:
if (reading != buttonState) {
buttonState = reading;
// only toggle the LED if the new button state is HIGH
if (buttonState == HIGH) {
hasChanged = true;
WhichScreen++;
}
} else {
hasChanged = false;
}
}
lastButtonState = reading;
// END of the switch Debouncing code
// --------------------------------------
if (WhichScreen > 6) {
WhichScreen = 1;
}
}
void firstScreen()
{
lcd.clear();
lcd.setCursor(0, 0); // Column, line
lcd.print("M1");
lcd.setCursor(0, 1);
lcd.print(U1);
lcd.setCursor(9, 1);
lcd.print(maxValue * 3.3 / 4096.0 );
///////////
}
void secondScreen()
{
lcd.clear();
lcd.setCursor(0, 0); // Column, line
lcd.print("M2");
lcd.setCursor(0, 1);
lcd.print("M2 b");
}
void thirdScreen()
{
lcd.clear();
lcd.setCursor(0, 0); // Column, line
lcd.print("M3");
lcd.setCursor(0, 1);
lcd.print("M3b");
}
void fourthScreen()
{
lcd.clear();
lcd.setCursor(0, 0); // Column, line
lcd.print("M4");
lcd.setCursor(0, 1);
lcd.print("M4 b");
}
void fifthScreen()
{
lcd.clear();
lcd.setCursor(0, 0); // Column, line
lcd.print("M5");
lcd.setCursor(0, 1);
lcd.print("M5 b");
}
void sixthScreen()
{
lcd.clear();
lcd.setCursor(0, 0); // Column, line
lcd.print("M av");
lcd.setCursor(0, 1);
lcd.print("M avb");
}
Вот здесь всё мертво
void firstScreen()
{
lcd.clear();
lcd.setCursor(0, 0); // Column, line
lcd.print("M1");
lcd.setCursor(0, 1);
lcd.print(U1);
lcd.setCursor(9, 1);
lcd.print(maxValue * 3.3 / 4096.0 );
///////////
}