Help with custom pr...
 
Notifications
Clear all

[Solved] Help with custom protocol for Fuel/Temp Gauge

1 Posts
1 Users
0 Reactions
754 Views
(@mafia_mods)
New Member
Joined: 1 year ago
Posts: 1
Topic starter  

Hello, I am working with a arduino uno trying to build a custom protocol for my temp and fuel gauges that are made with 180* 9g servos. I am using the PWMServo Library because I was getting a timer error using Servo.h and the Tone library together. (My speedo and Rpm gauge use air core motors) I cant seem to figure out the correct sketch for arduino. With the current sketch the fuel servo never moves to any position. Im using the nCalc Formula  format([DataCorePlugin.Computed.Fuel_Percent], '0')  inside Simhub, Please correct me if that is wrong. Any help is very appreciated!!!

#ifndef __SHCUSTOMPROTOCOL_H__
#define __SHCUSTOMPROTOCOL_H__

#include <Arduino.h>
#include <PWMServo.h>

class SHCustomProtocol {
private:

public:

  PWMServo myservo;
  int Fuel;    
  void setup() {
  myservo.attach(3); 
  }
  void read() {
    int Fuel = FlowSerialReadStringUntil('\n').toInt();
    FlowSerialDebugPrintLn("Fuel : " + String(Fuel)); 
  }
  void loop() {
    Fuel = map(Fuel, 0, 100, 20, 170);     // scale it to use it with the servo (value between 0 and 180)
    myservo.write(Fuel);                  // sets the servo position according to the scaled value 
  }

  void idle() {
  }
};

#endif

   
Quote
Share: