#include #include "arduino.h" #include "mesure.h" courant::courant(uint8_t pinU1, uint8_t pinU2, int r) { this->pinU1 = pinU1; this->pinU2 = pinU2; this->r = r; pinMode(pinU1, 0); pinMode(pinU2, 0); bridgeU1Enable = 0; bridgeU2Enable = 0; bridgeU1RapportR = 1; bridgeU2RapportR = 1; } courant::courant(uint8_t pinU1, uint8_t pinU2, int r, uint8_t bridgeU1Enable, uint8_t bridgeU2Enable,...) { this->pinU1 = pinU1; this->pinU2 = pinU2; this->r = r; pinMode(pinU1, 0); pinMode(pinU2, 0); this->bridgeU1Enable = bridgeU1Enable; this->bridgeU2Enable = bridgeU2Enable; va_list ap; va_start(ap, bridgeU2Enable); if(bridgeU1Enable) { this->bridgeU1Enable = bridgeU1Enable; this->bridgeU2Enable = bridgeU2Enable; bridgeU1RapportR = va_arg(ap, double); if(bridgeU2Enable) bridgeU2RapportR = va_arg(ap, double); else bridgeU2RapportR = 1; } else { this->bridgeU1Enable = 1; this->bridgeU2Enable = bridgeU2Enable; bridgeU1RapportR = 1; if(bridgeU2Enable) bridgeU2RapportR = va_arg(ap, double); else bridgeU2RapportR = 1; } va_end(ap); } void courant::config(uint8_t pinU1, uint8_t pinU2, int r) { this->pinU1 = pinU1; this->pinU2 = pinU2; this->r = r; pinMode(pinU1, 0); pinMode(pinU2, 0); bridgeU1Enable = 0; bridgeU2Enable = 0; bridgeU1RapportR = 1; bridgeU2RapportR = 1; } void courant::config(uint8_t pinU1, uint8_t pinU2, int r, uint8_t bridgeU1Enable, uint8_t bridgeU2Enable, ...) { this->pinU1 = pinU1; this->pinU2 = pinU2; this->r = r; pinMode(pinU1, 0); pinMode(pinU2, 0); this->bridgeU1Enable = bridgeU1Enable; this->bridgeU2Enable = bridgeU2Enable; va_list ap; va_start(ap, bridgeU2Enable); if(bridgeU1Enable) { this->bridgeU1Enable = bridgeU1Enable; this->bridgeU2Enable = bridgeU2Enable; bridgeU1RapportR = va_arg(ap, double); if(bridgeU2Enable) bridgeU2RapportR = va_arg(ap, double); else bridgeU2RapportR = 1; } else { this->bridgeU1Enable = 1; this->bridgeU2Enable = bridgeU2Enable; bridgeU1RapportR = 1; if(bridgeU2Enable) bridgeU2RapportR = va_arg(ap, double); else bridgeU2RapportR = 1; } va_end(ap); } void courant::lireTension() { u1RAW = analogRead(pinU1); u2RAW = analogRead(pinU2); u1 = (u1RAW*(5.0/1024.0))*(1/bridgeU1RapportR); u2 = (u2RAW*(5.0/1024.0))*(1/bridgeU2RapportR); } double courant::lireCourant() { lireTension(); double i = ((u1-u2)/(double)r)*1000; return i; } double courant::lireTensionU1() { return u1; } double courant::lireTensionU2() { return u2; }