Advertisement
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: "PWM Control"
- - Source Code NOT compiled for: Arduino Uno
- - Source Code created on: 2024-12-26 20:06:03
- ********* Pleasedontcode.com **********/
- /****** SYSTEM REQUIREMENTS *****/
- /****** SYSTEM REQUIREMENT 1 *****/
- /* make a high frequency beeping noise that gets */
- /* quicker and quicker and is steady high pitch when */
- /* drops to zero */
- /****** END SYSTEM REQUIREMENTS *****/
- /* START CODE */
- /****** DEFINITION OF LIBRARIES *****/
- #include <TimerOne.h> // Include TimerOne library
- /****** FUNCTION PROTOTYPES *****/
- void setup(void);
- void loop(void);
- void myPwm(unsigned char duty, float freq); // Added function prototype for myPwm
- // Instantiate TimerOne object
- TimerOne timer;
- void setup(void)
- {
- // put your setup code here, to run once:
- pinMode(10, OUTPUT); // Must use D10
- }
- void loop(void)
- {
- // put your main code here, to run repeatedly:
- for(int klik = 800; klik > 0; klik -= 50) // Adjusted to go down to 0 for steady high pitch
- {
- myPwm(127, 2500); // e.g. (127/255)50% duty with 2500 Hz
- delay(klik);
- myPwm(0, 2500); // Turn off sound
- delay(klik);
- }
- myPwm(127, 2500); // Maintain high pitch sound when dropping to zero
- }
- void myPwm(unsigned char duty, float freq)
- {
- timer.initialize(1000000 / freq); // Initialize Timer1 with frequency
- timer.pwm(10, duty); // Set PWM on pin 10
- }
- /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement