From b694b5fed3185041f1b860922f5370dfee808174 Mon Sep 17 00:00:00 2001 From: Adrien Van Date: Wed, 8 Feb 2017 00:45:16 +0100 Subject: [PATCH] first --- RegulationIntensite.h | 6 ++++++ RegulationIntensite.ino | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 RegulationIntensite.h diff --git a/RegulationIntensite.h b/RegulationIntensite.h new file mode 100644 index 0000000..ebf5fa4 --- /dev/null +++ b/RegulationIntensite.h @@ -0,0 +1,6 @@ +#ifndef REGULATIONINTENSITE_H +#define REGULATIONINTENSITE_H + +float get_curent(); + +#endif diff --git a/RegulationIntensite.ino b/RegulationIntensite.ino index e69de29..ee21e97 100644 --- a/RegulationIntensite.ino +++ b/RegulationIntensite.ino @@ -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(curenttarget_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__; +}