#include "RegulationIntensite.h" #define __RESISTOR_VALUE__ 10000 #define __ANALOGIN_BR__ A0 #define __ANALOGIN_AR__ A1 #define __PWM_OUT__ 3 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 float curent; static int pwm_value = 0; curent = get_curent(); Serial.println(curent); if(curenttarget_curent) { pwm_value--; analogWrite(__PWM_OUT__, pwm_value); } delay(10); } float get_curent() { int b = analogRead(__ANALOGIN_BR__); int a = analogRead(__ANALOGIN_AR__); float dv = (b-a)*(5.0/1023.0) ; //Tension réel float curent = (dv/(float)__RESISTOR_VALUE__)*1000; //Serial.print(a);Serial.print(";");Serial.print(b);Serial.print(";");Serial.print(dv);Serial.print(";");Serial.print(curent);Serial.print(";"); return curent; }