RegulationIntensite/RegulationIntensite.ino

37 lines
713 B
C++

#include "RegulationIntensite.h"
#define __RESISTOR_VALUE__ 10000
#define __ANALOGIN_BR__ A0
#define __ANALOGIN_AR__ A1
#define __PWM_OUT__ 3
float target_curent = 0;
void setup()
{
pinMode(__ANALOGIN_AR__,0);
pinMode(__ANALOGIN_BR__,0);
pinMode(__PWM_OUT__,1);
Serial.begin(9600);
}
void loop()
{
static int curent;
static int pwm_value = 0;
curent = get_curent();
if(curent<target_curent*0.9)
pwm_value++;
else if(curent>target_curent)
pwm_value--;
analogWrite(__PWM_OUT__, pwm_value);
}
float get_curent()
{
int b = analogRead(__ANALOGIN_BR__);
int a = analogRead(__ANALOGIN_AR__);
float dv = (a-b)*(5.0/1023.0) ; //Tension réel
return dv/(float)__RESISTOR_VALUE__;
}