Changeset 19 for trunk/Arduino/projects


Ignore:
Timestamp:
Sep 10, 2019, 11:24:05 AM (7 years ago)
Author:
markus
Message:

+ Activity/status display in loop
+ Activity LED (D9)
+ Prototype for temerature sensor (A2)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Arduino/projects/OT_boiler/OT_boiler.ino

    r15 r19  
    22#include <Ethernet.h>
    33#include <OT_Slave.h>
     4
     5//#define ACTIVITY_LED_PIN  LED_BUILTIN
     6#define ACTIVITY_LED_PIN  9
     7
     8#define USE_ETHERNET  0
    49
    510#define CONSOLE(cmd)  do { if (Serial) Serial.cmd; } while (0)
    … …  
    914byte  mac[] = { 0x02, 0xDE, 0xAD, 0xDE, 0xAD, 0x01 };
    1015byte  server[] = { 192, 168, 0, 22 };
     16
    1117volatile long  loops = 0;
     18volatile unsigned long msTicks = 0;
     19
    1220volatile long  state = 0;
    1321volatile bool  _connected = false;
    1422
    15 OT_Slave boiler;
     23OT_Slave        boiler;
    1624
    17 EthernetClient client;
     25EthernetClient  client;
    1826
    1927void setup()
    2028{
     29  msTicks = millis();
     30  digitalWrite(ACTIVITY_LED_PIN, LOW);  // Built-in LED off
     31  pinMode(ACTIVITY_LED_PIN, OUTPUT);            // Built-in LED active
    2132  // Console
    2233  Serial.begin(19200);
    2334  CONSOLE(println("\nSystem starting..."));
    2435  // Setup OT
    25   CONSOLE(print("OpenTherm.setup..."));
     36  CONSOLE(print("OpenTherm.begin..."));
    2637  boiler.begin(Sent_OT_Data);
    2738  CONSOLE(println("done"));
     39#if USE_ETHERNET
    2840  // Setup Ethernet
    2941  CONSOLE(print("Ethernet.begin..."));
    3042  Ethernet.begin(mac);
    3143  CONSOLE(println("done"));
     44#else
     45  CONSOLE(println("Ethernet is disabled!"));
     46#endif
    3247}
    3348
    … …  
    4257  Serial.println("]");
    4358*/
     59  msTicks = millis();
     60#if USE_ETHERNET
    4461  maintainEthernet();
     62#endif
    4563  boiler.maintain();
    46 /*
    47   delay(1000);
    48 */
     64#ifdef _NEVER_
     65  unsigned long base = boiler.IsActive() ? 500 : 3000;
     66  unsigned long periode = msTicks / base;
     67  int led = (periode & 1) ? HIGH : LOW;
     68  if (Serial) {
     69          static unsigned long prev = 0;
     70          if (prev != periode) {
     71                  prev = periode;
     72                  Serial.print("Time: ");
     73                  Serial.print(msTicks);
     74                  Serial.print("\tPeriode: ");
     75                  Serial.print(periode);
     76                  Serial.print("\tLED: ");
     77                  Serial.println(led);
     78          }
     79  }
     80  digitalWrite(ACTIVITY_LED_PIN, led);
     81  //digitalWrite(ACTIVITY_LED_PIN, boiler.IsActive() ? HIGH : LOW);
     82#else
     83  unsigned long periode = msTicks / (boiler.IsActive() ? 500 : 2000);
     84  static unsigned long prev = 0;
     85
     86  int a2 = analogRead(A2);   // read the input pin
     87#ifdef _R9_22K_
     88  const double m = 0.1309;
     89  const double b = -9.4535;
     90#elif defined(_R9_15K_1_)
     91  const double m = 0.1746;
     92  const double b = -13.164;
     93#else
     94  const double m = 0.1848;
     95  const double b = (-12.936 - 5.5);
     96#endif
     97  double ta2 = m*double(a2)+b;
     98 
     99  if (prev != periode) {
     100          prev = periode;
     101          int led = (periode & 1) ? HIGH : LOW;
     102          if (Serial) {
     103                  Serial.print("Time: ");
     104                  Serial.print(msTicks);
     105                  Serial.print("\tPeriode: ");
     106                  Serial.print(periode);
     107                  Serial.print("\tLED: ");
     108                  Serial.print(led);
     109      Serial.print("\tA2: ");
     110      Serial.print(a2);
     111      Serial.print("\tT(A2): ");
     112      Serial.println(ta2);
     113          }
     114          digitalWrite(ACTIVITY_LED_PIN, led);
     115  }
     116#endif
    49117}
    50118
Note: See TracChangeset for help on using the changeset viewer.