diff --git a/src/main_2/main_2.ino b/src/main_2/main_2.ino index 9e26c4253d48dc85f898543c43ae442655129c04..2cc61271f4100de2f1fc217708364376d53ac8b2 100644 --- a/src/main_2/main_2.ino +++ b/src/main_2/main_2.ino @@ -79,6 +79,7 @@ void setup() { // Turn on the blacklight and print a message. lcd.backlight(); ReadJson(); + lcd.setCursor(0,0); } void loop() { @@ -93,9 +94,8 @@ void loop() { // get the value to be displayed and update one digit //update_one_digit(years % digit_base); - lcd.setCursor(0,0); + lcd.autoscroll(); - //lcd.print(GenerateJSONString()); //lcd.print("Hello! Welcome to GreenTyNo :)"); delay(1000); @@ -106,8 +106,8 @@ void loop() { buzzerHigh = false; } - // Serial.print("Soil Moisture = "); - Serial.println(readSoil()); + //Serial.print("Soil Moisture = "); + Serial.print(readSoil()); if (readSoil() > 60) { // Serial.println("wet soil"); digitalWrite(ledPin, LOW); @@ -133,7 +133,8 @@ void loop() { //Serial.print("cahaya: "); //prints the values coming from the sensor on the screen float vout0 = valueLDR*0.0048828125; // calculate the voltage int lux0 = 500/(res0*((5-vout0)/vout0)); // calculate the Lux - //Serial.println(lux0); + Serial.print(':'); + Serial.println(lux0); lcd.print(GenerateSoilandLightText(readSoil(),lux0)); // delay(1000); //​take a reading every second @@ -143,11 +144,11 @@ void loop() { void PythonCommunication() { if (Serial.available() > 0) { int test; - char charRead= Serial.read(); + char charRead= Serial.read(); if(charRead >= '0' && charRead <= '9') { test = (10 * test) + (charRead - '0') ; // convert digits to a number + update_one_digit(test); } - update_one_digit(test); } } diff --git a/src/python/getSerial.py b/src/python/getSerial.py index 1ed7e099d93bf028fd7b2c75a480b537d8e1adc6..56ebae49358da7a6663e08935085fd44b55a5dfe 100644 --- a/src/python/getSerial.py +++ b/src/python/getSerial.py @@ -1,10 +1,28 @@ -import serial, struct, time -ser = serial.Serial('COM3') # open serial port +import serial, struct, time, urllib.request, json + +with urllib.request.urlopen("https://tranquil-citadel-63668.herokuapp.com/api/status") as url: + data = json.loads(url.read().decode()) + +year = data['year'] +print(year) + +ser = serial.Serial('COM8') # open serial port print(ser.name) # check which port was really used # ser.write(b'\x04') # write a string # ser.write(struct.pack('>B',1)) +# print(b'4' + b'0') +# print(struct.pack('b',3)) +# print(struct.pack('>B',year + 48)) while True : line = ser.readline() - print(line.decode().split('\r\n')[0]) + ser.write(struct.pack('>B',year + 48)) + # ser.write(struct.pack('>i',year)) + raw = line.decode().split('\r\n')[0] + arr = raw.split(':') + print(arr) + k = arr[0] + c = arr[1] + print(k) + print(c) ser.close() # close port \ No newline at end of file