já meti as mãos À obra, agora que tenho o aquário a bom caminho começo a divergir as minhas cinergias...
lol
Bom este projecto, será uma melhoria a todos os niveis dos meus anterior programa, irei colocar com o arduino:
controlo dos leds.
Controlo do meu sistema de bailling. (que estou a fazer)
medição dos watts produzidos pelo painel solar (será 1 até ver de 240w pico)
Medição do meu UPS (da tensão e avaliação por base na quebra de tensão da duração da baterias)
Fica aqqui o programa, já corre os menus isto foi criado com um arduino duemilinove+lcd shield, mas depois meto no mega que aqui tenho...
deverei demorar menos de 1 mês, estou a conseguir fazer coisas que antes dava-me cabo da cabeça implementar e assim torna-se mais fácil.
código:
#include <LiquidCrystal.h>
#include <LCDKeypad.h>
LCDKeypad lcd;
int second=15,minute=40,hour=07,day=29,month=01,year=2 012;
unsigned long lastTick=0;
unsigned long overflow=0;
unsigned long clic=0;
int backlight=20;
int backtempo=0;
int estado=0;
int estadoled=0;
int power=0;
byte p1[8] = { 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10};
byte p2[8] = { 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18};
byte p3[8] = { 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C};
byte p4[8] = { 0x1E, 0x1E, 0x1E, 0x1E, 0x1E, 0x1E, 0x1E, 0x1E};
byte p5[8] = { 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F};
void setup()
{
lcd.begin(16, 2);
lcd.clear();
lcd.createChar(0, p1);
lcd.createChar(1, p2);
lcd.createChar(2, p3);
lcd.createChar(3, p4);
lcd.createChar(4, p5);
pinMode(10, OUTPUT);
digitalWrite(10, HIGH);
}
void loop(){
crono();
tensao();
menu();
menuled();
ledpower();
}
void menu()
{
if (lcd.button()!=KEYPAD_NONE)
{
lcd.setCursor(6,1);
backlight=10;
digitalWrite(10, HIGH);
if (lcd.button()==KEYPAD_SELECT)
{
lcd.setCursor(6,1);
if (estado==0){
estado=1;
lcd.print("Leds ");}
else if (estado==1){
estado=0 ;
lcd.print("bailling ");
}
waitReleaseButton();
}
}
}
int tensao(){
lcd.setCursor(0,1);
float volts;
int volt;
volt = analogRead(2);
volts=volt/75.8;
if (volts<10.0){
lcd.print("0");
}
lcd.print(volts,1); //prints the int par
lcd.print("v ");
}
void ledpower()
{
int I;
if (estado==1 )
{
if (lcd.button()==KEYPAD_UP)
{
power=power+1;
backtempo=3;
if (power==17) {
power=16;}
lcd.setCursor(0,0);
lcd.print(" ");
lcd.setCursor(0,0);
for (I=0;I<power;I=I+1)
{
lcd.write(4);}
waitReleaseButton();
}
if (lcd.button()==KEYPAD_DOWN)
{
power=power-1;
backtempo=3;
if (power==0) {
power=1;}
lcd.setCursor(0,0);
lcd.print(" ");
lcd.setCursor(0,0);
for (I=0;I<power;I=I+1)
{
lcd.write(4);}
waitReleaseButton();
} }
}
int crono(){
clic=millis();
if (overflow > clic ){
overflow=clic;
lastTick=overflow;
}
if (clic - lastTick > 1000.0) {
lastTick = lastTick+1000; //duração do segundo
second++;
if (backtempo>0){
--backtempo;
}
if (backlight>0){
--backlight;
}
else
{
digitalWrite(10, LOW);
}
// move forward one minute every 60 seconds
if (second >59) {
minute++;
second = 0;
}
if (minute > 59) {
hour++;
minute = 0; // reset minutes to zero
}
if (hour>23){
hour=0;
day++;
}
if (day>30&(month==4 or month==6 or month==9 or month ==11)){
day = 1;
month++;
}
if (day>31&(month==1 or month==3 or month==5 or month==7 or month==8 or month==10 or month ==12)){
day = 1;
month++;
}
if (day>28 & month==2){
day=1;
month++;
}
if (month>12){
year++;
month=1;
}
if (backtempo==0){
tempo();
}}}
void tempo(){
if (hour <10){
lcd.setCursor(0,0);
lcd.print("0");
lcd.print(hour); //prints the int par
lcd.print(":");
}
else if (hour>9){
lcd.setCursor(0,0);
lcd.print(hour); //prints the int par
lcd.print(":");}
if (minute <10){
lcd.setCursor(3,0);
lcd.print("0");
lcd.print(minute); //prints the int par
lcd.print(":");
}
else if (minute>9){
lcd.setCursor(3,0);
lcd.print(minute); //prints the int par
lcd.print(":");}
if (second <10){
lcd.setCursor(6,0);
lcd.print("0");
lcd.print(second); //prints the int par
}
else if (second>9){
lcd.setCursor(6,0);
lcd.print(second); //prints the int par
lcd.print(" ");
}}
void waitReleaseButton()
{
delay(50);
while(lcd.button()!=KEYPAD_NONE)
{
}
delay(50);
}
void menuled()
{
if ((lcd.button()!=KEYPAD_LEFT ||lcd.button()!=KEYPAD_RIGHT)& estado==1 )
{
if (lcd.button()==KEYPAD_RIGHT)
{
lcd.setCursor(11,1);
if (estadoled==0){
estadoled=1;
lcd.print("Blue ");}
else if (estadoled==1){
estadoled=2;
lcd.print("white");}
else if (estadoled==2){
estadoled=3;
lcd.print("mixed");}
else if (estadoled==3){
estadoled=0;
lcd.print("ciclo");}
waitReleaseButton();
}
if (lcd.button()==KEYPAD_LEFT)
{
lcd.setCursor(11,1);
if (estadoled==0){
estadoled=3;
lcd.print("ciclo");}
else if (estadoled==1){
estadoled=0;
lcd.print("mixed");}
else if (estadoled==2){
estadoled=1;
lcd.print("blue ");}
else if (estadoled==3){
estadoled=2;
lcd.print("white");}
waitReleaseButton();
}}}