Advertisement
Bukisoh

V6

May 27th, 2019
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.49 KB | None | 0 0
  1. #include <Servo.h>
  2. #include <Wire.h>
  3. #include <LiquidCrystal_I2C.h>
  4.  
  5.  
  6.  
  7. LiquidCrystal_I2C lcd(0x27,20,4);
  8. Servo esc;
  9.  
  10. char Str1[19];
  11. char Str2[21];
  12. char Str3[17];
  13. char Str4[19];
  14.  
  15.  
  16. void setup() {
  17.  
  18. esc.attach(9);
  19. }
  20.  
  21. void loop() {
  22.  
  23.  
  24.   sprintf(Str1, "Vitesse = %3d km/h", vitesse());
  25.    lcd.setCursor(0,0);
  26.    lcd.print(Str1);
  27.  
  28.   sprintf(Str2, "UBat = %.2f V/ %3d %", volt()/10,map(volt(),210,294,0,100));
  29.     lcd.setCursor(0,1);
  30.     lcd.print(Str2);
  31.  
  32.   sprintf(Str3, "Throttle : %3d %", PWM);
  33.     lcd.setCursor(0,2);
  34.     lcd.print(Str3);
  35.  
  36.   sprintf(Str4, "Autonomie %.2f km", autonomie());
  37.     lcd.setCursor(0,3);
  38.     lcd.print(Str4);
  39. }
  40.  
  41. float volt()
  42. {
  43.   float R1 = 997000.0;                                       // valeur resistance
  44.   float R2 = 98500.0;
  45.   float vout = 0.0;
  46.   float vin = 0.0;
  47.  
  48.      float value = analogRead(A0);
  49.  
  50.      vout = (value * 5.0) / 1024.0;  
  51.      vin = vout / (R2/(R1+R2));
  52.      vin = vin * 10;
  53.      vin = map(vin, 210, 294 , 0, 100);
  54.      vin = constrain(vin,0,100);
  55.         return vin;
  56. }  
  57. float PWM()
  58. {
  59.   float PWM = analogRead(A1);
  60.    
  61.     PWM = map(PWM, 0, 1024, 0, 179);
  62.     esc.write(PWM);
  63.     int PWMA = map(PWM,0 ,179,0 ,100);
  64.     return (PWMA);
  65. }
  66. int vitesse()
  67. {
  68.   vitesse;
  69.   return vitesse;
  70.   }
  71. float autonomie()
  72. {
  73.   autonomie=  (volt()*ampere);
  74.   }
  75.  
  76.   /*
  77.    * https://liudr.wordpress.com/2012/01/16/sprintf/
  78.    * https://arduino.stackexchange.com/questions/19234/print-string-and-integer-lcd
  79.   */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement