Hello everyone, for the below code. The function (EQUAL()) would return a string of number. How do i convert that string to int, so that the number can be used for comparison. I tried coming out with the code however i got an error message . Thanks for the help (:
Arduino: 1.6.3 (Windows 8.1), Board: "Arduino Uno"
TESTING.ino: In function 'void loop()':
TESTING.ino:28:24: error: converting to 'const String' from initializer list would use explicit constructor 'String::String(int, unsigned char)'
In file included from C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Arduino.h:222:0,
from TESTING.ino:4:
C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/WString.h:147:16: error: initializing argument 1 of 'unsigned char String::operator>(const String&) const'
unsigned char operator > (const String &rhs) const;
^
Error compiling.
This report would have more information with
"Show verbose output during compilation"
enabled in File > Preferences.
CODES
#include <Servo.h>
Servo myservoE;
String APAltitude, APAltitude1;
int CodeIn;
int elevator=90;
String setAltitude;
int currentAltitude=0;
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
String setAltitude;
myservoE.attach(3);
}
void loop() {
// put your main code here, to run repeatedly:
myservoE.write(elevator);
if (Serial.available () > 0)
{
CodeIn=getChar();
if (CodeIn == '=')
{
setAltitude=EQUAL();
setAltitude.toInt();
if (setAltitude > currentAltitude)
{
elevator--;
myservoE.write(elevator);
}
}
}
}
char getChar()// The serial buffer routine to get a character
{
while(Serial.available() == 0);// wait for data
return((char)Serial.read());// Thanks Doug
}// end of getchar Routine.
String EQUAL()
{
CodeIn=getchar();
switch (CodeIn)
{
case 'b' : //getting the Altitude information from FS9
delay(11);
APAltitude = "";
APAltitude += char(Serial.read());
APAltitude += char(Serial.read());
APAltitude += char(Serial.read());
APAltitude += char(Serial.read());
APAltitude += char(Serial.read());
APAltitude +=(" ");
return APAltitude;
}
}