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: "LEDs Buzzer"
- - Source Code NOT compiled for: Arduino Mega
- - Source Code created on: 2024-06-11 14:02:30
- ********* Pleasedontcode.com **********/
- /****** SYSTEM REQUIREMENTS *****/
- /****** SYSTEM REQUIREMENT 1 *****/
- /* Implement a supercar effect using WS2812B LED */
- /* strip controlled by FastLED library. The setup */
- /* involves initializing digital pin 2 for output and */
- /* continuously updating the LED state based on raw */
- /* data input. */
- /****** SYSTEM REQUIREMENT 2 *****/
- /* emit sound like supercar telefilm. */
- /****** END SYSTEM REQUIREMENTS *****/
- /****** DEFINITION OF LIBRARIES *****/
- #include <FastLED.h> // https://github.com/FastLED/FastLED
- /****** FUNCTION PROTOTYPES *****/
- void setup(void);
- void loop(void);
- void updateOutputs(void);
- void fadeall(void);
- void playSupercarSound(void);
- /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
- const uint8_t strip_WS2812B_DIN_PIN_D2 = 2;
- const uint8_t myActiveBuzzer_ActiveBuzzer_output_PIN_D3 = 3;
- /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
- /***** used to store raw data *****/
- bool strip_WS2812B_DIN_PIN_D2_rawData = 0;
- bool myActiveBuzzer_ActiveBuzzer_output_PIN_D3_rawData = 0;
- /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
- /***** used to store data after characteristic curve transformation *****/
- float strip_WS2812B_DIN_PIN_D2_phyData = 0.0;
- float myActiveBuzzer_ActiveBuzzer_output_PIN_D3_phyData = 0.0;
- /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
- #define NUM_LEDS 64 // Number of LEDs in the strip
- #define DATA_PIN 2 // Data pin for the LED strip
- CRGB leds[NUM_LEDS]; // Array to hold the color values for each LED
- void setup(void)
- {
- // Initialize the LED strip
- FastLED.addLeds<WS2812, DATA_PIN, RGB>(leds, NUM_LEDS);
- FastLED.setBrightness(84); // Set the brightness of the LEDs
- // Set pin modes for other outputs
- pinMode(strip_WS2812B_DIN_PIN_D2, OUTPUT);
- pinMode(myActiveBuzzer_ActiveBuzzer_output_PIN_D3, OUTPUT);
- }
- void loop(void)
- {
- // Update the LED strip with the Cylon effect
- static uint8_t hue = 0;
- for (int i = 0; i < NUM_LEDS; i++) {
- leds[i] = CHSV(hue++, 255, 255);
- FastLED.show();
- fadeall();
- delay(10);
- }
- for (int i = NUM_LEDS - 1; i >= 0; i--) {
- leds[i] = CHSV(hue++, 255, 255);
- FastLED.show();
- fadeall();
- delay(10);
- }
- // Refresh output data for other outputs
- updateOutputs();
- // Play supercar sound
- playSupercarSound();
- }
- void updateOutputs()
- {
- digitalWrite(strip_WS2812B_DIN_PIN_D2, strip_WS2812B_DIN_PIN_D2_rawData);
- digitalWrite(myActiveBuzzer_ActiveBuzzer_output_PIN_D3, myActiveBuzzer_ActiveBuzzer_output_PIN_D3_rawData);
- }
- void fadeall()
- {
- for (int i = 0; i < NUM_LEDS; i++) {
- leds[i].nscale8(250);
- }
- }
- void playSupercarSound()
- {
- // Emit sound like supercar telefilm using the active buzzer
- tone(myActiveBuzzer_ActiveBuzzer_output_PIN_D3, 1000); // Play tone at 1000 Hz
- delay(100); // Wait for 100 ms
- noTone(myActiveBuzzer_ActiveBuzzer_output_PIN_D3); // Stop the tone
- delay(100); // Wait for 100 ms
- }
- /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement