Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Wire.h>
- #include <LiquidCrystal_I2C.h>
- #include <Servo.h>
- LiquidCrystal_I2C lcd(0x27,20,4);
- Servo esc; // Création de l'objet permettant le contrôle de l'ESC
- int PWM = 0;
- float vout = 0.0;
- float vin = 0.0;
- float R1 = 997000.0;
- float R2 = 98500.0;
- float PWMA = 0.0;
- void setup() {
- lcd.setCursor(0,0);
- lcd.print("Ubat ");
- lcd.setCursor(1,0);
- lcd.print("VMot ");
- esc.attach(9); // On attache l'ESC au port numérique 9 (port PWM obligatoire)
- // Initialisation de l'ESC
- // (certains ESC ont besoin d'une "procédure d'initialisation"
- // pour devenir opérationnels - voir notice)
- esc.write(0);
- delay(1000);
- esc.write(180);
- delay(1000);
- esc.write(0);
- }
- void loop() {
- float value = analogRead(A0);
- float PWM = analogRead(A1);
- vout = (value * 5.0) / 1024.0;
- vin = vout / (R2/(R1+R2));
- vin = vin * 10;
- vin = map(vin, 210, 294 , 0, 100);
- PWM = map(PWM, 0, 1024, 0, 179);
- esc.write(PWM);
- lcd.setCursor(0,5);
- lcd.print(vin);
- PWMA = map(PWM, 0, 179, 0,100);
- lcd.setCursor(1,5);
- lcd.print(PWMA);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement