Advertisement
kartonman

neon starup

Sep 15th, 2021
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. int flashtime;
  2. #define togglePin A0
  3. #define neonLED1 2
  4. #define neonLED2 3
  5. #define neonLED3 4
  6. #define neonLED4 5
  7. #define entranceLED1 6
  8. #define entranceLED2 7
  9.  
  10.  
  11.  
  12. //Setup ******************************************
  13.  
  14. void setup() {
  15. pinMode(togglePin, INPUT);
  16. pinMode(neonLED1, OUTPUT);
  17. pinMode(neonLED2, OUTPUT);
  18. pinMode(neonLED3, OUTPUT);
  19. pinMode(neonLED4, OUTPUT);
  20. pinMode(entranceLED1, OUTPUT);
  21. pinMode(entranceLED2, OUTPUT);
  22.  
  23. flashtime = millis() + 2000;
  24. }
  25.  
  26.  
  27. void loop() {
  28. digitalWrite(entranceLED1, HIGH);
  29. digitalWrite(entranceLED2, HIGH);
  30.  
  31. if (flashtime >= millis()) {
  32. neonLights();
  33. } else {
  34. digitalWrite(neonLED1, HIGH);
  35. digitalWrite(neonLED2, HIGH);
  36. digitalWrite(neonLED3, HIGH);
  37. digitalWrite(neonLED4, HIGH);
  38. }
  39. }
  40.  
  41. //Functions *************************************
  42.  
  43. uint8_t neonCounters[] = { 0, 0, 0, 0 };
  44. uint8_t neonLEDs[] = { neonLED1, neonLED2, neonLED3, neonLED4 };
  45.  
  46. void neonLights() {
  47. for (uint8_t i = 0; i < sizeof(neonCounters); i++) {
  48. if (neonCounters[i] == 0) {
  49. digitalWrite(neonLEDs[i], !digitalRead(neonLEDs[i]));
  50. neonCounters[i] = random(300);
  51. } else {
  52. neonCounters[i]--;
  53. }
  54. }
  55. delay(1);
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement