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: **Beeping Sound**
- - Source Code NOT compiled for: Arduino Uno
- - Source Code created on: 2024-12-26 20:32:20
- ********* 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 */
- /****** SYSTEM REQUIREMENT 2 *****/
- /* fix the code */
- /****** END SYSTEM REQUIREMENTS *****/
- /* START CODE */
- /****** DEFINITION OF LIBRARIES *****/
- #include <Arduino.h> // Include Arduino library for basic functions
- /****** FUNCTION PROTOTYPES *****/
- void setup(void);
- void loop(void);
- void myPwm(unsigned char duty, float freq); // Function prototype for myPwm
- int klik = 800; // Initialize klik variable
- void setup(void)
- {
- // Set pin 10 as an output
- pinMode(10, OUTPUT); // Must use D10
- }
- void loop(void)
- {
- // Main loop to create a high frequency beeping noise
- for (int klik = 800; klik > 0; klik -= 100) // Decrease klik in steps
- {
- myPwm(127, 2500); // Set PWM to 50% duty cycle at 2500 Hz
- delay(klik); // Wait for the current klik duration
- myPwm(0, 2500); // Turn off PWM
- delay(klik); // Wait for the current klik duration
- }
- myPwm(127, 2500); // Final beep at 2500 Hz
- }
- void myPwm(unsigned char duty, float freq) {
- TCCR1A = 0x21; // Set Timer/Counter Control Register A
- TCCR1B = 0x14; // Set Timer/Counter Control Register B
- OCR1A = (16000000 / (freq * 8)) - 1; // Calculate OCR1A for desired frequency
- OCR1B = OCR1A * (duty / 255.0); // Calculate OCR1B for desired duty cycle
- }
- /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement