Advertisement
Guest User

Untitled

a guest
Jul 18th, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.00 KB | None | 0 0
  1. int const RED[] = { 12, 0 };
  2. int const GREEN[] = { 11, 0 };
  3. int const ORANGE[] = { 11, 12, 0 };
  4. int const DEFAULT_DURATION = 1000;
  5. int const DEFAULT_COUNT = 1;
  6.  
  7. void blink(int color[]);
  8. void blink(int color[], int duration, int count);
  9. void blinkSequence(int* color[]);
  10. void blinkSequence(int* color[], int duration, int count);
  11. void on(int color[]);
  12. void off(int color[]);
  13.  
  14. void setup() {
  15. // initialize LED Pins as output
  16. Serial.begin(9600);
  17. pinMode(11, OUTPUT);
  18. pinMode(12, OUTPUT);
  19. pinMode(13, OUTPUT);
  20. digitalWrite(11, LOW);
  21. digitalWrite(12, LOW);
  22. digitalWrite(13, LOW);
  23. }
  24.  
  25. void loop() {
  26. int m = analogRead(0);
  27. int interval = 2000;
  28. Serial.print("Moisture is: ");
  29. Serial.println(m);
  30. if (m <= 580) {
  31. //Really Dry!: 580-
  32. int* seq[] = { RED, ORANGE, 0 };
  33. blinkSequence(seq, 150, 2);
  34. interval = 0;
  35. } else if (m <= 700) {
  36. //Needs water: 700 - 581
  37. blink(RED, 500);
  38. interval = 500;
  39. } else if (m <= 740) {
  40. //Could be wetter: 740 - 701
  41. blink(ORANGE, 4000);
  42. interval = 50;
  43. } else if (m <= 870) {
  44. //Happy range: 870 - 741
  45. blink(GREEN, 5000);
  46. interval = 50;
  47. } else {
  48. //Overwatered: 870+
  49. int* seq[] = { GREEN, ORANGE, 0 };
  50. blinkSequence(seq, 200, 5);
  51. interval = 3000;
  52. }
  53.  
  54. delay(interval);
  55. }
  56.  
  57. void blinkSequence(int* colors[], int duration, int count) {
  58. for (int i = count; i > 0; i--) {
  59. int** inner = colors;
  60. for(;*inner;inner++) {
  61. blink(*inner, duration);
  62. }
  63. }
  64. }
  65.  
  66. void blink(int color[], int duration) {
  67. on(color);
  68. delay(duration);
  69. off(color);
  70. }
  71.  
  72. void blinkSequence(int* colors[]) {
  73. for(;*colors;colors++) {
  74. blink(*colors);
  75. }
  76. }
  77.  
  78. void blink(int color[]) {
  79. on(color);
  80. delay(DEFAULT_DURATION);
  81. off(color);
  82. }
  83.  
  84. void on(int color[]) {
  85. for(;*color;color++) {
  86. digitalWrite(*color, HIGH);
  87. //Serial.print("HIGH:");
  88. //Serial.println(*color);
  89. }
  90. }
  91.  
  92. void off(int color[]) {
  93. for(;*color;color++) {
  94. digitalWrite(*color, LOW);
  95. //Serial.print("LOW:");
  96. //Serial.println(*color);
  97. }
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement