Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /********* Pleasedontcode.com **********
- Pleasedontcode thanks you for automatic code generation! Enjoy your code!
- - Terms and Conditions:
- You have a non-exclusive, revocable, worldwide, royalty-free license
- for personal and commercial use. Attribution is optional; modifications
- are allowed, but you're responsible for code maintenance. We're not
- liable for any loss or damage. For full terms,
- please visit pleasedontcode.com/termsandconditions.
- - Project: Inverted PWM
- - Source Code NOT compiled for: Arduino Nano
- - Source Code created on: 2025-12-30 00:36:34
- ********* Pleasedontcode.com **********/
- /****** SYSTEM REQUIREMENTS *****/
- /****** SYSTEM REQUIREMENT 1 *****/
- /* reverse duty cycle for output pin no. 11 */
- /****** END SYSTEM REQUIREMENTS *****/
- /* START CODE */
- /****** DEFINITION OF LIBRARIES *****/
- #include <Arduino.h>
- /****** FUNCTION PROTOTYPES *****/
- void setup(void);
- void loop(void);
- // Variable for the PWM output
- int pwmPin = 11;
- // System Requirement 1: reverse duty cycle for output pin no. 11
- // This means that when duty cycle is 0, PWM output should be maximum (255), and when duty cycle is 255, PWM output should be minimum (0).
- // We will create a variable for duty cycle and invert it in the loop.
- int dutyCycle = 0;
- int increment = 1;
- void setup() {
- // initialize PWM pin
- pinMode(pwmPin, OUTPUT);
- }
- void loop() {
- // change duty cycle
- dutyCycle += increment;
- // reverse duty cycle for output pin no. 11
- // invert duty cycle
- int invertedDutyCycle = 255 - dutyCycle;
- // write PWM value to pin
- analogWrite(pwmPin, invertedDutyCycle);
- // change direction at limits
- if (dutyCycle <= 0 || dutyCycle >= 255) {
- increment = -increment;
- }
- // delay for visibility
- delay(10);
- }
- /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment