2 LEDD проблема

Тед
Offline
Зарегистрирован: 06.11.2017
Здравствуйте 
Могу включить каждый отдельно, но когда включаю диод на БД14 второй не включается.
 
#include "EmonLib.h"              // Include Emon Library
EnergyMonitor emon1;              // Create an instance
#include <LiquidCrystal.h>
LiquidCrystal lcd(PA0, PA1, PA2, PA3, PA4, PA5);

const int ResetPin = PB12;
const int numReadings = 50;
int LED =  PB15;
int LED2 =  PB14;
int readings[numReadings];      // the readings from the analog input
int readIndex = 0;              // the index of the current reading
int total = 0;                  // the running total
int average = 0;                // the average
int inputPin = PA7;
int analogInput = PB0;
int value = 0;
float vout = 0.0;
float vin = 0.0;
float Vo;
float Irms = 0.0;
//float Vo;
float Io;

void setup()
{
  // initialize all the readings to 0:
  for (int thisReading = 0; thisReading < numReadings; thisReading++) {
    readings[thisReading] = 0;
  }
  pinMode(PB15, OUTPUT);  // LED
  pinMode(PB14, OUTPUT);  // LED2
  pinMode(ResetPin, INPUT_PULLDOWN);
  pinMode(PA7, INPUT);    // AC
  pinMode(PB0, INPUT_ANALOG); //DC

  lcd.begin(16, 2);

  //emon1.voltage(PA7, 234.26, 1.7);  // Voltage: input pin, calibration, phase_shift
  emon1.current(PA7, 2.8);
  

}

void loop()

{
  emon1.calcVI(20, 2000);

  if (digitalRead(ResetPin) == HIGH)
  {
    Io =  emon1.Irms;
  }
  else
  {
{
    // subtract the last reading:
    total = total - readings[readIndex];
  // read from the sensor:
  readings[readIndex] = analogRead(inputPin);
  // add the reading to the total:
  total = total + readings[readIndex];
  // advance to the next position in the array:
  readIndex = readIndex + 1;
}
  // if we're at the end of the array...
  if (readIndex >= numReadings) {
    // ...wrap around to the beginning:
    readIndex = 0;
  }
  }
  // calculate the average:
  average = total / numReadings;
  // send it to the computer as ASCII digits
  Serial.println(average);
  delay(1);
 
  if (digitalRead(ResetPin) == HIGH)
    //(digitalRead(ResetPin) == HIGH)
  {
    Vo = vin;

  }
  else {
    // read the value at analog input
    value = analogRead(analogInput);
    vout = (value * 3.3) / 4190.0; // 4200
    vin = vout;
    if (vin < 0.09)
      vin = 0.0; //statement to quash undesired reading !
  }

  float Irms = emon1.Irms;

  //if (Irms - Vo <= 0.90 && Irms - Vo >= 0.100) // delta 0.3
  if (Irms - Io <= 0.90 && Irms - Io >= 0.100) //  AC

  {
    digitalWrite(PB15, HIGH);
    LED = 1;

  }
  else
  {
    digitalWrite(PB15, LOW);
    LED = 0;

  }

  if (vin - Vo <= 0.4 && vin - Vo >= 0.1)         // DC
    // if(vin-Vo<= 1.20 && vin-Vo >= 1.00)
  {
    digitalWrite(PB14, HIGH);
    LED2 = 1;

  }
  else
  {
    digitalWrite(PB14, LOW);
    LED2 = 0;

  }
///////////////////////////////////////////////////////////////////////////////
  lcd.setCursor(0, 1);
  lcd.print(vin);
  lcd.setCursor(5, 1);
  lcd.print("o");
  lcd.print(Vo, 2);
  lcd.setCursor(11, 1);
  lcd.print (vin - Vo);

  //delay(500);
  lcd.setCursor(0, 0);
  lcd.print(Irms);
  lcd.setCursor(5, 0);
  lcd.print("o");
  lcd.print(Io, 2);
  lcd.setCursor(11, 0);
  lcd.print (Irms - Io);
}

 

 

asam
asam аватар
Offline
Зарегистрирован: 12.12.2018

А можно расшивровать "когда включаю диод на БД14 второй не включается." ?

Тед
Offline
Зарегистрирован: 06.11.2017

Исправление 

БД14 = LED2 =  PB14;

asam
asam аватар
Offline
Зарегистрирован: 12.12.2018

Ну я догадался, что БД14 это PB14. Вопросы

- Каким образом происходит " включаю диод на БД14" ?

- Почему при этом должен включаться второй? Может просто условие в 109 строчке не выполняется?

Тед
Offline
Зарегистрирован: 06.11.2017
Есть два входа, когда первое напряжение  попаает в пределы строки 95, LED включаеться, когда втарое в пределы строки 109, LED 2 включается.  
Диоды должны работать независимо , но так не получается. Первая диода мешает второй.
 
asam
asam аватар
Offline
Зарегистрирован: 12.12.2018

Добавь между 107 и 109 строкой

Serial.print("Vin=");
Serial.print(vin);
Serial.print(" Vo=");
Serial.println(Vo);

И посмотри в сериал мониторе какие там значения.

Тед
Offline
Зарегистрирован: 06.11.2017

эти значения я вижу на LCD

asam
asam аватар
Offline
Зарегистрирован: 12.12.2018

Ну, и какие они?

Тед
Offline
Зарегистрирован: 06.11.2017

Они как у обычного вольтметра , работают как надо, проблема только с LED.

asam
asam аватар
Offline
Зарегистрирован: 12.12.2018

Значения vin - Vo в диапазоне 0.1 - 0.4 есть?

Исправь 109 строчку на 

 if (((vin - Vo) <= 0.4) && ((vin - Vo) >= 0.1)) 

 

 

Тед
Offline
Зарегистрирован: 06.11.2017
Диоды включаются правильно отельно.
Включаю только первый LED = хорошо, выключаю его и включаю второй LED2 = хорошо.
Проблема - 
включаю перый LED и хочу второй  LED2, но он не включается.
Тед
Offline
Зарегистрирован: 06.11.2017

сообщение #9 = ничего не изменилось