#ifndef _MICROPLC_h
#define _MICROPLC_h
#if defined(ARDUINO)&&ARDUINO>=100
#include"Arduino.h"
#else
#include"WProgram.h"
#endif
#define T10MS 1
#define T100MS 10
#define T1S 100
union m4bits{struct{unsigned _1:1;unsigned _2:1;unsigned _3:1;unsigned _4:1;};struct{unsigned x:4;};};class microPLC{public:microPLC();static unsigned int ms;void init(void);private:};class Counter{public:Counter();Counter(int n_,int fin_);void Set(bool s_);void N(int);int Con(void);void Reset(bool r_);bool Q(void);bool D(void);protected:int n;int con;int fin;bool q;bool s;bool r;};class CI:public Counter{public:CI():Counter(){i=0;};CI(int n_,int fin_):Counter(n_,fin_){i=0;};void Inc(bool i_);protected:bool i;};class CD:public Counter{public:CD():Counter(){d=0;};CD(int n_,int fin_):Counter(n_,fin_){d=0;};void Dec(bool d_);private:bool d;};class CID:public CI{public:CID():CI(){d=0;i=0;};CID(int n_,int fin_):CI(n_,fin_){d=0;i=0;};void Dec(bool d_);private:bool d;};class Timer{public:Timer();Timer(int t_,int tb_);void Time(int t_);void TBase(int tb_);void Reset(bool r_);bool T(void);protected:int tb;int t;int tt;bool q;bool s;bool r;bool on;unsigned int ms2;void timerAVR(void);};class TI:public Timer{public:TI(int t_,int tb_):Timer(t_,tb_){};void Set(bool s_);bool Q(void);private:void timer(void);};class TIP:public TI{public:TIP(int t_,int tb_):TI(t_,tb_){};void Set(bool s_);};class TRC:public TI{public:TRC(int t_,int tb_):TI(t_,tb_){};void Set(bool s_);bool Q(void);private:void timer(void);};class TRCM:public TRC{public:TRCM(int t_,int tb_):TRC(t_,tb_){};void Set(bool s_);};class TRD:public TIP{public:TRD(int t_,int tb_):TIP(t_,tb_){};void Set(bool s_);};class PULSE:public Timer{public:PULSE(int t_,int toff_,int tb_):Timer(t_,tb_){toff=toff_;n=0;};PULSE(int t_,int toff_,int tb_,int n_):Timer(t_,tb_){toff=toff_;n=n_;};PULSE(){toff=0;n=0;};void TOff(int t_);void N(int n_);void Set(bool s_);bool Q(void);unsigned int getN(void);private:int toff;int n;unsigned int nc;void timer(void);};extern microPLC MICROPLC;
#endif