first
This commit is contained in:
		
							
								
								
									
										6
									
								
								RegulationIntensite.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										6
									
								
								RegulationIntensite.h
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,6 @@
 | 
			
		||||
#ifndef REGULATIONINTENSITE_H
 | 
			
		||||
#define REGULATIONINTENSITE_H
 | 
			
		||||
 | 
			
		||||
float get_curent();
 | 
			
		||||
 | 
			
		||||
#endif
 | 
			
		||||
@@ -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__;
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user