I hate C. It gives me nothing but problems. Where is a nice straightforward command such as FOR X= 1 to 3 (BASIC).
I have tried many variations of this program and nothing works PLUS the error description means nothing to me!
So here is a description of how to use the FOR loop in Arduino C:
https://startingelectronics.org/soft...e/07-for-loop/
Look at the first example program:
}Code:void setup() { int i; Serial.begin(9600); for (i = 0; i < 10; i++) { Serial.print("i = "); Serial.println(i); } } void loop() {
I tried to duplicate this just to blink the on-board LED (on pin 13) three times and then stop.
And so I get a ton of errors:Code:// For Loop test lighting the LED const int ledPin = 13; const int x; void setup() { pinMode(ledPin, OUTPUT); } for (x = 1; x<4; x = x + 1 ) { digitalWriteFast(ledPin, HIGH); // LED on delayMicroseconds(500 * 1000); // Pulse length half second digitalWriteFast(ledPin, LOW); // LED off delayMicroseconds(500 * 1000); // Pulse every half second } void loop() { }
Arduino: 1.8.9 (Windows 10), TD: 1.50, Board: "Teensy 4.0, Serial, 600 MHz, Faster, US English"
C:\Users\DW\Documents\Arduino\Programs\For_loop_te st\For_loop_test.ino:3:11: warning: uninitialized const 'x' [-fpermissive]
const int x;
^
For_loop_test:11: error: expected unqualified-id before 'for'
for (x = 1; x<4; x = x + 1 ) {
^
For_loop_test:11: error: 'x' does not name a type
for (x = 1; x<4; x = x + 1 ) {
^
For_loop_test:11: error: 'x' does not name a type
for (x = 1; x<4; x = x + 1 ) {
^
expected unqualified-id before 'for'
So why does it show the 2nd error twice and what is the meaning of a type. The type is identified in the declaration at the top?
And what is an Unqualified ID?
(Just so you know how easy this is to do in BASIC here it is.)
10 FOR X=1 to 3
20 OUTPUT Led, 1
30 WAIT 500
40 OUTPUT Led, 0
50 WAIT 500
60 NEXT X
70 END
Variables do not have to be defined, no little braces everywhere, case does not matter, easy and it works.