Advertisement
Bukisoh

Mot + Voltmetre + LCD

Feb 25th, 2019
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.12 KB | None | 0 0
  1. #include <Wire.h>
  2. #include <LiquidCrystal_I2C.h>
  3. #include <Servo.h>
  4.  
  5. LiquidCrystal_I2C lcd(0x27,20,4);
  6. Servo esc;   // Création de l'objet permettant le contrôle de l'ESC
  7.  
  8. int PWM = 0;
  9. float vout = 0.0;
  10. float vin = 0.0;
  11. float R1 = 997000.0;
  12. float R2 = 98500.0;
  13. float PWMA = 0.0;
  14.  
  15.  
  16. void setup() {
  17.   lcd.setCursor(0,0);
  18.   lcd.print("Ubat ");
  19.  
  20.   lcd.setCursor(1,0);
  21.   lcd.print("VMot ");
  22.  
  23.  
  24.   esc.attach(9); // On attache l'ESC au port numérique 9 (port PWM obligatoire)
  25.    
  26.    // Initialisation de l'ESC
  27.    //  (certains ESC ont besoin d'une "procédure d'initialisation"
  28.    //   pour devenir opérationnels - voir notice)
  29.     esc.write(0);
  30.     delay(1000);
  31.     esc.write(180);
  32.     delay(1000);
  33.     esc.write(0);
  34. }
  35.  
  36. void loop() {
  37.  
  38.  float value = analogRead(A0);
  39.  float PWM = analogRead(A1);
  40.  
  41.   vout = (value * 5.0) / 1024.0;  
  42.   vin = vout / (R2/(R1+R2));
  43.   vin = vin * 10;
  44.   vin = map(vin, 210, 294 , 0, 100);
  45.  
  46.  PWM = map(PWM, 0, 1024, 0, 179);
  47.  esc.write(PWM);
  48.  
  49. lcd.setCursor(0,5);
  50. lcd.print(vin);
  51.  
  52.  
  53. PWMA = map(PWM, 0, 179, 0,100);
  54. lcd.setCursor(1,5);
  55. lcd.print(PWMA);
  56.  
  57.  
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement