using example digitalreadserial
ESP8266 board
1.8.2 IDE
/*
DigitalReadSerial
Reads a digital input on pin 2, prints the result to the Serial Monitor
This example code is in the public domain.
http://www.arduino.cc/en/Tutorial/DigitalReadSerial
*/
// digital pin 2 has a pushbutton attached to it. Give it a name:
int pushButton = D2;
// the setup routine runs once when you press reset:
void setup() {
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
// make the pushbutton's pin an input:
pinMode(pushButton, INPUT);
}
// the loop routine runs over and over again forever:
void loop() {
// read the input pin:
int buttonState = digitalRead(pushButton);
// print out the state of the button:
Serial.println((buttonState));
delay(1); // delay in between reads for stability
}
compiles properly.
Sketch uses 263316 bytes (25%) of program storage space. Maximum is 1044464 bytes.
Global variables use 26792 bytes (32%) of dynamic memory, leaving 55128 bytes for local variables. Maximum is 81920 bytes.
===
only change is to add (F in the print line
/*
DigitalReadSerial
Reads a digital input on pin 2, prints the result to the Serial Monitor
This example code is in the public domain.
http://www.arduino.cc/en/Tutorial/DigitalReadSerial
*/
// digital pin 2 has a pushbutton attached to it. Give it a name:
int pushButton = D2;
// the setup routine runs once when you press reset:
void setup() {
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
// make the pushbutton's pin an input:
pinMode(pushButton, INPUT);
}
// the loop routine runs over and over again forever:
void loop() {
// read the input pin:
int buttonState = digitalRead(pushButton);
// print out the state of the button:
Serial.println(F(buttonState));
delay(1); // delay in between reads for stability
}
will not compile.
error :
In file included from /home/dave/.arduino15/packages/esp8266/hardware/esp8266/2.5.0/cores/esp8266/Arduino.h:261:0,
from sketch/DigitalReadSerial.ino.cpp:1:
/tmp/arduino_modified_sketch_452053/DigitalReadSerial.ino: In function 'void loop()':
/home/dave/.arduino15/packages/esp8266/hardware/esp8266/2.5.0/tools/sdk/libc/xtensa-lx106-elf/include/sys/pgmspace.h:37:114: error: initializer fails to determine size of '__c'
#define PSTR(s) (extension({static const char __c[] attribute((aligned(4))) PROGMEM = (s); &__c[0];}))
^
/home/dave/.arduino15/packages/esp8266/hardware/esp8266/2.5.0/cores/esp8266/WString.h:38:76: note: in definition of macro 'FPSTR'
#define FPSTR(pstr_pointer) (reinterpret_cast<const __FlashStringHelper *>(pstr_pointer))
^
/home/dave/.arduino15/packages/esp8266/hardware/esp8266/2.5.0/cores/esp8266/WString.h:39:34: note: in expansion of macro 'PSTR'
#define F(string_literal) (FPSTR(PSTR(string_literal)))
^
/tmp/arduino_modified_sketch_452053/DigitalReadSerial.ino:27:18: note: in expansion of macro 'F'
Serial.println(F(buttonState));
^
/home/dave/.arduino15/packages/esp8266/hardware/esp8266/2.5.0/tools/sdk/libc/xtensa-lx106-elf/include/sys/pgmspace.h:37:114: error: array must be initialized with a brace-enclosed initializer
#define PSTR(s) (extension({static const char __c[] attribute((aligned(4))) PROGMEM = (s); &__c[0];}))
^
/home/dave/.arduino15/packages/esp8266/hardware/esp8266/2.5.0/cores/esp8266/WString.h:38:76: note: in definition of macro 'FPSTR'
#define FPSTR(pstr_pointer) (reinterpret_cast<const __FlashStringHelper *>(pstr_pointer))
^
/home/dave/.arduino15/packages/esp8266/hardware/esp8266/2.5.0/cores/esp8266/WString.h:39:34: note: in expansion of macro 'PSTR'
#define F(string_literal) (FPSTR(PSTR(string_literal)))
^
/tmp/arduino_modified_sketch_452053/DigitalReadSerial.ino:27:18: note: in expansion of macro 'F'
Serial.println(F(buttonState));
^
exit status 1
Error compiling for board LOLIN(WEMOS) D1 R2 & mini.