I don't really know what arduino code should look like for this to work.
Czy wolisz polską wersję strony elektroda?
Nie, dziękuję Przekieruj mnie tam
#include <Wire.h>
#include "SDL_Arduino_INA3221.h"
#include "Nextion.h"
SDL_Arduino_INA3221 ina3221;
#define BATTERY_1 1
#define BATTERY_2 2
//NexButton b0 = NexButton(0, 4, "n1");
NexNumber t0 = NexNumber(0, 4, "t0");
char buffer[10] = {0};
NexTouch *nex_listen_list[] =
{
NULL
};
void setup(void)
{
Serial.begin(115200);
ina3221.begin();
}
void loop(void)
{
// Serial.println("------------------------------");
float busvoltage1 = 0;
busvoltage1 = ina3221.getBusVoltage_V(BATTERY_1);
t0.setText=(busvoltage1);
//Serial.print("LIPO_Battery Bus Voltage: "); Serial.print(busvoltage1); Serial.println(" V");
//Serial.println("");
float busvoltage2 = 0;
busvoltage2 = ina3221.getBusVoltage_V(BATTERY_2);
// Serial.print("Solar Cell Bus Voltage 2: "); Serial.print(busvoltage2); Serial.println(" V");
//Serial.println("");
delay(2000);
nexLoop(nex_listen_list);
}
#include <Wire.h>
#include "SDL_Arduino_INA3221.h"
#include "Nextion.h"
SDL_Arduino_INA3221 ina3221;
#define BATTERY_1 1
#define BATTERY_2 2
NexButton b0 = NexButton(0, 5, "b0");
NexNumber x0 = NexNumber(0, 8, "x0");
NexNumber x1 = NexNumber(0, 4, "x1");
char buffer[10] = {0};
NexTouch *nex_listen_list[] =
{
NULL
};
void setup(void)
{
nexInit() ;
ina3221.begin();
pinMode(2, INPUT_PULLUP); //REZYSTO 10KOCH MIEDZY WEJSCIEM A MASA
pinMode(13, OUTPUT);
}
int32_t busvoltage1;
int32_t busvoltage2;
void loop(void)
{
int sensorVal = digitalRead(2);
if (sensorVal == LOW) {
digitalWrite(13, LOW);
b0.Set_background_color_bco(63488);
} else {
digitalWrite(13, HIGH);
b0.Set_background_color_bco(2016);
}
float busvoltage1 = 0;
busvoltage1 = ina3221.getBusVoltage_V(BATTERY_1)*10;
x0.setValue(busvoltage1);
float busvoltage2 = 0;
busvoltage2 = ina3221.getBusVoltage_V(BATTERY_2)*10;
x1.setValue(busvoltage2);
delay(500);
nexLoop(nex_listen_list);
}
/**
* @file NexConfig.h
*
* Options for user can be found here.
*
* @author Wu Pengfei (email:<pengfei.wu@itead.cc>)
* @date 2015/8/13
* @copyright
* Copyright (C) 2014-2015 ITEAD Intelligent Systems Co., Ltd. \n
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*/
#ifndef __NEXCONFIG_H__
#define __NEXCONFIG_H__
/**
* @addtogroup Configuration
* @{
*/
/**
* Define DEBUG_SERIAL_ENABLE to enable debug serial.
* Comment it to disable debug serial.
*/
#define DEBUG_SERIAL_ENABLE
/**
* Define dbSerial for the output of debug messages.
*/
#define dbSerial Serial
/**
* Define nexSerial for communicate with Nextion touch panel.
*/
#define nexSerial Serial
#ifdef DEBUG_SERIAL_ENABLE
#define dbSerialPrint(a) dbSerial.print(a)
#define dbSerialPrintln(a) dbSerial.println(a)
#define dbSerialBegin(a) dbSerial.begin(a)
#else
#define dbSerialPrint(a) do{}while(0)
#define dbSerialPrintln(a) do{}while(0)
#define dbSerialBegin(a) do{}while(0)
#endif
/**
* @}
*/
#endif /* #ifndef __NEXCONFIG_H__ */
#include "Nextion.h"
const int ledPin = 5;
const int ledPin1 = 6;
const int ledPin2 = 7;
const int ledPin3 = 8;
NexDSButton bt0 = NexDSButton(0, 1, "bt0");
NexDSButton bt1 = NexDSButton(0, 9, "bt1");
NexDSButton bt2 = NexDSButton(0, 10, "bt2");
NexDSButton bt3 = NexDSButton(0, 11, "bt3");
char buffer[100] = {0};
NexTouch *nex_listen_list[] =
{
&bt0, &bt1, &bt2, &bt3,
NULL
};
void bt0PopCallback(void *ptr)
{
uint32_t dual_state;
NexDSButton *btn = (NexDSButton *)ptr;
dbSerialPrintln("b0PopCallback");
dbSerialPrint("ptr=");
dbSerialPrintln((uint32_t)ptr);
memset(buffer, 0, sizeof(buffer));
/* Get the state value of dual state button component . */
bt0.getValue(&dual_state);
if(dual_state)
{
digitalWrite(ledPin, HIGH);
}
else
{
digitalWrite(ledPin, LOW);
}
}
void bt1PopCallback(void *ptr)
{
uint32_t dual_state;
NexDSButton *btn = (NexDSButton *)ptr;
dbSerialPrintln("b1PopCallback");
dbSerialPrint("ptr=");
dbSerialPrintln((uint32_t)ptr);
memset(buffer, 0, sizeof(buffer));
/* Get the state value of dual state button component . */
bt1.getValue(&dual_state);
if(dual_state)
{
digitalWrite(ledPin1, HIGH);
}
else
{
digitalWrite(ledPin1, LOW);
}
}
void bt2PopCallback(void *ptr)
{
uint32_t dual_state;
NexDSButton *btn = (NexDSButton *)ptr;
dbSerialPrintln("b2PopCallback");
dbSerialPrint("ptr=");
dbSerialPrintln((uint32_t)ptr);
memset(buffer, 0, sizeof(buffer));
/* Get the state value of dual state button component . */
bt2.getValue(&dual_state);
if(dual_state)
{
digitalWrite(ledPin2, HIGH);
}
else
{
digitalWrite(ledPin2, LOW);
}
}
void bt3PopCallback(void *ptr)
{
uint32_t dual_state;
NexDSButton *btn = (NexDSButton *)ptr;
dbSerialPrintln("b3PopCallback");
dbSerialPrint("ptr=");
dbSerialPrintln((uint32_t)ptr);
memset(buffer, 0, sizeof(buffer));
/* Get the state value of dual state button component . */
bt3.getValue(&dual_state);
if(dual_state)
{
digitalWrite(ledPin3, HIGH);
}
else
{
digitalWrite(ledPin3, LOW);
}
}
void bt4PopCallback(void *ptr)
{
uint32_t dual_state;
NexDSButton *btn = (NexDSButton *)ptr;
dbSerialPrintln("b4PopCallback");
dbSerialPrint("ptr=");
dbSerialPrintln((uint32_t)ptr);
memset(buffer, 0, sizeof(buffer));
}
void setup(void)
{
Serial.begin(9600);
nexInit();
bt0.attachPop(bt0PopCallback, &bt0);
bt1.attachPop(bt1PopCallback, &bt1);
bt2.attachPop(bt2PopCallback, &bt2);
bt3.attachPop(bt3PopCallback, &bt3);
pinMode(ledPin, OUTPUT);
pinMode(ledPin1, OUTPUT);
pinMode(ledPin2, OUTPUT);
pinMode(ledPin3, OUTPUT);
}
void loop(void)
{
// Serial.print("t0.txt=\"Test\"");
// Serial.write(0xFF); Serial.write(0xFF); Serial.write(0xFF);
// delay(500);
// while (Serial.available()) {
// Serial.write(Serial.read()); // Odczytaj odpowiedź Nextion i wyślij do monitora portu szeregowego
// }
nexLoop(nex_listen_list);
}
/**
* @file NexConfig.h
*
* Options for user can be found here.
*
* @author Wu Pengfei (email:<pengfei.wu@itead.cc>)
* @date 2015/8/13
* @copyright
* Copyright (C) 2014-2015 ITEAD Intelligent Systems Co., Ltd. \n
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*/
#ifndef __NEXCONFIG_H__
#define __NEXCONFIG_H__
/**
* @addtogroup Configuration
* @{
*/
/**
* Define DEBUG_SERIAL_ENABLE to enable debug serial.
* Comment it to disable debug serial.
*/
#define DEBUG_SERIAL_ENABLE
/**
* Define dbSerial for the output of debug messages.
*/
#define dbSerial Serial
/**
* Define nexSerial for communicate with Nextion touch panel.
*/
#define nexSerial Serial
#ifdef DEBUG_SERIAL_ENABLE
#define dbSerialPrint(a) dbSerial.print(a)
#define dbSerialPrintln(a) dbSerial.println(a)
#define dbSerialBegin(a) dbSerial.begin(a)
#else
#define dbSerialPrint(a) do{}while(0)
#define dbSerialPrintln(a) do{}while(0)
#define dbSerialBegin(a) do{}while(0)
#endif
/**
* @}
*/
#endif /* #ifndef __NEXCONFIG_H__ */
* Comment it to disable debug serial.
*/
#define DEBUG_SERIAL_ENABLE
/**
* Define dbSerial for the output of debug messages.
*/
#define dbSerial Serial
/**
* Define nexSerial for communicate with Nextion touch panel.
*/
#define nexSerial Serial2