Using SevSeg library to display doubles

I have a program that counts rotations using accelerometer data and I'm trying to display those rotations on a 4digit-7segment display. My problem is that the SevSeg function sevseg.setNumber(displayValue, 1); gives me this error when I try to input a double. "call of overloaded 'setNumber(double&, int)' is ambiguous". The double displayValue is the amount of rotations added to the half rotations and the second parameter is where the decimal place goes. I could just use integers which I know work but it's important that the display also shows half turns.
Here is my code.

#include <Wire.h>
#include "SevSeg.h"
SevSeg sevseg; //Initiate a seven segment controller object

//Variables
int ADXL345 = 0x53;

float X_out, Y_out, Z_out, roll, pitch;
int fullR;
double halfR;
double displayValue = fullR + halfR;
int buttonState = 0;
boolean halfCounted = false;

const int buttonPin = A0;

void setup() {
  // initialize the pushbutton pin as an input:
  pinMode(buttonPin, INPUT);

  //SevSeg Setup
  byte numDigits = 4;
  byte digitPins[] = {7, 2, 4, 9};
  byte segmentPins[] = {13, 3, 8, 10, 11, 12, 5, 6 };
  bool resistorsOnSegments = true; 
  bool updateWithDelaysIn = true;
  byte hardwareConfig = COMMON_CATHODE; 
  sevseg.begin(hardwareConfig, numDigits, digitPins, segmentPins, resistorsOnSegments);
  sevseg.setBrightness(90);

  //So I can see my data on the serial port
  Serial.begin(9600);
  Wire.begin();
  Wire.beginTransmission(ADXL345);
  Wire.write(0x2D);
  Wire.write(8);
  Wire.endTransmission();
  delay(10);

  //Off-set Calibration
  //X-axis
  Wire.beginTransmission(ADXL345);
  Wire.write(0x1E);
  Wire.write(-6);
  Wire.endTransmission();
  delay(10);

  //Y-axis
  Wire.beginTransmission(ADXL345);
  Wire.write(0x1F);
  Wire.write(-3);
  Wire.endTransmission();
  delay(10);

  //Z-axis
  Wire.beginTransmission(ADXL345);
  Wire.write(0x20);
  Wire.write(2);
  Wire.endTransmission();
  delay(10);
}

void loop() {
  //Accelerometer math to convert it into degrees
  Wire.beginTransmission(ADXL345);
  Wire.write(0x32);
  Wire.endTransmission(false);
  Wire.requestFrom(ADXL345, 6, true);
  X_out = ( Wire.read() | Wire.read() << 8);
  X_out = X_out / 256;
  Y_out = ( Wire.read() | Wire.read() << 8);
  Y_out = Y_out / 256;
  Z_out = ( Wire.read() | Wire.read() << 8);
  Z_out = Z_out / 256;

  roll = atan(Y_out / sqrt(pow(X_out, 2) + pow(Z_out, 2))) * 180 / PI;
  pitch = atan(-1 * X_out / sqrt(pow(Y_out, 2) + pow(Z_out, 2))) * 180 / PI;


  //Counting rotations
  //Counts spins going clockwise
  while (pitch <= -60 && halfCounted == false)
  {
    halfR += .5;
    halfCounted = true;
  }

  while (pitch >= 60 && halfCounted == true)
  {
    halfR += .5;
    fullR += 1;
    halfCounted = false;
  }

  //Sends value to the display
  sevseg.setNumber(displayValue,1);
  sevseg.refreshDisplay();

  //Reset code (resets the display using a physical button)
  buttonState = digitalRead(buttonPin);
  if (buttonState == HIGH) 
  {
    halfR = 0;
    fullR = 0;
    halfCounted = false;
    sevseg.blank();
  }

  //Code to print all data to the serial port
  Serial.print("Y-Axis: ");
  Serial.print(roll);
  Serial.print(" / ");
  Serial.print("X-Axis: ");
  Serial.print(pitch);
  Serial.print(" / ");
  Serial.print("Half_Count: ");
  Serial.print(halfR);
  Serial.print(" / ");
  Serial.print("Full_Count: ");
  Serial.print(fullR);
  Serial.println(" / ");
}
int fullR;
double halfR;
double displayValue = fullR + halfR;

This addition will get done before the sketch begins. At that point, halfR and fullR are both zero, so displayValue will also be zero and will stay that way forever because the sketch never updates it.

What I would suggest is abandon keeping the full rotations and half rotations in separate variables. Use a single float variable, not a double. When you detect a half rotation, add 0.5 to the variable. This will make the logic much simpler and the value will be ready to display.

Alright I'll try that and then get back to you!

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.