Bugfixes in relais calss

This commit is contained in:
Jens Noack 2021-11-08 13:18:06 +01:00
parent ff64a36e20
commit 5f55011894
4 changed files with 55 additions and 48 deletions

View file

@ -2,6 +2,7 @@
#define __display_H__
#include "fonts.h"
#include <Wire.h>
#include "SSD1306Wire.h"
class display
@ -43,13 +44,15 @@ void display::_initDisplay()
{
//initialise OLED and display Welcome Message ...
_display->init();
_display->flipScreenVertically();
_display->setTextAlignment(TEXT_ALIGN_CENTER);
//_display->flipScreenVertically();
/* _display->setTextAlignment(TEXT_ALIGN_CENTER);
_display->setFont(Roboto_Condensed_Bold_16);
_display->clear();
_display->setContrast(MAX_CONTRAST);
_display->drawString(64, 32, "Itsblue.de");
_display->display();
*/
}
void display::header(String title, bool wificonected, bool localvalues, bool lastdatasent, bool timesynced)

View file

@ -1,38 +1,38 @@
#include <Arduino.h>
#include "train.h"
//#include "train.h"
#include "relais.h"
#include "taster.h"
#include "leds.h"
#include "mp3.h"
//#include "leds.h"
//#include "mp3.h"
#include "display.h"
#include "eeprom.h"
//#include "eeprom.h"
eeprom save;
//eeprom save;
///---- OLED ----
const size_t PIN_MONI_SDA = 21 ; //12
const size_t PIN_MONI_SCL = 22 ; //14
const size_t PIN_MONI_SDA = 25 ; //12
const size_t PIN_MONI_SCL = 26 ; //14
const unsigned int ADDR_MONI = 0x3c;
display moni(PIN_MONI_SDA, PIN_MONI_SCL, ADDR_MONI);
///---- MP3 ----
const size_t PIN_MP3_RX = 3 ; //D2;
const size_t PIN_MP3_TX = 1 ; //D3;
mp3 mp3ply(PIN_MP3_RX, PIN_MP3_TX);
//mp3 mp3ply(PIN_MP3_RX, PIN_MP3_TX);
///---- RELAIS ----
const size_t PIN_RELAIS_HAUESER = 9;
const size_t PIN_RELAIS_HAUESER = 18;
const size_t PIN_RELAIS_STERNE = 17;
const size_t PIN_RELAIS_SPIEGELBALL = 16;
const size_t PIN_RELAIS_OTHER = 4;
relais haeuser(PIN_RELAIS_HAUESER);
relais sterne(PIN_RELAIS_STERNE);
relais spiegel(PIN_RELAIS_SPIEGELBALL);
relais other(PIN_RELAIS_OTHER);
relais relais_haeuser(PIN_RELAIS_HAUESER);
relais relais_sterne(PIN_RELAIS_STERNE);
relais relais_spiegel(PIN_RELAIS_SPIEGELBALL);
relais relais_other(PIN_RELAIS_OTHER);
///---- Spannungsregler
const size_t PIN_TRAIN_UNTEN = 32;
const size_t PIN_TRAIN_OBEN = 33;
#define PWM_CHANNEL_OBEN 5
#define PWM_CHANNEL_UNTEN 6
train zugunten(PIN_TRAIN_UNTEN, PWM_CHANNEL_UNTEN );
train zugoben(PIN_TRAIN_OBEN, PWM_CHANNEL_OBEN );
//train zugunten(PIN_TRAIN_UNTEN, PWM_CHANNEL_UNTEN );
//train zugoben(PIN_TRAIN_OBEN, PWM_CHANNEL_OBEN );
///--- Taster ----
const size_t PIN_TASTER_AUSSEN_LICHT = 36;
const size_t PIN_TASTER_AUSSEN_MOVE = 39;
@ -46,8 +46,8 @@ taster taster_train_oben(PIN_TASTER_TRAIN_OBEN);
uint16_t rgbled_state_flag = 0;
const size_t PIN_RGBLEDS = 19;
#define NUMRGBLEDS 20
Adafruit_NeoPixel rgb_leds(NUMRGBLEDS, PIN_RGBLEDS, NEO_GRB + NEO_KHZ800);
//Adafruit_NeoPixel rgb_leds(NUMRGBLEDS, PIN_RGBLEDS, NEO_GRB + NEO_KHZ800);
enum led_t {LTANNE=1, LBACK=2, LSTERNE=4, LTEICH=8};
leds led_tanne(&rgb_leds, &rgbled_state_flag, LTANNE, 5000,220, 0, 5 );
leds led_teich(&rgb_leds, &rgbled_state_flag, LTEICH, 5000,220, 6, 10 );
//leds led_tanne(&rgb_leds, &rgbled_state_flag, LTANNE, 5000,220, 0, 5 );
//leds led_teich(&rgb_leds, &rgbled_state_flag, LTEICH, 5000,220, 6, 10 );

