Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Servo.h>
- #include <Wire.h>
- #include <LiquidCrystal_I2C.h>
- #include <vesc_uart.h>
- #include <datatypes.h>
- LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
- Servo esc;
- char Str1[20];
- char Str2[21];
- char Str3[21];
- char Str4[21];
- bool etat=false;
- int chrono=0;
- int temps=0;
- double vitesse=0;
- int hallSensorPin=2;
- volatile int compteur=0;
- char str_vitesse[10];
- void setup() {
- Serial.begin(115200);
- lcd.begin(20,4);
- esc.attach(9);
- pinMode(hallSensorPin, INPUT);
- attachInterrupt(0,detectaimant,LOW);
- }
- struct bldcMeasure measuredValues;
- void loop() {
- if (VescUartGetValue(measuredValues)) {
- Serial.print("Loop: ");
- SerialPrint(measuredValues);
- }
- else
- {
- Serial.println("Failed to get data!");
- }
- chrono=millis();
- if (etat == true) {
- etat=false;
- chrono = chrono - temps;
- vitesse =(2/(chrono/1000.0))*3.6;
- delay(5);
- temps=millis();
- Serial.println(vitesse);
- dtostrf(vitesse, 4, 2, str_vitesse);
- }
- sprintf(Str1, "Vitesse: %s km/h", str_vitesse);
- lcd.setCursor(0,0);
- lcd.print(Str1);
- sprintf(Str3, "Throttle: %3d %", map(analogRead(A1),0,1020,0,100));
- lcd.setCursor(0,1);
- lcd.print(Str3);
- }
- float PWM()
- {
- int PWMa = analogRead(A1);
- PWMa = map(PWM, 0, 1024, 0, 179);
- esc.write(PWMa);
- }
- void detectaimant()
- {
- etat= true;
- }
- /*
- * https://liudr.wordpress.com/2012/01/16/sprintf/
- * https://arduino.stackexchange.com/questions/19234/print-string-and-integer-lcd
- * https://www.electric-skateboard.builders/t/recording-data-from-vesc-summary-of-tools/7020/13
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement