This commit is contained in:
Adrien VAN DAMME 2017-02-09 14:12:10 +01:00
parent b694b5fed3
commit 284f89dc62
1 changed files with 16 additions and 5 deletions

View File

@ -5,32 +5,43 @@
#define __ANALOGIN_AR__ A1
#define __PWM_OUT__ 3
float target_curent = 0;
float target_curent = 0.05;//ma
void setup()
{
pinMode(__ANALOGIN_AR__,0);
pinMode(__ANALOGIN_BR__,0);
pinMode(__PWM_OUT__,1);
digitalWrite(__PWM_OUT__, 122);
Serial.begin(9600);
}
void loop()
{
static int curent;
static float curent;
static int pwm_value = 0;
curent = get_curent();
Serial.println(pwm_value);
if(curent<target_curent*0.9)
{
pwm_value++;
analogWrite(__PWM_OUT__, pwm_value);
}
else if(curent>target_curent)
{
pwm_value--;
analogWrite(__PWM_OUT__, pwm_value);
}
delay(50);
}
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__;
float dv = (b-a)*(5.0/1023.0) ; //Tension réel
float curent = (dv/(float)__RESISTOR_VALUE__)*100;
Serial.print(a);Serial.print(";");Serial.print(b);Serial.print(";");Serial.print(dv);Serial.print(";");Serial.print(curent);Serial.print(";");
return curent;
}