Hello!
I want to use the Tx,Rx pins as "normal gpio" pins.
I tested with the Blink example code.
But, i got this error:
Arduino: 1.8.3 (Linux), Alaplap:"WeMos D1 R2 & mini, 80 MHz, 115200, 4M (3M SPIFFS)"
/tmp/arduino_modified_sketch_710267/Blink.ino: In function 'void loop()':
Blink:34: error: 'statepl' was not declared in this scope
digitalWrite(statepl, HIGH); // turn the LED on (HIGH is the voltage level)
^
exit status 1
'statepl' was not declared in this scope
The sample code:
// the setup function runs once when you press reset or power the board
void setup() {
int statepl = 3;
pinMode(statepl, FUNCTION_3);//rx pin!!!
pinMode(statepl, OUTPUT);
}
// the loop function runs over and over again forever
void loop() {
digitalWrite(statepl, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(statepl, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}
Only work when i declare the statepl variable in the void loop statement.
This is not the best solution.
I want all the variables declaring outside from the void loop.
Is it possible?
Thanks!
By declaring statepl inside setup() you make it local to setup() and thus you get the "not declared in this scope" error when you try to use it in loop(). You need to declare statepl in the global scope (outside of setup()) if you want to be able to use it in loop():
int statepl = 3;
// the setup function runs once when you press reset or power the board
void setup() {
pinMode(statepl, FUNCTION_3);//rx pin!!!
pinMode(statepl, OUTPUT);
}
// the loop function runs over and over again forever
void loop() {
digitalWrite(statepl, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(statepl, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}
I try use ESP8266 with GPIO6-11.
I use pinMode (9, FUNCTION_3); (or I tryed Function_4), but not work. Why?
// the setup function runs once when you press reset or power the board
void setup() {
// initialize digital pin LED_BUILTIN as an output.
pinMode (6, FUNCTION_3);
pinMode(6, OUTPUT);
pinMode (7, FUNCTION_3);
pinMode(7, OUTPUT);
pinMode (8, FUNCTION_3);
pinMode(8, OUTPUT);
pinMode (9, FUNCTION_3);
pinMode(9, OUTPUT);
pinMode (10, FUNCTION_3);
pinMode(10, OUTPUT);
pinMode (11, FUNCTION_3);
pinMode(11, OUTPUT);
pinMode(2, OUTPUT); //built in led
}
// the loop function runs over and over again forever
void loop() {
digitalWrite(11, HIGH); // turn the LED on (HIGH is the voltage level)
digitalWrite(2, HIGH);
delay(1000); // wait for a second
digitalWrite(11, LOW); // turn the LED off by making the voltage LOW
digitalWrite(2, LOW);
delay(1000); // wait for a second
}
Yes, I read it. I am not typically user . But theoretically, the opportunity is given to use them when we change the mode.(Function_3 is a normal IO mode).
Why not work this mode?
I watch the pin2, this not working too. After start blink short(0,5sec), and 7sec pause, and again short blink, 7sec, and carry on....