Writing a function

The problem with using global variables instead of passing function arguments is a loss in flexibility. For example, if you have a function that flashes an LED and accesses the global variable ledPin to decide which pin to use, the function can only flash that pin. If instead, it takes an argument, you can pass in different pins depending on which LED you want to flash. Sure, all of those pin variables might be global and accessible from within the function, but the function will have no way of knowing which pin to flash.