Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Servo.h>
- #include <Wire.h>
- #include <LiquidCrystal_I2C.h>
- LiquidCrystal_I2C lcd(0x27,20,4);
- Servo esc;
- char Str1[19];
- char Str2[21];
- char Str3[17];
- char Str4[19];
- void setup() {
- esc.attach(9);
- }
- void loop() {
- sprintf(Str1, "Vitesse = %3d km/h", vitesse());
- lcd.setCursor(0,0);
- lcd.print(Str1);
- sprintf(Str2, "UBat = %.2f V/ %3d %", volt()/10,map(volt(),210,294,0,100));
- lcd.setCursor(0,1);
- lcd.print(Str2);
- sprintf(Str3, "Throttle : %3d %", PWM);
- lcd.setCursor(0,2);
- lcd.print(Str3);
- sprintf(Str4, "Autonomie %.2f km", autonomie());
- lcd.setCursor(0,3);
- lcd.print(Str4);
- }
- float volt()
- {
- float R1 = 997000.0; // valeur resistance
- float R2 = 98500.0;
- float vout = 0.0;
- float vin = 0.0;
- float value = analogRead(A0);
- vout = (value * 5.0) / 1024.0;
- vin = vout / (R2/(R1+R2));
- vin = vin * 10;
- vin = map(vin, 210, 294 , 0, 100);
- vin = constrain(vin,0,100);
- return vin;
- }
- float PWM()
- {
- float PWM = analogRead(A1);
- PWM = map(PWM, 0, 1024, 0, 179);
- esc.write(PWM);
- int PWMA = map(PWM,0 ,179,0 ,100);
- return (PWMA);
- }
- int vitesse()
- {
- vitesse;
- return vitesse;
- }
- float autonomie()
- {
- autonomie= (volt()*ampere);
- }
- /*
- * https://liudr.wordpress.com/2012/01/16/sprintf/
- * https://arduino.stackexchange.com/questions/19234/print-string-and-integer-lcd
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement