Click here to Skip to main content
15,888,037 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I know the fix is probably very simple but in the following code, at the bottom you will see
C++
return string(range);
For this I get an error that says: error: 'string' was not declared in this scope.

How do I fix this ????

C++
#include <Wire.h>
#include <Adafruit_VL6180X.h>

Adafruit_VL6180X vl = Adafruit_VL6180X();


//sets if armed
boolean alarmState = false;
//uint8_t change = null;
void setup() {
    for(int i = 0; i < 4; i++){
    pinMode(i, OUTPUT);
    
    }
  Serial.begin(115200);
  
  // wait for serial port to open on native usb devices
  while (!Serial) {
    delay(1);
  }
  
  Serial.println("Adafruit VL6180x test!");
  if (! vl.begin()) {
    Serial.println("Failed to find sensor");
    while (1);
  }
  Serial.println("Sensor found!");
}

void loop() {
   for(int i = 0; i < 4; i++){
   vl = Adafruit_VL6180X();
    digitalWrite(i, HIGH);  sensor(); delay(100);  digitalWrite(i, LOW);
    }
 
}

String sensor(){
  float lux = vl.readLux(VL6180X_ALS_GAIN_5);

  Serial.print("Lux: "); Serial.println(lux);
  
  uint8_t range = vl.readRange();
  uint8_t status = vl.readRangeStatus();

  if (status == VL6180X_ERROR_NONE) {
    Serial.print("Range: "); Serial.println(range);
  }

  // Some error occurred, print it out!
  
  if  ((status >= VL6180X_ERROR_SYSERR_1) && (status <= VL6180X_ERROR_SYSERR_5)) {
    Serial.println("System error");
  }
  else if (status == VL6180X_ERROR_ECEFAIL) {
    Serial.println("ECE failure");
  }
  else if (status == VL6180X_ERROR_NOCONVERGE) {
    Serial.println("No convergence");
  }
  else if (status == VL6180X_ERROR_RANGEIGNORE) {
    Serial.println("Ignoring range");
  }
  else if (status == VL6180X_ERROR_SNR) {
    Serial.println("Signal/Noise error");
  }
  else if (status == VL6180X_ERROR_RAWUFLOW) {
    Serial.println("Raw reading underflow");
  }
  else if (status == VL6180X_ERROR_RAWOFLOW) {
    Serial.println("Raw reading overflow");
  }
  else if (status == VL6180X_ERROR_RANGEUFLOW) {
    Serial.println("Range reading underflow");
  }
  else if (status == VL6180X_ERROR_RANGEOFLOW) {
    Serial.println("Range reading overflow");
  }
return string(range);
  }
void setAlarm(boolean state){
  alarmState = state;
}


What I have tried:

Arduino reference tutorials on variable scope plus arduino and stackoverflow forums.
Posted
Updated 26-Jul-20 15:42pm
v3
Comments
KarstenK 22-Jan-19 12:00pm    
The compiler told you the truth. You need to learn the language syntax. That will you save a lot of time.

If you are continuing to have problems, please reply to the answers/comments/questions in your original post from yesterday:
I multiple of the same error - "was not declared in this scope, what do I do?[^]
 
Share this answer
 
Comments
Member 14082063 21-Jan-19 13:43pm    
Thank you for taking the time to help me, I really appreciate it and the issue has been resolved.
Make char as a string value.
char =*your value;
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900