Advertisement
pleasedontcode

"Random Blink" rev_01

Apr 6th, 2024
99
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: "Random Blink"
  13.     - Source Code compiled for: Arduino Mega
  14.     - Source Code created on: 2024-04-06 22:51:46
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* all pins low  PoleR  PoleG  PoleB  Blink ransomly */
  21. /****** END SYSTEM REQUIREMENTS *****/
  22.  
  23. /****** DEFINITION OF LIBRARIES *****/
  24. #include <Arduino.h>
  25.  
  26. /****** FUNCTION PROTOTYPES *****/
  27. void setup(void);
  28. void loop(void);
  29. void updateOutputs(void);
  30.  
  31. /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
  32. const uint8_t PoleR_LED_PIN_D2 = 2;
  33. const uint8_t PoleG_LED_PIN_D3 = 3;
  34. const uint8_t PoleB_LED_PIN_D4 = 4;
  35. const uint8_t PoleON_LED_PIN_D5 = 5;
  36.  
  37. /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
  38. bool PoleR_LED_PIN_D2_rawData = 0;
  39. bool PoleG_LED_PIN_D3_rawData = 0;
  40. bool PoleB_LED_PIN_D4_rawData = 0;
  41. bool PoleON_LED_PIN_D5_rawData = 0;
  42.  
  43. void setup(void)
  44. {
  45.   // put your setup code here, to run once:
  46.   pinMode(PoleR_LED_PIN_D2, OUTPUT);
  47.   pinMode(PoleG_LED_PIN_D3, OUTPUT);
  48.   pinMode(PoleB_LED_PIN_D4, OUTPUT);
  49.   pinMode(PoleON_LED_PIN_D5, OUTPUT);
  50. }
  51.  
  52. void loop(void)
  53. {
  54.   // put your main code here, to run repeatedly:
  55.   updateOutputs(); // Refresh output data
  56.  
  57.   // Implement System Requirement 1: Set all pins low, then randomly blink them
  58.   digitalWrite(PoleR_LED_PIN_D2, LOW);
  59.   digitalWrite(PoleG_LED_PIN_D3, LOW);
  60.   digitalWrite(PoleB_LED_PIN_D4, LOW);
  61.   digitalWrite(PoleON_LED_PIN_D5, LOW);
  62.  
  63.   delay(500); // Wait for 500ms
  64.  
  65.   // Generate random numbers between 0 and 1
  66.   PoleR_LED_PIN_D2_rawData = random(2);
  67.   PoleG_LED_PIN_D3_rawData = random(2);
  68.   PoleB_LED_PIN_D4_rawData = random(2);
  69.   PoleON_LED_PIN_D5_rawData = random(2);
  70.  
  71.   delay(500); // Wait for 500ms
  72. }
  73.  
  74. void updateOutputs()
  75. {
  76.   digitalWrite(PoleR_LED_PIN_D2, PoleR_LED_PIN_D2_rawData);
  77.   digitalWrite(PoleG_LED_PIN_D3, PoleG_LED_PIN_D3_rawData);
  78.   digitalWrite(PoleB_LED_PIN_D4, PoleB_LED_PIN_D4_rawData);
  79.   digitalWrite(PoleON_LED_PIN_D5, PoleON_LED_PIN_D5_rawData);
  80. }
  81.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement