Program pre arduino

C++, C#, Visual Basic, Delphi, Perl a ostatní

Moderátor: Moderátoři Živě.cz

Odeslat příspěvekod pitopit 24. 5. 2020 21:53

Zdravím,vedel by mi niekto poradiť s úpravou programu pre arduino?Keď aj za nejakú odmenu.
Prípadne na niekoho kontakt kto by mi s tým pomohol.
Jedná sa o jednoduchý program pre akvárium.
Ja sa do programovania nejak extra nerozumiem.
Potreboval by som aby príkaz na PWM mosfet 1.Hnojenie 12V sa nezapínal každý deň ale len v nastavený deň.
Kód: Vybrat vše
//Nastavení-5x rele a hodiny rtc 3231

#include <Wire.h>
#include <DS3231.h>
#define DS3231_I2C_ADDRESS 0x68

int rele1 = 3;  // SSR rele 1 - pin 3 svetlo
int rele2 = 4;  // SSR rele 2 - pin 4 CO2
int rele3 = 5;  // SSR rele 3 - pin 5 hladin.čistič
int rele4 = 6;  // Mosfet  rele 4 - pin 6 hnojenie
int rele5 = 7;  // Mosfet rele 5 - pin 7 elektrolýza


// Convert normal decimal numbers to binary coded decimal
byte decToBcd(byte val)
{
  return ( (val / 10 * 16) + (val % 10) );
}
// Convert binary coded decimal to normal decimal numbers
byte bcdToDec(byte val)
{
  return ( (val / 16 * 10) + (val % 16) );
}

void setup()
{
  Wire.begin();
  Serial.begin(9600);
   //set the initial time here:
   //DS3231 seconds, minutes, hours, day, date, month, year
   //setDS3231time(00,38,17,1,4,6,18);   //  Nastavení hodin

  pinMode(rele1, OUTPUT);
  pinMode(rele2, OUTPUT);
  pinMode(rele3, OUTPUT);
  pinMode(rele4, OUTPUT);
  pinMode(rele5, OUTPUT);
 
  digitalWrite(3, HIGH);
  digitalWrite(4, HIGH);
  digitalWrite(5, HIGH);
  digitalWrite(6, LOW);
  digitalWrite(7, LOW);
}
void setDS3231time(byte second, byte minute, byte hour, byte dayOfWeek, byte
                   dayOfMonth, byte month, byte year)
{
  // sets time and date data to DS3231
  Wire.beginTransmission(DS3231_I2C_ADDRESS);
  Wire.write(0); // set next input to start at the seconds register
  Wire.write(decToBcd(30)); // set seconds
  Wire.write(decToBcd(28)); // set minutes
  Wire.write(decToBcd(17)); // set hours
  Wire.write(decToBcd(7)); // set day of week (1=Sunday, 7=Saturday)
  Wire.write(decToBcd(6)); // set date (1 to 31)
  Wire.write(decToBcd(8)); // set month
  Wire.write(decToBcd(16)); // set year (0 to 99)
  Wire.endTransmission();
}
void readDS3231time(byte *second,
                    byte *minute,
                    byte *hour,
                    byte *dayOfWeek,
                    byte *dayOfMonth,
                    byte *month,
                    byte *year)
{
  Wire.beginTransmission(DS3231_I2C_ADDRESS);
  Wire.write(0); // set DS3231 register pointer to 00h
  Wire.endTransmission();
  Wire.requestFrom(DS3231_I2C_ADDRESS, 7);
  // request seven bytes of data from DS3231 starting from register 00h
  *second = bcdToDec(Wire.read() & 0x7f);
  *minute = bcdToDec(Wire.read());
  *hour = bcdToDec(Wire.read() & 0x3f);
  *dayOfWeek = bcdToDec(Wire.read());
  *dayOfMonth = bcdToDec(Wire.read());
  *month = bcdToDec(Wire.read());
  *year = bcdToDec(Wire.read());
}
void displayTime()
{
  byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;
  // retrieve data from DS3231
  readDS3231time(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month, &year);
  // send it to the serial monitor
  Serial.print(hour, DEC);
  // convert the byte variable to a decimal number when displayed
  Serial.print(":");
  if (minute < 10)
  {
    Serial.print("0");
  }
  Serial.print(minute, DEC);
  Serial.print(":");
  if (second < 10)
  {
    Serial.print("0");
  }
  Serial.print(second, DEC);
  Serial.print("   ");
  Serial.print(dayOfMonth, DEC);
  Serial.print("/");
  Serial.print(month, DEC);
  Serial.print("/");
  Serial.print(year, DEC);
  Serial.print("  Den: ");
  switch (dayOfWeek) {
    case 7:
      Serial.println("Neděle");
      break;
    case 1:
      Serial.println("Pondělí");
      break;
    case 2:
      Serial.println("Uterý");
      break;
    case 3:
      Serial.println("Středa");
      break;
    case 4:
      Serial.println("Čtvrtek");
      break;
    case 5:
      Serial.println("Pátek");
      break;
    case 6:
      Serial.println("Sobota");
      break;
  }
}
void loop()
{
  displayTime();

  byte s, m, h, dvt, dvm, mesic, r;
  readDS3231time(&s, &m, &h, &dvt, &dvm, &mesic, &r);


  //--------------------------------------------------------------------------------
  //      Nastavení času a vteřin sepnutí SSR relé 1-Svetlo

  if (h == 11 && m == 00 && s <= 0) {
    digitalWrite(rele1, LOW);  //rele zapne
  }
  if (h == 21 && m == 00 && s >= 0) {  // 00 vteřin
    digitalWrite(rele1, HIGH);  //rele vypne
  }
  //-----------------------------------------------------------------------------
  //                 SSR relé č. 2        CO2
  if (h == 9 && m == 00 && s <= 0) {
    digitalWrite(rele2, LOW);  //rele zapne
  }
  if (h == 21 && m == 00 && s >= 0) { // 8 vteřin
    digitalWrite(rele2, HIGH);  //rele vypne
  }
  //--------------------------------------------------------------------------------
  //                  SSR relé č.3 Filter-hladinový čistič

  if (h == 10  && m == 30 && s <= 0) {
    digitalWrite(rele3, LOW);  //rele zapne
  }
  if (h == 10 && m == 45 && s >= 0) { // 0 vteřin
    digitalWrite(rele3, HIGH);  //rele vypne
  }
  if (h == 13  && m == 00 && s <= 0) {
    digitalWrite(rele3, LOW);  //rele zapne
  }
  if (h == 13 && m == 10 && s >= 0) { // 0 vteřin
    digitalWrite(rele3, HIGH);  //rele vypne
  }
  if (h == 15  && m == 00 && s <= 0) {
    digitalWrite(rele3, LOW);  //rele zapne
  }
  if (h == 15 && m == 10 && s >= 0) { // 0 vteřin
    digitalWrite(rele3, HIGH);  //rele vypne
  }
  if (h == 17  && m == 00 && s <= 0) {
    digitalWrite(rele3, LOW);  //rele zapne
  }
  if (h == 17 && m == 10 && s >= 0) { // 0 vteřin
    digitalWrite(rele3, HIGH);  //rele vypne
  }
 
  if (h == 19  && m == 00 && s <= 0) {
    digitalWrite(rele3, LOW);  //rele zapne
  }
  if (h == 19 && m == 10 && s >= 0) { // 0 vteřin
    digitalWrite(rele3, HIGH);  //rele vypne
  }
 
  if (h == 21  && m == 00 && s <= 0) {
    digitalWrite(rele3, LOW);  //rele zapne
  }
  if (h == 21 && m == 20 && s >= 0) { // 0 vteřin
    digitalWrite(rele3, HIGH);  //rele vypne
  }
  //---------------------------------------------------------------------------------
  //                   PWM mosfet 1.Hnojenie 12V

  if (h == 9  && m == 30 && s <= 0) {
    digitalWrite(rele4, HIGH);  //rele zapne
  }
  if (h == 9 && m == 30 && s >= 20) { // 10 vteřin
    digitalWrite(rele4, LOW);  //rele vypne
  }
  //---------------------------------------------------------------------------------
  //                    PWM mosfet 2.Elektrolýza.14x po 30 sekúnd

  if (h == 9  && m == 00 && s <= 0) {
    digitalWrite(rele5, HIGH);  //rele zapne
  }
  if (h == 9 && m == 00 && s >= 30) { // 10 vteřin
    digitalWrite(rele5, LOW);  //rele vypne
  }
  if (h == 10  && m == 00 && s <= 0) {
    digitalWrite(rele5, HIGH);  //rele zapne
  }
  if (h == 10 && m == 00 && s >= 30) { // 10 vteřin
    digitalWrite(rele5, LOW);  //rele vypne
  }
  if (h == 11  && m == 00 && s <= 0) {
    digitalWrite(rele5, HIGH);  //rele zapne
  }
  if (h == 11 && m == 00 && s >= 30) { // 10 vteřin
    digitalWrite(rele5, LOW);  //rele vypne
  }
  if (h == 12  && m == 00 && s <= 0) {
    digitalWrite(rele5, HIGH);  //rele zapne
  }
  if (h == 12 && m == 00 && s >= 30) { // 10 vteřin
    digitalWrite(rele5, LOW);  //rele vypne
  }
  if (h == 13  && m == 00 && s <= 0) {
    digitalWrite(rele5, HIGH);  //rele zapne
  }
  if (h == 13 && m == 00 && s >= 30) { // 10 vteřin
    digitalWrite(rele5, LOW);  //rele vypne
  }
  if (h == 14  && m == 00 && s <= 0) {
    digitalWrite(rele5, HIGH);  //rele zapne
  }
  if (h == 14 && m == 00 && s >= 30) { // 10 vteřin
    digitalWrite(rele5, LOW);  //rele vypne
  }
  if (h == 15  && m == 00 && s <= 0) {
    digitalWrite(rele5, HIGH);  //rele zapne
  }
  if (h == 15 && m == 00 && s >= 30) { // 10 vteřin
    digitalWrite(rele5, LOW);  //rele vypne
  }
  if (h == 16  && m == 00 && s <= 0) {
    digitalWrite(rele5, HIGH);  //rele zapne
  }
  if (h == 16 && m == 00 && s >= 30) { // 10 vteřin
    digitalWrite(rele5, LOW);  //rele vypne
  }
  if (h == 17  && m == 00 && s <= 0) {
    digitalWrite(rele5, HIGH);  //rele zapne
  }
  if (h == 17 && m == 00 && s >= 30) { // 10 vteřin
    digitalWrite(rele5, LOW);  //rele vypne
  }
  if (h == 18  && m == 00 && s <= 0) {
    digitalWrite(rele5, HIGH);  //rele zapne
  }
  if (h == 18 && m == 00 && s >= 30) { // 10 vteřin
    digitalWrite(rele5, LOW);  //rele vypne
  }
  if (h == 19  && m == 00 && s <= 0) {
    digitalWrite(rele5, HIGH);  //rele zapne
  }
  if (h == 19 && m == 00 && s >= 30) { // 10 vteřin
    digitalWrite(rele5, LOW);  //rele vypne
  }
  if (h == 20  && m == 00 && s <= 0) {
    digitalWrite(rele5, HIGH);  //rele zapne
  }
  if (h == 20 && m == 00 && s >= 30) { // 10 vteřin
    digitalWrite(rele5, LOW);  //rele vypne
  }
  if (h == 21  && m == 00 && s <= 0) {
    digitalWrite(rele5, HIGH);  //rele zapne
  }
  if (h == 21 && m == 00 && s >= 30) { // 10 vteřin
    digitalWrite(rele5, LOW);  //rele vypne
  }
//---------------------------------------------------------------------------------
delay(1000);
}
pitopit
Kolemjdoucí

Odeslat příspěvekod soban 25. 5. 2020 00:30

//---------------------------------------------------------------------------------
// PWM mosfet 1.Hnojenie 12V

if (h == 9 && m == 30 && s <= 0 && dvt == 1) {
digitalWrite(rele4, HIGH); //rele zapne
}
if (h == 9 && m == 30 && s >= 20) { // 10 vteřin
digitalWrite(rele4, LOW); //rele vypne
}
//---------------------------------------------------------------------------------


Zapne se pouze v Sunday (1=Sunday, 7=Saturday)
/----------------------------------------\
| Petr Šobáň |
| Olomouc |
\----------------------------------------/
soban
Pokročilý


Kdo je online

Uživatelé procházející toto fórum: Žádní registrovaní uživatelé a 0 návštevníků