Arduino – Smart Garden Study-Board
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
#include <SoftwareSerial.h> SoftwareSerial BTSerial(2,3); #include <Wire.h> #include <LiquidCrystal_I2C.h> LiquidCrystal_I2C lcd(0x27, 16, 2); char chr[25]; int index=0; int varCDS=0, varSOIL=0, T=0, H=0; int piezo=A3; int ledA=6; int ledB=13; unsigned long cnt=0; byte user_value1[8]={ B00000, B00100, B00100, B01110, B11111, B11101, B01110, B00000 }; void setup() { lcd.init(); lcd.backlight(); lcd.createChar(0, user_value1); Serial.begin(9600); BTSerial.begin(9600); pinMode(ledA, OUTPUT); pinMode(ledB, OUTPUT); } void loop() { char temp; if (BTSerial.available()) { temp=BTSerial.read(); if (index==0) { while (temp!='$') { temp=BTSerial.read(); } } chr[index]=temp; index++; Serial.print(temp); } if (temp=='\n') { index=0; sscanf(chr, "$IOT,%d,%d,%d,%d,", &varCDS, &varSOIL, &T, &H); lcd.setCursor(0,0); lcd.print("C:"); for (int i=0;i<4-String(varCDS).length();i++) { lcd.print(" "); } lcd.print(varCDS); lcd.setCursor(8,0); lcd.print("S:"); for (int i=0;i<4-String(varSOIL).length();i++) { lcd.print(" "); } lcd.print(varSOIL); lcd.setCursor(15,0); if (varSOIL < 500) { if (cnt==0) { cnt=millis(); tone(piezo, 1319); lcd.write(0); digitalWrite(ledA, HIGH); digitalWrite(ledB, LOW); } else if (millis() > cnt+1000) { cnt=0; } else if (millis() > cnt+500) { tone(piezo, 1047); lcd.print(" "); digitalWrite(ledA, LOW); digitalWrite(ledB, HIGH); } } else { lcd.print(" "); cnt=0; noTone(piezo); } lcd.setCursor(0,1); lcd.print("T:"); lcd.print(T); lcd.write(223); lcd.print("C"); lcd.setCursor(8,1); lcd.print("H:"); lcd.print(H); lcd.print("%"); } } |