View file

@ -22,6 +22,7 @@ relais::relais(size_t ctrl_pin)
_ctrl_pin = ctrl_pin;
_relais_on = false;
pinMode(_ctrl_pin, OUTPUT);
off();
}
relais::~relais()
@ -30,13 +31,13 @@ relais::~relais()
void relais::on()
{
digitalWrite(_ctrl_pin, HIGH);
digitalWrite(_ctrl_pin, LOW);
_relais_on = true;
}
void relais::off()
{
digitalWrite(_ctrl_pin, LOW);
digitalWrite(_ctrl_pin, HIGH);
_relais_on = false;
}
@ -44,12 +45,12 @@ void relais::toggle()
{
if(true == _relais_on)
{
digitalWrite(_ctrl_pin, LOW);
digitalWrite(_ctrl_pin, HIGH);
_relais_on = false;
}
else
{
digitalWrite(_ctrl_pin, HIGH);
digitalWrite(_ctrl_pin, LOW);
_relais_on = true;
}
}

View file

@ -8,46 +8,48 @@ uint64_t licht_all_count = 0;
uint64_t move_all_count = 0;
void setup() {
Serial.begin(115200);
//load counters
save.set_int("licht", 0);
save.set_int("move", 0);
licht_all_count = save.get_int("licht");
move_all_count = save.get_int("move");
// save.set_int("licht", 0);
// save.set_int("move", 0);
// licht_all_count = save.get_int("licht");
// move_all_count = save.get_int("move");
// all relais off;
haeuser.off();
sterne.off();
spiegel.off();
other.off();
relais_haeuser.off();
relais_sterne.off();
relais_spiegel.off();
relais_other.off();
/*
zugoben.stop();
zugunten.stop();
led_tanne.setColor(0x0f0);
mp3ply.play(1);
*/
}
uint8_t licht_count = 0;
void loop() {
led_teich.rainbowCycle();
rgb_leds.show();
//led_teich.rainbowCycle();
//rgb_leds.show();
if(taster_aussen_licht.pressed())
{
licht_all_count++;
save.set_int("licht",licht_all_count);
licht_count++;
if(licht_count > 4)
licht_count = 1;
}
relais_haeuser.toggle();
if(taster_aussen_move.pressed())
{
move_all_count++;
save.set_int("move", move_all_count);
}
relais_other.toggle();
if(taster_train_oben.pressed())
relais_sterne.toggle();
if(taster_train_unten.pressed())
relais_spiegel.toggle();
/*
show_counters(licht_all_count, move_all_count);
switch (licht_count)
@ -83,12 +85,12 @@ void loop() {
other.off();
break;
}
*/
}
/*
void show_counters(uint64_t counter_licht, uint64_t counter_move)
{
moni.clear();
@ -96,4 +98,5 @@ void show_counters(uint64_t counter_licht, uint64_t counter_move)
moni.data(10,15,counter_licht, "Licht:");
moni.data(10,15,counter_move, "Moves:");
moni.show();
}
}
*/