This commit is contained in:
Adrien Van 2017-02-08 00:45:16 +01:00
parent 9b15b4709d
commit b694b5fed3
2 changed files with 42 additions and 0 deletions

6
RegulationIntensite.h Normal file
View File

@ -0,0 +1,6 @@
#ifndef REGULATIONINTENSITE_H
#define REGULATIONINTENSITE_H
float get_curent();
#endif

View File

@ -0,0 +1,36 @@
#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__;
}