Skip to content

Commit

Permalink
New
Browse files Browse the repository at this point in the history
  • Loading branch information
dracuten1 committed Feb 18, 2019
0 parents commit ebc7db0
Show file tree
Hide file tree
Showing 66 changed files with 3,416 additions and 0 deletions.
772 changes: 772 additions & 0 deletions Board_1/Board_1.ino

Large diffs are not rendered by default.

282 changes: 282 additions & 0 deletions Board_2/Board_2.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,282 @@
#include <SerialCommand.h> // Thêm vào sketch thư viện Serial Command
#include <Adafruit_NeoPixel.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>

#define CELL_RELAY 6
#define TEMP_RELAY 4
#define WATER_RELAY 5
#define PIN 7
SerialCommand sCmd; // Khai báo biến sử dụng thư viện Serial Command
LiquidCrystal_I2C lcd(0x27, 20, 4);//Thêm màn hình lcd


float tempCon=30;
float humiCon=75;
int luxCon=600;

class LightController{
private:
const int NUMPIXELS =16;

int _currentLedOff=0;
int _r=255;
int _g=255;
int _b=255;

Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);

void TurnOnALed(){
if(_currentLedOff>0){
_currentLedOff = _currentLedOff - 1;
}
}
void TurnOffALed(){
if(_currentLedOff<NUMPIXELS){
_currentLedOff =_currentLedOff+ 1;
}
}

public:
void ControlNeoColor() {
for(int i=0;i<NUMPIXELS;i++){
if(i==8){
int temp=_r;
_r=_g;
_g=temp;
}
if(i<_currentLedOff){
pixels.setPixelColor(i, pixels.Color(0,0,0));
}else{
pixels.setPixelColor(i, pixels.Color(_r,_g,_b));
}
}
int temp=_r;
_r=_g;
_g=temp;
pixels.show();
}
void SetColor(int r, int g, int b){
//Serial.println("Color");
//Serial.print(r);
//Serial.println(g);
//Serial.println(b);

_r=r;
_g=g;
_b=b;
ControlNeoColor();
}
void SetRColor(int r){
_r=r;
}
void SetGColor(int r){
_g=r;
}
void SetBColor(int r){
_b=r;
}
void Control(int currentLux){
//Serial.println("LightController");
if(currentLux==0){
TurnOffALed();
}else {
TurnOnALed();
}
ControlNeoColor();
}
LightController(){
pixels.begin();
SetColor(255,0,0);
}
};

LightController *light;
void setup() {
//Khởi tạo Serial ở baudrate 9600 (trùng với HOST)
Serial.begin(19200);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
lcd.begin();
// Print a message to the LCD.
lcd.backlight();
//pinMode 2 đèn LED là OUTPUT
light=new LightController();
pinMode(TEMP_RELAY,OUTPUT);
pinMode(WATER_RELAY,OUTPUT);
pinMode(CELL_RELAY,OUTPUT);
String s="Set up....";
lcd.setCursor(0,0);
lcd.print(s);

// Một số hàm trong thư viện Serial Command

// Khi có câu lệnh tên là LED_RED sẽ chạy hàm led_red


sCmd.addCommand("Light_R", LightR);
sCmd.addCommand("Light_G", LightG);
sCmd.addCommand("Light_B", LightB);
sCmd.addCommand("Set_Temp",Temp);
sCmd.addCommand("Temp_Relay", SetTempCon);
sCmd.addCommand("Set_Lux",Lux);
sCmd.addCommand("Lux_Control", SetLuxCon);
sCmd.addCommand("Set_Humi",Water);
sCmd.addCommand("Humi_Relay", HumiCon);
s="Set up done";
lcd.setCursor(0,0);
lcd.print(s);
//Serial.println("Setup done");
}

void loop() {
sCmd.readSerial();
light->ControlNeoColor();
//Bạn không cần phải thêm bất kỳ dòng code nào trong hàm loop này cả
}

