learning user defined function to blink LED

This is my first post. I am trying to learn user defined functions, and am starting with a very simple blink a LED. The code works fine until I try to insert it a user defined function. What am I doing wrong? I am attaching a copy of the code. The error message is as follows:

Arduino: 1.8.2 (Windows 10), Board: “Arduino/Genuino Uno”

C:\Users\Ken Burr\Documents\Arduino\user_define_function_to_blink_LED\user_define_function_to_blink_LED.ino: In function ‘void loop()’:

user_define_function_to_blink_LED:26: error: too few arguments to function ‘void digitalWrite(uint8_t, uint8_t)’

byte blinkLed = digitalWrite(ledPin);

^

In file included from sketch\user_define_function_to_blink_LED.ino.cpp:1:0:

C:\Users\Ken Burr\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.6.21\cores\arduino/Arduino.h:134:6: note: declared here

void digitalWrite(uint8_t, uint8_t);

^

user_define_function_to_blink_LED:27: error: expected ‘,’ or ‘…’ before ‘(’ token

void blinkLed(int digitalWrite(ledPin) {

^

user_define_function_to_blink_LED:33: error: expected ‘)’ before ‘}’ token

}

^

user_define_function_to_blink_LED:33: error: expected initializer before ‘}’ token

exit status 1
too few arguments to function ‘void digitalWrite(uint8_t, uint8_t)’

This report would have more information with
“Show verbose output during compilation”
option enabled in File → Preferences.

user_define_function_to_blink_LED.ino (581 Bytes)

You seem to have a byte variable blinkLed, which doesn't do anything, and also a function with exactly the same name that you never call. That's just confusing.

Your definition for the function blinkLed() is INSIDE loop(). You can't do that, it must be outside loop(). And you've given it a parameter which it doesn't need and which is invalid anyway (you can't do a digitalWrite() without telling it what value to write).

Basically you need to move the function definition outside loop(). Then all loop() should contain is a call to the function.

Steve

:slight_smile: Thanks for pointing me in the right direction. I finally got the code to work thanks to your suggestions.
Ken