So I recently started Arduino and I am doing Arduino Analog input and output on LED & Serial.
So when I verify the code, it's saying: 'inputVal' was not declared in this scope (I'll upload the code)
Can anyone help?
Code: /*
Tutorial for Analog input and Output.
Input through Potentiomete and output through PWM on LED and serial monitor.
Prepared by Robo India.
www.roboindia.com
*/
int analog_ip = A7;
int LED = 3;
int intputVal = 0;
int old_ip_val = 0;
void setup() {
pinMode (LED, OUTPUT);
Serial.begin(96000);
Serial.print("ROBO INDIA\nroboindia.com/nTutorial on Analog inout and output.\n");
}
void loop() {
inputVal = analogRead(analog_ip);
if (inputVal < old_ip_val - 5 | | inputVal < old_ip_val + 5)
}
{
Serial.print("Input Value : ");
Serial.print(inputVal);
Serial.print("\nLED Brightness : ");
Serial.print(inputVal / 4);
Serial.print("\n");
analogWrite(LED, inputVal / 4);
delay(500);
old_ip_val = inputVal;
{
}
}
Error Message: Arduino: 1.8.19 (Mac OS X), Board: "Arduino Uno"
/Users/anshumansrivastava/Desktop/Analog_input_and_output_on_LED_n_Serial/Analog_input_and_output_on_LED_n_Serial.ino: In function 'void loop()':
Analog_input_and_output_on_LED_n_Serial:19:1: error: 'inputVal' was not declared in this scope
inputVal = analogRead(analog_ip);
^~~~~~~~
/Users/anshumansrivastava/Desktop/Analog_input_and_output_on_LED_n_Serial/Analog_input_and_output_on_LED_n_Serial.ino:19:1: note: suggested alternative: 'intputVal'
inputVal = analogRead(analog_ip);
^~~~~~~~
intputVal
/Users/anshumansrivastava/Desktop/Analog_input_and_output_on_LED_n_Serial/Analog_input_and_output_on_LED_n_Serial.ino: At global scope:
Analog_input_and_output_on_LED_n_Serial:21:2: error: expected unqualified-id before '{' token
{ if( inputVal<old_ip_val-5 || inputVal<old_ip_val+5)
^
Analog_input_and_output_on_LED_n_Serial:25:1: error: expected unqualified-id before '{' token
{
^
exit status 1
'inputVal' was not declared in this scope
This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.
Screenshots of code are nearly worthless. We cannot copy and paste them into an editor or the IDE for examination and verification. Read the forum guidelines to see how to properly post code and some good information on making a good post. Use the IDE autoformat tool (ctrl-t or Tools, Auto format) before posting code in code tags.
Please include the entire error message. It is easy to do. There is a button (lower right of the IDE window) called "copy error message". Copy the error and paste into a post in code tags. Paraphrasing the error message leaves out important information.
If you read and follow the guidelines you will get better and faster help.
Once you fix the inputVal issue,
Here is your loop fixed. There were extra brackets and a space between | | that should not be there. It needs to be || (no space).
void loop()
{
inputVal = analogRead(analog_ip);
// *********** no space between ||
if (inputVal < old_ip_val - 5 || inputVal < old_ip_val + 5)
//} ********** extra bracket
{
Serial.print("Input Value : ");
Serial.print(inputVal);
Serial.print("\nLED Brightness : ");
Serial.print(inputVal / 4);
Serial.print("\n");
analogWrite(LED, inputVal / 4);
delay(500);
old_ip_val = inputVal;
//{ ********** extra bracket
}
}
/*
Tutorial for Analog input and Output.
Input through Potentiomete and output through PWM on LED and serial monitor.
Prepared by Robo India.
www.roboindia.com
*/
int analog_ip = A7;
int LED = 3;
int intputVal = 0;
int old_ip_val = 0;
void setup() {
pinMode (LED, OUTPUT);
Serial.begin(96000);
Serial.print("ROBO INDIA\nroboindia.com/nTutorial on Analog inout and output.\n");
}
void loop() {
inputVal = analogRead(analog_ip);
if ( inputVal < old_ip_val - 5 || inputVal < old_ip_val + 5)
{
Serial.print("Input Value : ");
Serial.print(inputVal);
Serial.print("\nLED Brightness : ");
Serial.print(inputVal / 4);
Serial.print("\n");
analogWrite(LED, inputVal / 4);
delay(500);
old_ip_val = inputVal;
}
}
Look carefully. The variable names must match, exactly.
This compiles:
/*
Tutorial for Analog input and Output.
Input through Potentiomete and output through PWM on LED and serial monitor.
Prepared by Robo India.
www.roboindia.com
*/
int analog_ip = A7;
int LED = 3;
int inputVal = 0; // no t
int old_ip_val = 0;
void setup()
{
pinMode (LED, OUTPUT);
Serial.begin(96000);
Serial.print("ROBO INDIA\nroboindia.com/nTutorial on Analog inout and output.\n");
}
void loop()
{
inputVal = analogRead(analog_ip);
if ( inputVal < old_ip_val - 5 || inputVal < old_ip_val + 5)
{
Serial.print("Input Value : ");
Serial.print(inputVal);
Serial.print("\nLED Brightness : ");
Serial.print(inputVal / 4);
Serial.print("\n");
analogWrite(LED, inputVal / 4);
delay(500);
old_ip_val = inputVal;
}
}
you do need to use the same name, arduino doesnt spell check.
Also you should sort out your braces, this is very messy. I see youre just checking the first part of the loop(); but just cut and paste the "junk" into notepad rather then leave it in your code!