Hello all,
I am working on a project to make a resistive steering wheel control adapter to integrate an aftermarket head unit into a chevy silverado. The truck has resistive SWC, but it is designed for sourcing not sinking. The head unit wants sinking not sourcing. Using voltage dividers and diodes, I believe I have the hardware figured out, I am struggling with getting the code to compile. I understand that Variables should be defined within the function which they are used. I also thought that I understood that Pins were predefined in association with the board(an Arduino Nano in this case). I keep getting "not declared in this scope", for every pin. I am not sure where the break down is here or what I am getting wrong. I would appreciate any guidance.
void setup()
{
Serial.begin(9600);
pinMode(D2, OUTPUT);
pinMode(D3, OUTPUT);
pinMode(D4, OUTPUT);
pinMode(D5, OUTPUT);
pinMode(D6, OUTPUT);
pinMode(D7, OUTPUT);
pinMode(D8, OUTPUT);
digitalWrite(D2, high);
digitalWrite(D3, high);
digitalWrite(D4, high);
digitalWrite(D5, high);
digitalWrite(D6, high);
digitalWrite(D7, high);
digitalWrite(D8, high);
}
void loop()
{
int input_value = analogRead(A0);
if (input_value > 975 ) {
digitalWrite(D2, low);
delay(10);
digitalWrite(D2, high);}
else if (input_value < 955 && input_value > 920) {
digitalWrite(D3, low);
delay(10);
digitalWrite(D3, high);}
else if (input_value < 805 && input_value > 765) {
digitalWrite(D4, low);
delay(10);
digitalWrite(D4, high);}
else if (input_value < 680 && input_value > 620) {
digitalWrite(D5, low);
delay(10);
digitalWrite(D5, high);}
else if (input_value < 580 && input_value > 520) {
digitalWrite(D6, low);
delay(10);
digitalWrite(D6, high);}
else if (input_value < 480 && input_value > 420) {
digitalWrite(D7, low);
delay(10);
digitalWrite(D7, high);}
else (input_value < 370 && input_value > 310) {
digitalWrite(D8, low);
delay(10);
digitalWrite(D8, high);}
delay(10);
Serial.println(input_value);
}
Lose the D's. You just need the number.
Try:
void setup() {
Serial.begin(9600);
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
pinMode(7, OUTPUT);
pinMode(8, OUTPUT);
digitalWrite(2, HIGH);
digitalWrite(3, HIGH);
digitalWrite(4, HIGH);
digitalWrite(5, HIGH);
digitalWrite(6, HIGH);
digitalWrite(7, HIGH);
digitalWrite(8, HIGH);
}
void loop() {
int input_value = analogRead(A0);
if( input_value > 975 ) {
digitalWrite(2, LOW);
delay(10);
digitalWrite(2, HIGH);
} else if (input_value < 955 && input_value > 920) {
digitalWrite(3, LOW);
delay(10);
digitalWrite(3, HIGH);
} else if (input_value < 805 && input_value > 765) {
digitalWrite(4, LOW);
delay(10);
digitalWrite(4, HIGH);
} else if (input_value < 680 && input_value > 620) {
digitalWrite(5, LOW);
delay(10);
digitalWrite(5, HIGH);
} else if (input_value < 580 && input_value > 520) {
digitalWrite(6, LOW);
delay(10);
digitalWrite(6, HIGH);
} else if (input_value < 480 && input_value > 420) {
digitalWrite(7, LOW);
delay(10);
digitalWrite(7, HIGH);
} else if (input_value < 370 && input_value > 310) {
digitalWrite(8, LOW);
delay(10);
digitalWrite(8, HIGH);
}
delay(10);
Serial.println(input_value);
}
I attempted the suggested changes, the following is my fault log.
EDIT: I just realized in your suggestion you changed HIGH and LOW to all caps, I am still missing that, will try again.
Arduino: 1.8.5 (Windows 7), Board: "Arduino Nano, ATmega328P (Old Bootloader)"
Build options changed, rebuilding all
C:\Users\AL\Documents\Arduino\Chevy_Head_unit_SWC_button\Chevy_Head_unit_SWC_button.ino: In function 'void setup()':
Chevy_Head_unit_SWC_button:19: error: 'high' was not declared in this scope
digitalWrite(2, high);
^~~~
C:\Users\AL\Documents\Arduino\Chevy_Head_unit_SWC_button\Chevy_Head_unit_SWC_button.ino:19:19: note: suggested alternative: 'sinh'
digitalWrite(2, high);
^~~~
sinh
C:\Users\AL\Documents\Arduino\Chevy_Head_unit_SWC_button\Chevy_Head_unit_SWC_button.ino: In function 'void loop()':
Chevy_Head_unit_SWC_button:34: error: 'low' was not declared in this scope
digitalWrite(2, low);
^~~
C:\Users\AL\Documents\Arduino\Chevy_Head_unit_SWC_button\Chevy_Head_unit_SWC_button.ino:34:25: note: suggested alternative: 'pow'
digitalWrite(2, low);
^~~
pow
Chevy_Head_unit_SWC_button:36: error: 'high' was not declared in this scope
digitalWrite(2, high);}
^~~~
C:\Users\AL\Documents\Arduino\Chevy_Head_unit_SWC_button\Chevy_Head_unit_SWC_button.ino:36:25: note: suggested alternative: 'sinh'
digitalWrite(2, high);}
^~~~
sinh
Chevy_Head_unit_SWC_button:38: error: 'low' was not declared in this scope
digitalWrite(3, low);
^~~
C:\Users\AL\Documents\Arduino\Chevy_Head_unit_SWC_button\Chevy_Head_unit_SWC_button.ino:38:25: note: suggested alternative: 'pow'
digitalWrite(3, low);
^~~
pow
Chevy_Head_unit_SWC_button:40: error: 'high' was not declared in this scope
digitalWrite(3, high);}
^~~~
C:\Users\AL\Documents\Arduino\Chevy_Head_unit_SWC_button\Chevy_Head_unit_SWC_button.ino:40:24: note: suggested alternative: 'sinh'
digitalWrite(3, high);}
^~~~
sinh
Chevy_Head_unit_SWC_button:42: error: 'low' was not declared in this scope
digitalWrite(4, low);
^~~
C:\Users\AL\Documents\Arduino\Chevy_Head_unit_SWC_button\Chevy_Head_unit_SWC_button.ino:42:25: note: suggested alternative: 'pow'
digitalWrite(4, low);
^~~
pow
Chevy_Head_unit_SWC_button:44: error: 'high' was not declared in this scope
digitalWrite(4, high);}
^~~~
C:\Users\AL\Documents\Arduino\Chevy_Head_unit_SWC_button\Chevy_Head_unit_SWC_button.ino:44:25: note: suggested alternative: 'sinh'
digitalWrite(4, high);}
^~~~
sinh
Chevy_Head_unit_SWC_button:46: error: 'low' was not declared in this scope
digitalWrite(5, low);
^~~
C:\Users\AL\Documents\Arduino\Chevy_Head_unit_SWC_button\Chevy_Head_unit_SWC_button.ino:46:25: note: suggested alternative: 'pow'
digitalWrite(5, low);
^~~
pow
Chevy_Head_unit_SWC_button:48: error: 'high' was not declared in this scope
digitalWrite(5, high);}
^~~~
C:\Users\AL\Documents\Arduino\Chevy_Head_unit_SWC_button\Chevy_Head_unit_SWC_button.ino:48:25: note: suggested alternative: 'sinh'
digitalWrite(5, high);}
^~~~
sinh
Chevy_Head_unit_SWC_button:50: error: 'low' was not declared in this scope
digitalWrite(6, low);
^~~
C:\Users\AL\Documents\Arduino\Chevy_Head_unit_SWC_button\Chevy_Head_unit_SWC_button.ino:50:25: note: suggested alternative: 'pow'
digitalWrite(6, low);
^~~
pow
Chevy_Head_unit_SWC_button:52: error: 'high' was not declared in this scope
digitalWrite(6, high);}
^~~~
C:\Users\AL\Documents\Arduino\Chevy_Head_unit_SWC_button\Chevy_Head_unit_SWC_button.ino:52:24: note: suggested alternative: 'sinh'
digitalWrite(6, high);}
^~~~
sinh
Chevy_Head_unit_SWC_button:54: error: 'low' was not declared in this scope
digitalWrite(7, low);
^~~
C:\Users\AL\Documents\Arduino\Chevy_Head_unit_SWC_button\Chevy_Head_unit_SWC_button.ino:54:24: note: suggested alternative: 'pow'
digitalWrite(7, low);
^~~
pow
Chevy_Head_unit_SWC_button:56: error: 'high' was not declared in this scope
digitalWrite(7, high);}
^~~~
C:\Users\AL\Documents\Arduino\Chevy_Head_unit_SWC_button\Chevy_Head_unit_SWC_button.ino:56:24: note: suggested alternative: 'sinh'
digitalWrite(7, high);}
^~~~
sinh
Chevy_Head_unit_SWC_button:58: error: 'low' was not declared in this scope
digitalWrite(8, low);
^~~
C:\Users\AL\Documents\Arduino\Chevy_Head_unit_SWC_button\Chevy_Head_unit_SWC_button.ino:58:24: note: suggested alternative: 'pow'
digitalWrite(8, low);
^~~
pow
Chevy_Head_unit_SWC_button:60: error: 'high' was not declared in this scope
digitalWrite(8, high);}
^~~~
C:\Users\AL\Documents\Arduino\Chevy_Head_unit_SWC_button\Chevy_Head_unit_SWC_button.ino:60:24: note: suggested alternative: 'sinh'
digitalWrite(8, high);}
^~~~
sinh
exit status 1
'high' was not declared in this scope
This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.
Thank you for the help. could some one explain the situation with the pin naming? Analog pins are A0,A1,etc... but Digital Pins are just their associated number?
Thank you.
In some cores, the digital pins are also assigned D# numbers (often to make native GPIO numbers more like the original AVR pin number assignments). But it's not done in the AVR core.