Advertisement
pleasedontcode

"LEDs Buzzer" rev_04

Jun 11th, 2024
286
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /********* Pleasedontcode.com **********
  2.  
  3.     Pleasedontcode thanks you for automatic code generation! Enjoy your code!
  4.  
  5.     - Terms and Conditions:
  6.     You have a non-exclusive, revocable, worldwide, royalty-free license
  7.     for personal and commercial use. Attribution is optional; modifications
  8.     are allowed, but you're responsible for code maintenance. We're not
  9.     liable for any loss or damage. For full terms,
  10.     please visit pleasedontcode.com/termsandconditions.
  11.  
  12.     - Project: "LEDs Buzzer"
  13.     - Source Code NOT compiled for: Arduino Mega
  14.     - Source Code created on: 2024-06-11 14:02:30
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* Implement a supercar effect using WS2812B LED */
  21.     /* strip controlled by FastLED library. The setup */
  22.     /* involves initializing digital pin 2 for output and */
  23.     /* continuously updating the LED state based on raw */
  24.     /* data input. */
  25. /****** SYSTEM REQUIREMENT 2 *****/
  26.     /* emit sound like supercar telefilm. */
  27. /****** END SYSTEM REQUIREMENTS *****/
  28.  
  29. /****** DEFINITION OF LIBRARIES *****/
  30. #include <FastLED.h>  // https://github.com/FastLED/FastLED
  31.  
  32. /****** FUNCTION PROTOTYPES *****/
  33. void setup(void);
  34. void loop(void);
  35. void updateOutputs(void);
  36. void fadeall(void);
  37. void playSupercarSound(void);
  38.  
  39. /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
  40. const uint8_t strip_WS2812B_DIN_PIN_D2 = 2;
  41. const uint8_t myActiveBuzzer_ActiveBuzzer_output_PIN_D3 = 3;
  42.  
  43. /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
  44. /***** used to store raw data *****/
  45. bool strip_WS2812B_DIN_PIN_D2_rawData = 0;
  46. bool myActiveBuzzer_ActiveBuzzer_output_PIN_D3_rawData = 0;
  47.  
  48. /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
  49. /***** used to store data after characteristic curve transformation *****/
  50. float strip_WS2812B_DIN_PIN_D2_phyData = 0.0;
  51. float myActiveBuzzer_ActiveBuzzer_output_PIN_D3_phyData = 0.0;
  52.  
  53. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  54. #define NUM_LEDS 64  // Number of LEDs in the strip
  55. #define DATA_PIN 2   // Data pin for the LED strip
  56.  
  57. CRGB leds[NUM_LEDS];  // Array to hold the color values for each LED
  58.  
  59. void setup(void)
  60. {
  61.     // Initialize the LED strip
  62.     FastLED.addLeds<WS2812, DATA_PIN, RGB>(leds, NUM_LEDS);
  63.     FastLED.setBrightness(84);  // Set the brightness of the LEDs
  64.  
  65.     // Set pin modes for other outputs
  66.     pinMode(strip_WS2812B_DIN_PIN_D2, OUTPUT);
  67.     pinMode(myActiveBuzzer_ActiveBuzzer_output_PIN_D3, OUTPUT);
  68. }
  69.  
  70. void loop(void)
  71. {
  72.     // Update the LED strip with the Cylon effect
  73.     static uint8_t hue = 0;
  74.     for (int i = 0; i < NUM_LEDS; i++) {
  75.         leds[i] = CHSV(hue++, 255, 255);
  76.         FastLED.show();
  77.         fadeall();
  78.         delay(10);
  79.     }
  80.     for (int i = NUM_LEDS - 1; i >= 0; i--) {
  81.         leds[i] = CHSV(hue++, 255, 255);
  82.         FastLED.show();
  83.         fadeall();
  84.         delay(10);
  85.     }
  86.  
  87.     // Refresh output data for other outputs
  88.     updateOutputs();
  89.  
  90.     // Play supercar sound
  91.     playSupercarSound();
  92. }
  93.  
  94. void updateOutputs()
  95. {
  96.     digitalWrite(strip_WS2812B_DIN_PIN_D2, strip_WS2812B_DIN_PIN_D2_rawData);
  97.     digitalWrite(myActiveBuzzer_ActiveBuzzer_output_PIN_D3, myActiveBuzzer_ActiveBuzzer_output_PIN_D3_rawData);
  98. }
  99.  
  100. void fadeall()
  101. {
  102.     for (int i = 0; i < NUM_LEDS; i++) {
  103.         leds[i].nscale8(250);
  104.     }
  105. }
  106.  
  107. void playSupercarSound()
  108. {
  109.     // Emit sound like supercar telefilm using the active buzzer
  110.     tone(myActiveBuzzer_ActiveBuzzer_output_PIN_D3, 1000); // Play tone at 1000 Hz
  111.     delay(100); // Wait for 100 ms
  112.     noTone(myActiveBuzzer_ActiveBuzzer_output_PIN_D3); // Stop the tone
  113.     delay(100); // Wait for 100 ms
  114. }
  115.  
  116. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement