Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. class Pin
  2. {
  3. public:
  4. int pinNr;
  5. int brightness;
  6. int cooldown;
  7. bool increase = false;
  8.  
  9. Pin(int nr){
  10. pinNr = nr;
  11. brightness = 0;
  12. cooldown = random(100,1000); // ändra för cooldownen första gåongen (mellan 1-75 atm)
  13. pinMode(nr, OUTPUT);
  14.  
  15. }
  16. Pin(){
  17. pinNr = 0;
  18. brightness = 0;
  19. cooldown = 0;
  20. increase = false;
  21. }
  22.  
  23. void CheckTime() // check every loop
  24. {
  25. if (increase == true){
  26. if (brightness >= 100)
  27. {
  28. increase = false;
  29. }
  30. else
  31. {
  32. brightness = brightness +2;
  33. }
  34. }
  35. else if (increase == false)
  36. {
  37. if (brightness <= 0)
  38. {
  39. if (cooldown <= 0)
  40. {
  41. increase = true;
  42. cooldown = random(100,1000);
  43. }
  44. else {
  45. cooldown = cooldown -1;
  46. }
  47. }
  48. else{
  49. brightness = brightness -2;
  50. }
  51. }
  52.  
  53. analogWrite(pinNr, brightness);
  54. }
  55. };
  56.  
  57. Pin pinArray[] = {Pin(3),Pin(5),Pin(6),Pin(9),Pin(10),Pin(11)};
  58.  
  59. void setup() {
  60. digitalWrite(13, HIGH);
  61. }
  62.  
  63. void loop() {
  64.  
  65. for (int i = 0; i < 6; i++) {
  66. pinArray[i].CheckTime();
  67. }
  68.  
  69. delay(30);
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement