Skip to content
Snippets Groups Projects
Commit 6d35e848 authored by 13515029 - Finiko Kasula Novenda's avatar 13515029 - Finiko Kasula Novenda
Browse files

Add main_2

parent e93b91e0
Branches
No related merge requests found
...@@ -3,7 +3,6 @@ ...@@ -3,7 +3,6 @@
#include <Wire.h> #include <Wire.h>
#include <LiquidCrystal_I2C.h> #include <LiquidCrystal_I2C.h>
#include <ArduinoJson.h> #include <ArduinoJson.h>
//#include <TimeLib.h>
const int ledPin = 2; const int ledPin = 2;
const int buttonPin = 4; const int buttonPin = 4;
...@@ -43,7 +42,8 @@ const byte digit_pattern[10] = ...@@ -43,7 +42,8 @@ const byte digit_pattern[10] =
B01101111, // 9 B01101111, // 9
}; };
unsigned int counter = 0; int counter = 0;
int sign = 50;
bool isSuccess; bool isSuccess;
int years; int years;
...@@ -52,10 +52,6 @@ int light; ...@@ -52,10 +52,6 @@ int light;
char json[] = "{\"success\":true,\"year\":3,\"humidity\":5,\"light\":10}"; char json[] = "{\"success\":true,\"year\":3,\"humidity\":5,\"light\":10}";
//#define TIME_MSG_LEN 11 // time sync to PC is HEADER and unix time_t as ten ascii digits
//#define TIME_HEADER 'T' // Header tag for serial time sync message
void setup() { void setup() {
// put your setup code here, to run once: // put your setup code here, to run once:
Serial.begin(9600); Serial.begin(9600);
...@@ -79,26 +75,23 @@ void setup() { ...@@ -79,26 +75,23 @@ void setup() {
// Turn on the blacklight and print a message. // Turn on the blacklight and print a message.
lcd.backlight(); lcd.backlight();
ReadJson(); ReadJson();
lcd.setCursor(0,0); //lcd.autoscroll();
} }
void loop() { void loop() {
counter = counter + sign;
int i; if (counter >= 255) {
unsigned int digit_base; sign = -50;
} else if (counter <= 0) {
counter++; sign = 25;
}
digit_base = 10;
// get the value to be displayed and update one digit // get the value to be displayed and update one digit
//update_one_digit(years % digit_base); PythonCommunication();
lcd.autoscroll();
//lcd.print("Hello! Welcome to GreenTyNo :)");
delay(1000);
lcd.setCursor(0,0);
lcd.scrollDisplayLeft();
// put your main code here, to run repeatedly: // put your main code here, to run repeatedly:
buttonState = digitalRead(buttonPin); buttonState = digitalRead(buttonPin);
...@@ -106,7 +99,6 @@ void loop() { ...@@ -106,7 +99,6 @@ void loop() {
buzzerHigh = false; buzzerHigh = false;
} }
//Serial.print("Soil Moisture = ");
Serial.print(readSoil()); Serial.print(readSoil());
if (readSoil() > 60) { if (readSoil() > 60) {
// Serial.println("wet soil"); // Serial.println("wet soil");
...@@ -123,22 +115,20 @@ void loop() { ...@@ -123,22 +115,20 @@ void loop() {
} }
if(buzzerHigh) { if(buzzerHigh) {
digitalWrite(buzzer, HIGH); analogWrite(buzzer, counter);
delay(200); //delay(200);
digitalWrite(buzzer, LOW); //digitalWrite(buzzer, LOW);
delay(1000); //delay(1000);
} }
valueLDR = analogRead(sensorLDR); // read the value from the sensor valueLDR = analogRead(sensorLDR); // read the value from the sensor
//Serial.print("cahaya: "); //prints the values coming from the sensor on the screen
float vout0 = valueLDR*0.0048828125; // calculate the voltage float vout0 = valueLDR*0.0048828125; // calculate the voltage
int lux0 = 500/(res0*((5-vout0)/vout0)); // calculate the Lux int lux0 = 500/(res0*((5-vout0)/vout0)); // calculate the Lux
Serial.print(':'); Serial.print(':');
Serial.println(lux0); Serial.println(lux0);
lcd.print(GenerateSoilandLightText(readSoil(),lux0)); lcd.print(GenerateSoilandLightText(readSoil(),lux0));
// delay(1000); //​take a reading every second delay(1000); //​take a reading every second
PythonCommunication();
} }
void PythonCommunication() { void PythonCommunication() {
...@@ -153,7 +143,7 @@ void PythonCommunication() { ...@@ -153,7 +143,7 @@ void PythonCommunication() {
} }
String GenerateSoilandLightText(int soil, int light) { String GenerateSoilandLightText(int soil, int light) {
return ("GreenTyno Humidity : "+ String(soil) + " RB Light : " + String(light) +" Lux"); return ("GreenTyno Humidity "+ String(soil) + " RB Light " + String(light) +" Lux ");
} }
int readSoil() { int readSoil() {
...@@ -165,9 +155,7 @@ int readSoil() { ...@@ -165,9 +155,7 @@ int readSoil() {
return 1023-val; //send current moisture value return 1023-val; //send current moisture value
} }
void update_one_digit(int data) void update_one_digit(int data) {
{
int i;
byte pattern; byte pattern;
// get the digit pattern to be updated // get the digit pattern to be updated
...@@ -206,41 +194,6 @@ String GenerateJSONString() { ...@@ -206,41 +194,6 @@ String GenerateJSONString() {
totalString = "|GreenTyno | Humidity : "+ humidityString + " Light : " + lightString +" |"; totalString = "|GreenTyno | Humidity : "+ humidityString + " Light : " + lightString +" |";
return (totalString); return (totalString);
} }
/*
int GetCurrentTime() {
//GetPCTime();
//setTime(0);
//Serial.println(Serial.available());
if (Serial.available() > 0) {
GetPCTime();
}
if(timeStatus() != timeNotSet) {
Serial.println(year());
return(year());
} else {
return (0);
}
}
void GetPCTime() {
// if time available from serial port, sync the DateTime library
while(Serial.available() >= TIME_MSG_LEN ){ // time message
//Serial.println(Serial.read());
if( Serial.read() == TIME_HEADER ) {
time_t pctime = 0;
for(int i=0; i < TIME_MSG_LEN -1; i++){
char charRead= Serial.read();
if( charRead >= '0' && charRead <= '9') {
pctime = (10 * pctime) + (charRead - '0') ; // convert digits to a number
}
}
setTime(pctime);
Serial.println(pctime);
//Serial.println();
}
}
}*/
void InitializeClient() { void InitializeClient() {
pinMode(13, OUTPUT); pinMode(13, OUTPUT);
......
...@@ -4,25 +4,23 @@ with urllib.request.urlopen("https://tranquil-citadel-63668.herokuapp.com/api/st ...@@ -4,25 +4,23 @@ with urllib.request.urlopen("https://tranquil-citadel-63668.herokuapp.com/api/st
data = json.loads(url.read().decode()) data = json.loads(url.read().decode())
year = data['year'] year = data['year']
print(year)
ser = serial.Serial('COM8') # open serial port ser = serial.Serial('COM8') # open serial port
print(ser.name) # check which port was really used print(ser.name) # check which port was really used
# ser.write(b'\x04') # write a string ser.write(struct.pack('>B',year + 48))
# ser.write(struct.pack('>B',1))
# print(b'4' + b'0')
# print(struct.pack('b',3))
# print(struct.pack('>B',year + 48))
while True : while True :
line = ser.readline() line = ser.readline()
ser.write(struct.pack('>B',year + 48))
# ser.write(struct.pack('>i',year))
raw = line.decode().split('\r\n')[0] raw = line.decode().split('\r\n')[0]
arr = raw.split(':') arr = raw.split(':')
print(arr) humidity = arr[0]
k = arr[0] light = arr[1]
c = arr[1]
print(k) #postUrl = "http://localhost/api-greentyno/updateStatus?humidity=" + humidity + "&light=" + light
print(c) #print(postUrl)
# print(humidity)
# print(light)
# with urllib.request.urlopen(postUrl) as url:
# print()# data = json.loads(url.read().decode())
ser.close() # close port ser.close() # close port
\ No newline at end of file
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment