State was not declared in scope

When I compile this code I got an error 'Exit status 1 ‘state’ was not declared in the scope !!
int status = 1;
void setup () {
Serial.begin (9600);
pinMode (13, OUTPUT);
pinMode (12, OUTPUT);
pinMode (11, OUTPUT);
pinMode (10, OUTPUT);
pinMode (9, OUTPUT);
pinMode (8, OUTPUT);
pinMode (7, OUTPUT);
pinMode (6, OUTPUT);
}
void loop () {
if (Serial.available ()> 0) {
status = Serial.read ();
}
if (state == ‘a’) {
digitalWrite (13.1);
}
if (state == ‘b’) {
digitalWrite (13.0);
}
if (state == ‘c’) {
digitalWrite (12.1);
}
if (state == ‘d’) {
digitalWrite (12.0);
}
if (state == ‘e’) {
digitalWrite (11.1);
}
if (state == ‘f’) {
digitalWrite (11.0);
}
if (state == ‘g’) {
digitalWrite (10.1);
}
if (state == ‘h’) {
digitalWrite (10.0);
}
if (state == ‘i’) {
digitalWrite (9.1);
}
if (state == ‘j’) {
digitalWrite (9.0);
}
if (state == ‘k’) {
digitalWrite (8.1);
}
if (state == ‘l’) {
digitalWrite (8.0);
}
if (state == ‘m’) {
digitalWrite (7.1);
}
if (state == ‘n’) {
digitalWrite (7.0);
}
if (state == ‘or’) {
digitalWrite (6.1);
}
if (state == ‘p’) {
digitalWrite (6.0);
}
if (state == ‘q’) {// all off
digitalWrite (13.0);
digitalWrite (12.0);
digitalWrite (11.0);
digitalWrite (10.0);
digitalWrite (9.0);
digitalWrite (8.0);
digitalWrite (7.0);
digitalWrite (6.0);
}
if (state == ‘r’) {// all on
digitalWrite (13.1);
digitalWrite (12.1);
digitalWrite (11.1);
digitalWrite (10.1);
digitalWrite (9.1);
digitalWrite (8.1);
digitalWrite (7.1);
digitalWrite (6.1);
}
if (state == ‘s’) {// blink
digitalWrite (13.1);
digitalWrite (12.1);
digitalWrite (11.1);
digitalWrite (10.1);
digitalWrite (9.1);
digitalWrite (8.1);
digitalWrite (7.1);
digitalWrite (6.1);
delay (500);
digitalWrite (13.0);
digitalWrite (12.0);
digitalWrite (11.0);
digitalWrite (10.0);
digitalWrite (9.0);
digitalWrite (8.0);
digitalWrite (7.0);
digitalWrite (6.0);
delay (500);
}
if (state == ‘t’) {// Sequence 1
digitalWrite (13.1);
delay (200);
digitalWrite (12.1);
delay (200);
digitalWrite (11.1);
delay (200);
digitalWrite (10.1);
delay (200);
digitalWrite (9.1);
delay (200);
digitalWrite (8.1);
delay (200);
digitalWrite (7.1);
delay (200);
digitalWrite (6.1);
delay (200);
digitalWrite (13.0);
digitalWrite (12.0);
digitalWrite (11.0);
digitalWrite (10.0);
digitalWrite (9.0);
digitalWrite (8.0);
digitalWrite (7.0);
digitalWrite (6.0);
delay (200);
}
if (state == ‘u’) {// Sequence 2
}
if (state == ‘v’) {// Sequence 3
digitalWrite (13.1);
delay (200);
digitalWrite (13.0);
digitalWrite (12.1);
delay (200);
digitalWrite (12.0);
digitalWrite (11.1);
delay (200);
digitalWrite (11.0);
digitalWrite (10.1);
delay (200);
digitalWrite (10.0);
digitalWrite (9.1);
delay (200);
digitalWrite (9.0);
digitalWrite (8.1);
delay (200);
digitalWrite (8.0);
digitalWrite (7.1);
delay (200);
digitalWrite (7.0);
digitalWrite (6.1);
delay (200);
digitalWrite (6.0);
digitalWrite (7.1);
delay (200);
digitalWrite (7.0);
digitalWrite (8.1);
delay (200);
digitalWrite (8.0);
digitalWrite (9.1);
delay (200);
digitalWrite (9.0);
digitalWrite (10.1);
delay (200);
digitalWrite (10.0);
digitalWrite (11.1);
delay (200);
digitalWrite (11.0);
digitalWrite (12.1);
delay (200);
digitalWrite (12.0);
}
}

You haven't defined any variable named state. You do have one named status. Is that what you meant to use?

Please read the "How to Use This Forum" sticky at the top of any of the boards. In it you will learn how to post code correctly with code tags. We'd really appreciate that in the future.

digitalWrite (13.1);

I think you’ll also find that this is an error as well. You use a comma to separate arguments. And digitalWrite should be given HIGH or LOW as the second argument, not 0 or 1.

See here for details. https://www.arduino.cc/en/Reference/digitalWrite

Delta_G:
And digitalWrite should be given HIGH or LOW as the second argument, not 0 or 1.

Just curious. Why does it matter?

sterretje:
Just curious. Why does it matter?

It really doesn't. But the API is the API and there's no reason not to use it. It's always a good practice to stick with things like that in case they change on some other architecture. Imagine a chip comes out where writing a 0 to some register turns a pin on and 1 turns it off. That's crazy but not entirely unreasonable. Or if for whatever reason the underlying low level stuff changes. Or imagine that one day they combine analogWrite with digitalWrite and HIGH gets defined as 255. If you stick with the API, then the code remains portable. The new core for the new chip redefines HIGH and LOW and things still work in your code the way you expect.

Although I will give you that if there was ever a candidate API for this type of abuse it is this one. It's handy to use boolean values in digitalWrite. And the likelyhood of that kind of change coming along and breaking code is vanishingly small. But still, it's good practice to stick to an API when you can, and I think writing HIGH or LOW instead of 0 or 1 is just good practice. And a hell of a lot easier to read.

The decimal instead of a comma on the other hand is right out... Won't compile.

You might want to consider using case or at least else if instead of all of those if statements.

@Delta_G

You worded what I thought would be the objection. Thanks.

int status = 1;

but in loop you used state.

void loop () {
if (Serial.available ()> 0) {
status = Serial.read ();
}
if (state == 'a') {
digitalWrite (13.1);
}

second the digital Write arguments should be like this
digitalWrite(13, HIGH);
or
digitalwrite(13,LOW);

you used 0,1 instead of HIGH,LOW. change it first.

How it works ?.

next time use code tag