Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int const RED[] = { 12, 0 };
- int const GREEN[] = { 11, 0 };
- int const ORANGE[] = { 11, 12, 0 };
- int const DEFAULT_DURATION = 1000;
- int const DEFAULT_COUNT = 1;
- void blink(int color[]);
- void blink(int color[], int duration, int count);
- void blinkSequence(int* color[]);
- void blinkSequence(int* color[], int duration, int count);
- void on(int color[]);
- void off(int color[]);
- void setup() {
- // initialize LED Pins as output
- Serial.begin(9600);
- pinMode(11, OUTPUT);
- pinMode(12, OUTPUT);
- pinMode(13, OUTPUT);
- digitalWrite(11, LOW);
- digitalWrite(12, LOW);
- digitalWrite(13, LOW);
- }
- void loop() {
- int m = analogRead(0);
- int interval = 2000;
- Serial.print("Moisture is: ");
- Serial.println(m);
- if (m <= 580) {
- //Really Dry!: 580-
- int* seq[] = { RED, ORANGE, 0 };
- blinkSequence(seq, 150, 2);
- interval = 0;
- } else if (m <= 700) {
- //Needs water: 700 - 581
- blink(RED, 500);
- interval = 500;
- } else if (m <= 740) {
- //Could be wetter: 740 - 701
- blink(ORANGE, 4000);
- interval = 50;
- } else if (m <= 870) {
- //Happy range: 870 - 741
- blink(GREEN, 5000);
- interval = 50;
- } else {
- //Overwatered: 870+
- int* seq[] = { GREEN, ORANGE, 0 };
- blinkSequence(seq, 200, 5);
- interval = 3000;
- }
- delay(interval);
- }
- void blinkSequence(int* colors[], int duration, int count) {
- for (int i = count; i > 0; i--) {
- int** inner = colors;
- for(;*inner;inner++) {
- blink(*inner, duration);
- }
- }
- }
- void blink(int color[], int duration) {
- on(color);
- delay(duration);
- off(color);
- }
- void blinkSequence(int* colors[]) {
- for(;*colors;colors++) {
- blink(*colors);
- }
- }
- void blink(int color[]) {
- on(color);
- delay(DEFAULT_DURATION);
- off(color);
- }
- void on(int color[]) {
- for(;*color;color++) {
- digitalWrite(*color, HIGH);
- //Serial.print("HIGH:");
- //Serial.println(*color);
- }
- }
- void off(int color[]) {
- for(;*color;color++) {
- digitalWrite(*color, LOW);
- //Serial.print("LOW:");
- //Serial.println(*color);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement