Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*2710/2022
- nextion Serial 2
- GPS SerialGPS RX 17 TX 16
- hum dan NPK SErial NPK RS 27 TX 32 or 14
- editing nextion OK
- editing NPK not ok - 27/10
- */
- #include <TinyGPS++.h>
- TinyGPSPlus gps;
- //#define ss Serial1
- #include <WiFi.h>
- #define RXD_RS485 33 // rubah dari 27 ke 33
- #define TXD_RS485 32 //14 yg baru 32 yg lm
- #define pinLed 13
- #define RXD_GPS 17
- #define TXD_GPS 16
- String str_lat = "";
- String str_lon = "";
- String str_date = "";
- String str_time = "";
- int myIP;
- int _gauge_display;
- int val_sen, val_min;
- double val_max;
- const char* ssid = "untan";
- const char* password = "";
- int buf_detik, detik = 0;
- int jam, menit;
- int tahun, bulan, tanggal;
- int counter;
- int pin_value = 0;
- int progress_value;
- bool ledState = 0;
- /*Nextion */
- uint16_t voltageGraph; // a variable to store the reading
- // for simplicity reasons, we do not use float and we are going to take the measure in millivolts
- const int volt = 34;
- int potValue = 0;
- const int REFRESH_TIME = 3000; // time to refresh the Nextion page every 100 ms
- unsigned long refresh_timer = millis();
- unsigned long cur_time, old_time;
- const byte hum[] = {0x01, 0x03, 0x00, 0x00, 0x00, 0x02, 0xC4, 0x0B};
- //const byte hum[] = {0x01, 0x03, 0x02, 0x00, 0x00, 0x02, 0xC5, 0xB3};
- const byte temp[] = {0x01, 0x03, 0x00, 0x12, 0x00, 0x01, 0x24, 0x0f};
- const byte rh[] = {0x01, 0x03, 0x00, 0x00, 0x00, 0x02, 0xC4, 0x0B};
- const byte condutiv[] = {0x01, 0x03, 0x00, 0x15, 0x00, 0x01, 0x95, 0xCE};
- const byte ph[] = {0x01, 0x03, 0x00, 0x06, 0x00, 0x01, 0x64, 0x0B};
- const byte nitro[] = {0x01, 0x03, 0x00, 0x1E, 0x00, 0x01, 0xE4, 0x0C};
- const byte phos[] = {0x01, 0x03, 0x00, 0x1F, 0x00, 0x01, 0xB5, 0xCC};
- const byte pota[] = {0x01, 0x03, 0x00, 0x20, 0x00, 0x01, 0x85, 0xC0};
- //const byte code[]= {0x01, 0x03, 0x00, 0x1e, 0x00, 0x03, 0x65, 0xCD};
- //const byte sens[] = {0x01, 0x03, 0x00, 0x00, 0x00, 0x07, 0x04, 0x08};
- //const byte hum[] = {0x01, 0x03, 0x00, 0x12, 0x00, 0x02, 0x64, 0x0e};
- byte values[11];
- int val_hum = 0;
- int val_temp = 0;
- float val_ph = 0;
- int val_con, val_nitro, val_phos, val_pota;
- int val_rh;
- String humid, temper, acid, nitrog, posf, kalium, con; //mjd string buat nextion
- static uint8_t npkAddr = 1;
- byte val1, val2, val3, val4, val5, val6, val7; //mjd hex
- int nit, pho, kal, soiltmp, soilrh, soilhum, soilph; //mjd angka
- //byte baca_nitro, baca_phos, baca_pota; //menjadi HEX
- //int val_nitro, val_phos, val_pota; //menjadi angka
- //String nitrog, posf, kalium; //menjadi string buat nextion
- /*=========================================================================================================VOID SETUP===================================================================================*/
- void setup()
- {
- delay(100);
- pinMode(pinLed, OUTPUT);
- Serial.begin(115200);
- Serial2.begin(9600, SERIAL_8N1, 35, 15); // nextion serial
- delay(100);
- WiFi.mode(WIFI_STA);
- WiFi.begin(ssid, password);
- int timeout = 10 * 4; // 10 seconds
- while (WiFi.status() != WL_CONNECTED && (timeout-- > 0)) {
- delay(250);
- }
- Serial.println("");
- if (WiFi.status() != WL_CONNECTED) {
- Serial.println("Failed to connect");
- }
- //Serial.print("WiFi connected in: ");
- //Serial.print(millis());
- Serial.print(ssid);
- Serial.print(":");
- Serial.println(WiFi.localIP());
- myIP = WiFi.localIP();
- String statIP = String(myIP);
- tampil_text("IP", statIP);
- Serial.println(statIP);
- Serial.println(myIP);
- delay(100);
- }
- /*============================================================================================================VOID LOOP================================================================================*/
- void loop() {
- byte val1, val2, val3, val4, val5, val6, val7;
- //-------------------------------------task 1 -----------------------------------------------
- cur_time = millis();
- if (cur_time - old_time >= 3000) {
- Serial.println("baca Sensor");
- serial_rs485();
- //for (int i = 0; i < 11; i++) {
- //baca_hum();
- //baca_npk;
- val1 = baca_nitro();
- nit = val1;
- delay(250);
- Serial.print("N:");
- Serial.println(nit);
- val_nitro = val1;
- val2 = baca_phos();
- pho = val2;
- delay(250);
- Serial.print("P:");
- Serial.println(pho);
- val_phos=val2;
- val3 = baca_pota();
- kal = val3;
- delay(250);
- Serial.print("K:");
- Serial.println(kal);
- val_pota=val3;
- val4 = baca_hum();
- soilhum = val4;
- delay(250);
- Serial.print("Hum:");
- Serial.println(soilhum);
- val5 = baca_temp();
- soiltmp = val5;
- delay(250);
- Serial.print("Temp:");
- Serial.println(soiltmp);
- val6 = baca_rh();
- soilrh = val6;
- delay(250);
- Serial.print("EC:");
- Serial.println(soilrh);
- delay(250);
- val7 = baca_ph();
- soilph = val7;
- delay(250);
- Serial.print("pH:");
- Serial.println(soilph);
- delay(250);
- //}
- serial_gps();
- //sent_nextion;
- for (int i = 0; i < 3; i++) {
- read_gps();
- delay(250);
- }
- old_time = millis();
- }
- //-------------------------------------task 2 -----------------------------------------------
- if ((millis() - refresh_timer) > REFRESH_TIME) { //IMPORTANT do not have serial print commands in the loop without a delay
- // or an if statement with a timer condition like this one.
- //potValue = analogRead(volt); // Read the analog pin
- //voltageGraph = map(potValue, 0, 4095, 0, 100);
- //Serial.print("volt ");
- //Serial.println(voltageGraph);
- counter++;
- val_max = counter;
- Serial.println(val_max);
- //baca_npk;
- tampil_text("statssid", ssid);
- tampil_text("twea", "35");
- tampil_text("tweh", "79");
- kirim_val("jtemp", "35");
- kirim_slider("jtemp", 3);
- String Moisture = String(soilhum);
- String humid = String(soilhum);
- String temper = String(soiltmp);
- String con = String (soilrh);
- String acid = String (soilph);
- String nitrog = String(nit);
- String posf = String (pho);
- String kalium = String (kal);
- tampil_text("tp1", humid); //hum
- tampil_text("tp2", temper); //val_temp
- tampil_text("tp3", acid); //value 8
- tampil_text("tp4", con); // value tds
- tampil_text("t7", nitrog); // nitrogen = String (values[8]);
- tampil_text("t8", posf); //String posf = String (values[i]);
- tampil_text("t9", kalium); //String kalium = String (values[i]);
- tampil_text("t7", nitrog); // nitrogen = String (values[8]);
- tampil_text("t8", posf); //String posf = String (values[i]);
- tampil_text("t9", kalium); //String kalium = String (values[i]);
- tampil_text("tp4", con); // value tds
- tampil_text("th1", Moisture);
- tampil_text("th2", Moisture);
- tampil_text("th3", Moisture);
- tampil_text("th4", Moisture);
- tampil_text("th5", Moisture);
- tampil_text("th6", Moisture);
- kirim_val("j0", Moisture);
- kirim_val("jn", nitrog);
- kirim_val("jp", posf);
- kirim_val("jk", kalium);
- kirim_val("jth", Moisture);
- kirim_val("jtds", Moisture);
- kirim_val("jtur", Moisture);
- kirim_val("h0", humid); // tipe : text
- kirim_val("h1", temper);
- kirim_val("h2", acid);
- kirim_val("h3", con);
- kirim_val("z0", nitrog);
- kirim_val("z1", posf);
- kirim_val("z2", kalium);
- kirim_val("z3", Moisture);
- kirim_val("zf", Moisture);
- kirim_gauge("z0", val_nitro);
- kirim_gauge("z1", val_phos);
- kirim_gauge("z2", val_pota);
- kirim_gauge("z3", val_max);
- kirim_gauge("zf", val_max);
- kirim_slider("j0", val_max); //type text
- kirim_slider("jn", val1);
- kirim_slider("jp", val2);
- kirim_slider("jk", val3);
- kirim_slider("jth", val_max);
- kirim_slider("jtds", val_max);
- kirim_slider("jtur", val_max);
- kirim_slider("h0", val_hum);
- kirim_slider("h1", val_temp);
- kirim_slider("h2", val_ph);
- kirim_slider("h3", val_rh);
- tampil_text("tssn", Moisture);
- kirim_val("tssn", Moisture);
- //kirim_slider("tssn", Moisture);
- kirim_wave(val_max);
- refresh_timer = millis(); // Set the timer equal to millis, create a time stamp to start over the "delay"
- //old_time = millis();
- }
- }
- /*===================================================================================================================END VOID LOOP =========================================================================*/
- void serial_rs485() {
- Serial1.begin(4800, SERIAL_8N1, RXD_RS485, TXD_RS485);
- delay(500);
- }
- void serial_gps() {
- Serial1.begin(9600, SERIAL_8N1, RXD_GPS, TXD_GPS);
- delay(500);
- }
- void read_gps() {
- while (Serial1.available() > 0)
- if (gps.encode(Serial1.read()))
- displayInfo();
- if (millis() > 5000 && gps.charsProcessed() < 5) //jlh kirim koordinat d serial print
- {
- Serial.println(F("No GPS detected: check wiring."));
- while (true);
- }
- if (buf_detik != detik) {
- String str_buf_date = "";
- String str_buf_time = "";
- String str_tgl = "";
- String str_bln = "";
- String str_jam = "";
- String str_menit = "";
- String str_detik = "";
- str_bln = bulan < 10 ? "0" + String(bulan) : String(bulan);
- str_tgl = tanggal < 10 ? "0" + String(tanggal) : String(tanggal);
- str_buf_date = str_bln + "/" + str_tgl + "/" + String(tahun) + " ";
- str_date = str_buf_date;
- Serial.print(" tanggal/jam: ");
- Serial.print(str_date);
- tampil_text("t0", str_date);
- str_detik = detik < 10 ? "0" + String(detik) : String(detik);
- str_menit = menit < 10 ? "0" + String(menit) : String(menit);
- str_jam = jam < 10 ? "0" + String(jam) : String(jam);
- str_buf_time = str_jam + ":" + str_menit + ":" + str_detik;
- str_time = str_buf_time;
- Serial.print(str_time);
- Serial.println();
- tampil_text("t1", str_time);
- buf_detik = detik;
- }
- }
- void displayInfo() {
- if (gps.date.isValid())
- {
- bulan = gps.date.month();
- tanggal = gps.date.day();
- tahun = gps.date.year();
- }
- else
- {
- Serial.print(F("INVALID"));
- }
- if (gps.time.isValid())
- {
- jam = gps.time.hour();
- detik = gps.time.second();
- menit = gps.time.minute();
- //convert to local zone, indonesia + 7
- jam = jam + 7;
- if (jam >= 24 ) {
- jam = jam - 24;
- }
- }
- else
- {
- Serial.print(F("INVALID"));
- }
- String str_buf_lat = "";
- String str_buf_lon = "";
- String str_buf_date = "";
- String str_buf_time = "";
- Serial.print(F("Location: "));
- if (gps.location.isValid())
- {
- str_buf_lat = String(gps.location.lat(), 6);
- str_buf_lon = String(gps.location.lng(), 6);
- Serial.print(str_buf_lat); Serial.print(",");
- Serial.println(str_buf_lon);
- tampil_text("tkx", str_buf_lat);
- tampil_text("tky", str_buf_lon);
- }
- else
- {
- Serial.print(F("INVALID"));
- tampil_text("tkx", "LOST");
- tampil_text("tky", "SIGNAL");
- }
- }
- /*
- void sent_nextion() {
- tampil_text("statssid", ssid);
- tampil_text("twea", "35");
- tampil_text("tweh", "79");
- kirim_val("jtemp", "35");
- kirim_slider("jtemp", 3);
- String Moisture = String(val_hum);
- String humid = String(soilhum);
- String temper = String(soiltmp);
- String con = String (soilrh);
- String acid = String (soilph);
- String nitrog = String(nit);
- String posf = String (pho);
- String kalium = String (kal);
- tampil_text("tp1", humid); //hum
- tampil_text("tp2", temper); //val_temp
- tampil_text("tp3", acid); //value 8
- tampil_text("tp4", con); // value tds
- tampil_text("t7", nitrog); // nitrogen = String (values[8]);
- tampil_text("t8", posf); //String posf = String (values[i]);
- tampil_text("t9", kalium); //String kalium = String (values[i]);
- tampil_text("t7", nitrog); // nitrogen = String (values[8]);
- tampil_text("t8", posf); //String posf = String (values[i]);
- tampil_text("t9", kalium); //String kalium = String (values[i]);
- tampil_text("tp4", con); // value tds
- tampil_text("th1", Moisture);
- tampil_text("th2", Moisture);
- tampil_text("th3", Moisture);
- tampil_text("th4", Moisture);
- tampil_text("th5", Moisture);
- tampil_text("th6", Moisture);
- kirim_val("j0", Moisture);
- kirim_val("jn", Moisture);
- kirim_val("jp", Moisture);
- kirim_val("jk", Moisture);
- kirim_val("jth", Moisture);
- kirim_val("jtds", Moisture);
- kirim_val("jtur", Moisture);
- kirim_val("h0", Moisture);
- kirim_val("h1", Moisture);
- kirim_val("h2", Moisture);
- kirim_val("h3", Moisture);
- kirim_val("z0", Moisture);
- kirim_val("z1", Moisture);
- kirim_val("z2", Moisture);
- kirim_val("z3", Moisture);
- kirim_val("zf", Moisture);
- kirim_gauge("z0", val_max);
- kirim_gauge("z1", val_max);
- kirim_gauge("z2", val_max);
- kirim_gauge("z3", val_max);
- kirim_gauge("zf", val_max);
- kirim_slider("j0", val_max);
- kirim_slider("jn", val_max);
- kirim_slider("jp", val_max);
- kirim_slider("jk", val_max);
- kirim_slider("jth", val_max);
- kirim_slider("jtds", val_max);
- kirim_slider("jtur", val_max);
- kirim_slider("h0", val_max);
- kirim_slider("h1", val_max);
- kirim_slider("h2", val_max);
- kirim_slider("h3", val_max);
- tampil_text("tssn", Moisture);
- kirim_val("tssn", Moisture);
- //kirim_slider("tssn", Moisture);
- kirim_wave(val_max);
- }
- /*====================================================================================================*/
- /*
- byte baca_hum() {
- delay(10);
- if (Serial1.write(hum, sizeof(hum)) == 8) {
- for (byte i = 0; i < 9; i++) {
- values[i] = Serial1.read();
- Serial.print(values[i], HEX);
- Serial.print(",");
- }
- Serial.println();
- }
- Serial.print(values[3], HEX);
- Serial.println(values[4], HEX);
- Serial.print(values[5], HEX);
- Serial.println(values[6], HEX);
- val_hum = (values[3] << 8);// | values[4];
- val_temp = (values[5] << 8);// | values[6];
- String Moisture = String(val_hum);
- String Soiltemp = String(val_temp);
- Serial.print("hum: ");
- Serial.println(val_hum);
- tampil_text("tp1", Moisture); //hum
- Serial.print("temp: ");
- Serial.println(val_temp);
- tampil_text("tp3", soiltemp); //value 8
- return values[4];
- }*/
- /*=================================================================================================================================================================================================*/
- byte baca_hum() {
- delay(10);
- if (Serial1.write(hum, sizeof(hum)) == 8) {
- for (byte i = 0; i < 7; i++) {
- values[i] = Serial1.read();
- Serial.print(values[i], HEX);
- Serial.print(",");
- val_hum = (values[i], HEX);
- //String con = String (val_rh);
- //tampil_text("tp4", con); // value tds
- }
- Serial.println();
- }
- return values[4];
- }
- byte baca_temp() {
- delay(10);
- if (Serial1.write(temp, sizeof(temp)) == 8) {
- for (byte i = 0; i < 7; i++) {
- values[i] = Serial1.read();
- Serial.print(values[i], HEX);
- Serial.print(",");
- val_temp = (values[i], HEX);
- //String con = String (val_rh);
- //tampil_text("tp4", con); // value tds
- }
- Serial.println();
- }
- return values[4];
- }
- byte baca_rh() {
- delay(10);
- if (Serial1.write(rh, sizeof(rh)) == 8) {
- for (byte i = 0; i < 7; i++) {
- values[i] = Serial1.read();
- Serial.print(values[i], HEX);
- Serial.print(",");
- val_rh = (values[i], HEX);
- //String con = String (val_rh);
- //tampil_text("tp4", con); // value tds
- }
- Serial.println();
- }
- return values[4];
- }
- byte baca_con() {
- delay(10);
- if (Serial1.write(condutiv, sizeof(condutiv)) == 8) {
- for (byte i = 0; i < 7; i++) {
- values[i] = Serial1.read();
- Serial.print(values[i], HEX);
- val_con = (values[i], HEX);
- Serial.print(",");
- }
- Serial.println();
- }
- return values[4];
- }
- byte baca_ph() {
- delay(100);
- if (Serial1.write(ph, sizeof(ph)) == 8) {
- for (byte i = 0; i < 7; i++) {
- values[i] = Serial1.read();
- Serial.print(values[i], HEX);
- //String soilph = String (values[i], HEX);
- //tampil_text("tp3", soilph); // ph = String (values[8]);
- Serial.print(",");
- }
- Serial.println();
- }
- return values[4];
- }
- byte baca_nitro() {
- delay(10);
- if (Serial1.write(nitro, sizeof(nitro)) == 8) {
- for (byte i = 0; i < 7; i++) {
- values[i] = Serial1.read();
- Serial.print(values[i], HEX);
- val_nitro = (values[i], HEX);
- //tampil_text("t7", nitrogen); // nitrogen = String (values[8]);
- Serial.print(",");
- }
- Serial.println();
- }
- return values[4];
- }
- byte baca_phos() {
- delay(10);
- if (Serial1.write(phos, sizeof(phos)) == 8) {
- for (byte i = 0; i < 7; i++) {
- values[i] = Serial1.read();
- Serial.print(values[i], HEX);
- //String posf = String (values[i], HEX);
- //tampil_text("t8", posf); //String posf = String (values[i]);
- Serial.print(",");
- }
- Serial.println();
- }
- return values[4];
- }
- byte baca_pota() {
- delay(10);
- if (Serial1.write(pota, sizeof(pota)) == 8) {
- for (byte i = 0; i < 7; i++) {
- values[i] = Serial1.read();
- Serial.print(values[i], HEX);
- //String kalium = String (values[i], HEX);
- //tampil_text("t9", kalium); //String kalium = String (values[i]);
- Serial.print(",");
- }
- Serial.println();
- }
- return values[4];
- }
- /*========================================================================================================================================================================================================
- void baca_npk() {
- //for (int i = 0; i < 11; i++) {
- val1 = baca_nitro();
- nit = val1;
- delay(250);
- Serial.print("N:");
- Serial.println(nit);
- val2 = baca_phos();
- pho = val2;
- delay(250);
- Serial.print("P:");
- Serial.println(pho);
- val3 = baca_pota();
- kal = val3;
- delay(250);
- Serial.print("K:");
- Serial.println(kal);
- val4 = baca_hum();
- soilhum = val4;
- delay(250);
- Serial.print("Hum:");
- Serial.println(soilhum);
- val5 = baca_temp();
- soiltmp = val5;
- delay(250);
- Serial.print("Temp:");
- Serial.println(soiltmp);
- val6 = baca_rh();
- soilrh = val6;
- delay(250);
- Serial.print("EC:");
- Serial.println(soilrh);
- delay(250);
- val7 = baca_ph();
- soilph = val7;
- delay(250);
- Serial.print("pH:");
- Serial.println(soilph);
- delay(250);
- /*String (nitrog) = String(nit);
- Serial.println(" mg/kg");
- tampil_text("t7", nitrog); // nitrogen = String (values[8]);
- Serial.print("Phosphorous: ");
- Serial.print(pho);
- Serial.println(" mg/kg");
- //String posf = String (pho);
- //tampil_text("t8", posf); //String posf = String (values[i]);
- Serial.print("Potassium: ");
- Serial.print(kal);
- Serial.println(" mg/kg");
- //String kalium = String (kal);
- //tampil_text("t9", kalium); //String kalium = String (values[i]);
- Serial.print("EC: ");
- Serial.print(val_rh);
- Serial.println(" us");
- //String con = String (val_rh);
- //tampil_text("tp4", con); // value tds*/
- //}
- /*============================================================================================================================================================================================*/
- void tampil_text(String _add_txt, String _txt_display) {
- String buf_txt = _add_txt + ".txt=" + "\"" + _txt_display + "\"";
- Serial2.print(buf_txt);
- Serial2.write(0xff);
- Serial2.write(0xff);
- Serial2.write(0xff);
- }
- void kirim_val(String _add_slide, String _txt_display) {
- String buf_slider = _add_slide + ".val=" + "\"" + _txt_display + "\"";
- Serial2.print(buf_slider);
- Serial2.write(0xff);
- Serial2.write(0xff);
- Serial2.write(0xff);
- }
- void kirim_gauge(String _add_gauge, int _gauge_display) {
- String warna_jingga = _add_gauge + ".pco=64520";
- String warna_merah = _add_gauge + ".pco=63488";
- String warna_kuning = _add_gauge + ".pco=65519";
- String warna_hijau = _add_gauge + ".pco=34784";
- String warna_bg_green = _add_gauge + ".pco=1024";
- int sensgauge = constrain(_gauge_display, 0, 255); //(buf_senval,0,2048);
- int val_gauge = map(sensgauge, 0, 255, 0, 180); //(sens, 300, 2048, 50, 0);
- Serial2.print("valgauge");
- Serial2.print(val_gauge);
- Serial2.print(_add_gauge);
- Serial2.print(".val=");
- Serial2.print(val_gauge);
- Serial2.write(0xff);
- Serial2.write(0xff);
- Serial2.write(0xff);
- //String buf_gauge = _add_gauge + ".val=" + "\"" + val_gauge+ "\"";
- //Serial1.print(buf_gauge);
- if (val_gauge <= 15) { //}for (val_min > 80; val_min <= 100; val_min++){
- Serial2.print(warna_merah);
- Serial2.write(0xff);
- Serial2.write(0xff);
- Serial2.write(0xff);
- } else if ((val_gauge > 15) && (val_gauge <= 37)) {
- Serial2.print(warna_jingga);
- Serial2.write(0xff);
- Serial2.write(0xff);
- Serial2.write(0xff);
- } else if ((val_gauge > 37) && (val_gauge <= 60)) {
- Serial2.print(warna_kuning);
- Serial2.write(0xff);
- Serial2.write(0xff);
- Serial2.write(0xff);
- } else if ((val_gauge > 60) && (val_gauge <= 80)) {
- Serial2.print(warna_hijau);
- Serial2.write(0xff);
- Serial2.write(0xff);
- Serial2.write(0xff);
- } else if ((val_gauge > 80) && (val_gauge <= 100)) {
- Serial2.print(warna_bg_green);
- Serial2.write(0xff);
- Serial2.write(0xff);
- Serial2.write(0xff);
- } delay(100);
- }
- void kirim_slider(String _add_col, int val_sen) {
- //String warna_biru = _add_col + ".pco=64520";
- String warna_merah = _add_col + ".pco=63488";
- String warna_kuning = _add_col + ".pco=65519";
- String warna_hijau = _add_col + ".pco=34784";
- String warna_bg_green = _add_col + ".pco=1024";
- //int buf_senval = val_sen.toInt();
- int sens = constrain(val_sen, 0, 400); //(buf_senval,0,2048);
- int val_min = map(sens, 0, 400, 0, 100); //(sens, 300, 2048, 50, 0);
- //String buf_slider = _add_col + ".val=" + "\"" + val_min+ "\"";
- //Serial1.print(buf_slider);
- Serial2.print(_add_col);
- Serial2.print(".val=");
- Serial2.print(val_min);
- Serial2.write(0xff);
- Serial2.write(0xff);
- Serial2.write(0xff);
- if (val_min <= 20) { //}for (val_min > 80; val_min <= 100; val_min++){
- Serial2.print(warna_merah);
- Serial2.write(0xff);
- Serial2.write(0xff);
- Serial2.write(0xff);
- } else if ((val_min > 20) && (val_min <= 40)) {
- Serial2.print(warna_hijau);
- Serial2.write(0xff);
- Serial2.write(0xff);
- Serial2.write(0xff);
- } else if ((val_min > 40) && (val_min <= 60)) {
- Serial2.print(warna_bg_green);
- Serial2.write(0xff);
- Serial2.write(0xff);
- Serial2.write(0xff);
- } else if ((val_min > 60) && (val_min <= 80)) {
- Serial2.print(warna_kuning);
- Serial2.write(0xff);
- Serial2.write(0xff);
- Serial2.write(0xff);
- } else if ((val_min > 80) && (val_min <= 100)) {
- Serial2.print(warna_merah);
- Serial2.write(0xff);
- Serial2.write(0xff);
- Serial2.write(0xff);
- } delay(100);
- }
- void kirim_wave(int wave_val) {
- int senswave = constrain(wave_val, 0, 255); //(buf_senval,0,2048);
- int val_wave = map(senswave, 0, 255, 0, 255); //(sens, 300, 2048, 50, 0);
- Serial1.print("valwave");
- Serial1.print(val_wave);
- //Serial1.print("add 1,1," + val_wave);
- String tosend = "add ";
- tosend += 1;//id
- tosend += ",";
- tosend += 1; //channel
- tosend += ",";
- tosend += val_wave;
- Serial1.print(tosend);
- Serial1.write(0xff);
- Serial1.write(0xff);
- Serial1.write(0xff);
- delay(600);
- }
Add Comment
Please, Sign In to add comment