Hi Guys I wondering what i did wrong with this sketch.
void setup() {
// put your setup code here, to run once:
int delayTime = 1000;
Serial.begin (9600);
}
void loop() {
// put your main code here, to run repeatedly:
Serial.println ("hello world");
digitalWrite (2, HIGH);
delay (delayTime);
digitalWrite (2, LOW);
delay (delayTime);
}
I get this when I compile it
type or paste code hereC:\Users\lotso\AppData\Local\Temp\.arduinoIDE-unsaved2025517-8488-1lmi8xx.fz8x\sketch_jun17a\sketch_jun17a.ino: In function 'void loop()':
C:\Users\lotso\AppData\Local\Temp\.arduinoIDE-unsaved2025517-8488-1lmi8xx.fz8x\sketch_jun17a\sketch_jun17a.ino:11:10: error: 'delayTime' was not declared in this scope
11 | delay (delayTime);
| ^~~~~~~~~
exit status 1
Compilation error: 'delayTime' was not declared in this scope
Read the link provided by @ilguargua.
It explains in detail
However most beginners just make all variables global and declare them at the top of the program outside of setup and loop, that way they can be used inside both setup and loop
Ok I assumed all Variables were global by default.
my esp32 seemed to upload the code and was working fine a few hours ago but now it just hangs saying this:-
Wrote 292768 bytes (157662 compressed) at 0x00010000 in 2.8 seconds (effective 825.9 kbit/s)...
Hash of data verified.
Leaving...
Hard resetting via RTS pin...
type or paste code here
int time1 = 1000;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
Serial.println ("hello world");
digitalWrite (2, HIGH);
delay (time1);
digitalWrite (2, LOW);
delay (time1);
}
I was doing other programs like a simple led blink then a serial write program (hello world) and watched it run through the serial monitor etc.
when I moved onto variables I had that problem we discussed.
It is writing to serial every 2 seconds, so it is working it just isn't setting pin 2 HIGH and LOW now. There is a lesson in this for me? the led might died.
I will do thanks.
I was experimenting with the serial monitor.
in a Triangle Tech PLC you can change the value of a global variable like "A" with a serial monitor by typing A=A+1 or A= 4000 etc but that doesn't seem to be the case with this IDE. Thanks guys for helping me learn