ogWrite. Example code of this method is shown above in figure 14. The analogWrite
function generates a square wave that is varied in the void loop. The two things the function
needs to run are a pin variable and a value to set the duty cycle. The values for this function must
be between 0 and 255. A duty cycle of 100 percent occurs if the value is set at 255 and a value of
0 gives a duty cycle of 0 percent. To obtain a specific duty cycle, a value for analogWrite needs
to be calculated as:
duty cycle * 255 = analogWrite value
The example code in figure 14 lines that change the duty cycle each time it completes one loop.
The output of this code is shown in figure 15 below. Each square picture shows a different time.
The pictures from left to right prove the functionality of the code changing the pulse widt