I have a Dual axis sensor that generates a PWM signal of 100Hz and at 0.0Deg the duty is +50% -50% and at 3Deg the duty reads +52% and -48% then when I tilt it the opposite way -2.6Deg the duty reads +48% -52%. I've attached some pics to show the readings
I'm using the Pulse in and at zero it displays 4962 and at 3Deg= 5179 and -2.6=4768,
The part I'm struggling with is how to convert the PWM_value into displaying it like the inclinometer does as anybody got any ideas or advise the best method
code below
#include <LiquidCrystal_I2C.h>
#include <Wire.h>
LiquidCrystal_I2C lcd(0x027, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); // Set the LCD I2C address
byte PWM_PIN = 3; //PWM input from daul axis sensor
long currentMillis = 0; //used to count the mills
long previousMillis = 0; // previuosmills
long interval = 500; // interval time for display stops the flickering
int pwm_value; // holds the pwm value
int level; // not used yet
float digital_level; show's the slow value
void setup() {
pinMode(PWM_PIN, INPUT);
lcd.begin (20, 4); // for 20 X 4 LCD module
lcd.setBacklight(HIGH);
lcd.clear();
}
void loop() {
pwm_value = pulseIn(PWM_PIN, HIGH);
digital_level = pwm_value;
lcd.setCursor(0, 0);
lcd.print(pwm_value);
lcd.print(" ");
currentMillis = millis();
if (currentMillis - previousMillis > interval)
{
previousMillis = currentMillis;
lcd.setCursor(0, 1);
lcd.print(digital_level);
lcd.print(" ");
}
}
moderator: fixed title