void HumiCon(){
//Đoạn code này dùng để đọc TỪNG tham số. Các tham số mặc định có kiểu dữ liệu là "chuỗi"
char *arg;
arg = sCmd.next();
float value = atof(arg);
humiCon=value;
}
void SetTempCon(){
char *arg;
arg = sCmd.next();
//Serial.print("Water");

float value = atof(arg); // Chuyển chuỗi thành số
tempCon=value;
//Serial.print("Set temp control");
}
void SetLuxCon(){

char *arg;
arg = sCmd.next();
//Serial.print("Water");

int value = atoi(arg); // Chuyển chuỗi thành số
luxCon=value;
//Serial.print("Set lux control");
}
// hàm led_red sẽ được thực thi khi gửi hàm LED_RED
void Water() {
//Đoạn code này dùng để đọc TỪNG tham số. Các tham số mặc định có kiểu dữ liệu là "chuỗi"
char *arg;
arg = sCmd.next();
//Serial.print("Water");

float value = atof(arg); // Chuyển chuỗi thành số
//Serial.println(value);
String s=" ";
lcd.setCursor(0,0);
lcd.print(s);
lcd.setCursor(0,0);
s="Do am: ";
s+=arg;
lcd.print(s);
if(value>humiCon+2){
digitalWrite(WATER_RELAY,LOW);
}
else if(value<humiCon-2){
digitalWrite(WATER_RELAY,HIGH);
}
}

// hàm led_blue sẽ được thực thi khi gửi hàm LED_BLUE
void Temp() {
//Đoạn code này dùng để đọc TỪNG tham số. Các tham số mặc định có kiểu dữ liệu là "chuỗi"
char *arg;
arg = sCmd.next();

int value = atoi(arg); // Chuyển chuỗi thành số
Serial.print("Temp: ");
Serial.println(value);
String s=" ";
lcd.setCursor(0,1);
lcd.print(s);
lcd.setCursor(0,1);
s="Nhiet do: ";
s+=arg;
lcd.print(s);
if(value>tempCon+0.5){
digitalWrite(TEMP_RELAY,LOW);
digitalWrite(CELL_RELAY,HIGH);
}
else if(value<tempCon-0.5){
digitalWrite(TEMP_RELAY,HIGH);
digitalWrite(CELL_RELAY,LOW)
}
else if(value<=tempCon+0.2||value>=tempCon-0.2){
digitalWrite(TEMP_RELAY,LOW);
digitalWrite(CELL_RELAY,LOW);
}
}
void Lux(){
//Đoạn code này dùng để đọc TỪNG tham số. Các tham số mặc định có kiểu dữ liệu là "chuỗi"
char *arg;
arg = sCmd.next();

int value = atoi(arg); // Chuyển chuỗi thành số
String s=" ";
lcd.setCursor(0,2);
lcd.print(s);
lcd.setCursor(0,2);
s="Do sang: ";
s+=arg;
lcd.print(s);
//Serial.println("LightController");
if(value > luxCon+ 30){
//Serial.println("Lux_control 0");
light->Control(0);
}else if(value < luxCon - 30){
//Serial.println("Lux_control 1");
light->Control(1);
}

}
void LightR(){
//Đoạn code này dùng để đọc TỪNG tham số. Các tham số mặc định có kiểu dữ liệu là "chuỗi"
char *arg;
arg = sCmd.next();
int r = atoi(arg); // Chuyển chuỗi thành số
light->SetRColor(r);
String s=" ";
lcd.setCursor(0,3);
lcd.print(s);
lcd.setCursor(0,3);
s="R: ";
s+=arg;
lcd.print(s);
}
void LightG(){
//Đoạn code này dùng để đọc TỪNG tham số. Các tham số mặc định có kiểu dữ liệu là "chuỗi"
char *arg;
arg = sCmd.next();
int r = atoi(arg); // Chuyển chuỗi thành số
light->SetGColor(r);
String s=" ";
lcd.setCursor(7,3);
lcd.print(s);
lcd.setCursor(7,3);
s="G: ";
s+=arg;
lcd.print(s);
}
void LightB(){
//Đoạn code này dùng để đọc TỪNG tham số. Các tham số mặc định có kiểu dữ liệu là "chuỗi"
char *arg;
arg = sCmd.next();
int r = atoi(arg); // Chuyển chuỗi thành số
light->SetBColor(r);
String s=" ";
lcd.setCursor(14,3);
lcd.print(s);
lcd.setCursor(14,3);
s="B: ";
s+=arg;
lcd.print(s);
}
11 changes: 11 additions & 0 deletions MushRoom/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
*.iml
.gradle
/local.properties
/.idea/caches/build_file_checksums.ser
/.idea/libraries
/.idea/modules.xml
/.idea/workspace.xml
.DS_Store
/build
/captures
.externalNativeBuild
29 changes: 29 additions & 0 deletions MushRoom/.idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions MushRoom/.idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 34 additions & 0 deletions MushRoom/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions MushRoom/.idea/runConfigurations.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions MushRoom/app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
Loading

0 comments on commit ebc7db0

Please sign in to comment.