LusoRobótica - Robótica em Português

Robótica => Iniciantes => Tópico iniciado por: barrma em 16 de Janeiro de 2015, 16:43

Título: Iniciante - juntar codigos
Enviado por: barrma em 16 de Janeiro de 2015, 16:43
Boa tarde a todos,

Estou a tentar desenvolver um pequeno projecto, que tem como objectivo, controlar temperaturas de um aquário. Controlar equipamentos através de reles e botões em um tft touch.

Para muitos  isto não é difícil,  mas na verdade eu não estou a conseguir adaptar os códigos que encontrei, já testei o RTC, TFT, e o sensor de temperatura. Todos funcionam e estão actualmente ligados no arduino mega.  Ainda não tenho os reles, mas isso não me preocupa agora. 


A duvida que tenho é como vou adaptar os códigos, tenho o código do layout ou da "primeira página", onde vou colocar a data, hora e temperatura. 

O problema é que não estou a conseguir juntar estes códigos. Deixo aqui um exemplo do que pretendo fazer e os códigos que tenho. Quem me poder ajudar a juntar os códigos agradecia.

Obrigado


Código: [Seleccione]
Código do layout:


#include <UTFT.h>


extern uint8_t SmallFont[];

UTFT myGLCD(ITDB32S,38,39,40,41);   
void setup()
{
  randomSeed(analogRead(0));
 

  myGLCD.InitLCD();
  myGLCD.setFont(SmallFont);
}

void loop()
{
  int buf[318];
  int x, x2;
  int y, y2;
  int r;


  myGLCD.clrScr();

  myGLCD.setColor(255, 0, 0);
  myGLCD.fillRect(0, 0, 319, 13);
  myGLCD.setColor(64, 64, 64);
  myGLCD.setBackColor(255, 0, 0);
  myGLCD.print(" Data     Relogio    Temperatura", CENTER, 1);
 

  delay (10000);
}


Sensor da temperatura:

 
#include <OneWire.h>

const int sensors = 1; //number of temperature sensors on the bus
int sensors_pin = 10; //the pin where the bus its connected to arduino
uint8_t sensors_address[sensors][8]; //here will store the sensors addresses for later use

OneWire  sensor_bus(sensors_pin);

float get_temperature (uint8_t *address);

void setup(void) {
  Serial.begin(9600);
  int x,y,c=0;
  Serial.println("Starting to look for sensors...");
  for(x=0;x<sensors;x++){
    if(sensor_bus.search(sensors_address[x]))
      c++;
  }
  if(c > 0) {
    Serial.println("Found this sensors : ");
    for(x=0;x<sensors;x++) {
      Serial.print("\tSensor ");
      Serial.print(x+1);
      Serial.print(" at address : ");
      for(y=0;y<8;y++){
        Serial.print(sensors_address[x][y],HEX);
        Serial.print(" ");
      }
      Serial.println();
    }
  } else
    Serial.println("Didn't find any sensors");
}

void loop(void) {
   
    for(int x=0;x<sensors;x++) {
      Serial.print("Sensor ");
      Serial.print(x+1);
      Serial.print(" ");
      Serial.print(get_temperature(sensors_address[x]));
      Serial.println(" C");
    }
    delay(2000);
}

float get_temperature(uint8_t *address) {
  byte data[12];
  int x;
  sensor_bus.reset();
  sensor_bus.select(address);
  sensor_bus.write(0x44,1);
 
  sensor_bus.reset();
  sensor_bus.select(address);
  sensor_bus.write(0xBE,1);
 
  for(x=0;x<9;x++){
    data[x] = sensor_bus.read();
  }
   
  unsigned short tr = data[0];
  tr = tr + data[1]*256;
 
    //For testing purpuses only
  /*
  for(x=0;x<9;x++){
    Serial.print(data[x],DEC );
    Serial.print(" ");
  }
 
  Serial.print(" tr=");
  Serial.print(tr, DEC);
  Serial.print("; ");
  */
 
  if(tr > 0xF000){
    tr = 0 - tr;
  }
 
 
  float temperature = (float)tr*(float)0.0625 ;

  return temperature;
}


Relógio:
#include "Wire.h"
#define DS3231_I2C_ADDRESS 0x68
// Convert normal decimal numbers to binary coded decimal
byte decToBcd(byte val)
{
  return( (val/10*16) + (val%10) );
}
// Convert binary coded decimal to normal decimal numbers
byte bcdToDec(byte val)
{
  return( (val/16*10) + (val%16) );
}
void setup()
{
  Wire.begin();
  Serial.begin(9600);
  setDS3231time(30,47,18,5,15,01,15);
  // set the initial time here:
  // DS3231 seconds, minutes, hours, day, date, month, year
  // setDS3231time(30,40,18,5,26,11,14);
}
void setDS3231time(byte second, byte minute, byte hour, byte dayOfWeek, byte
dayOfMonth, byte month, byte year)
{
  // sets time and date data to DS3231
  Wire.beginTransmission(DS3231_I2C_ADDRESS);
  Wire.write(0); // set next input to start at the seconds register
  Wire.write(decToBcd(second)); // set seconds
  Wire.write(decToBcd(minute)); // set minutes
  Wire.write(decToBcd(hour)); // set hours
  Wire.write(decToBcd(dayOfWeek)); // set day of week (1=Sunday, 7=Saturday)
  Wire.write(decToBcd(dayOfMonth)); // set date (1 to 31)
  Wire.write(decToBcd(month)); // set month
  Wire.write(decToBcd(year)); // set year (0 to 99)
  Wire.endTransmission();
}
void readDS3231time(byte *second,
byte *minute,
byte *hour,
byte *dayOfWeek,
byte *dayOfMonth,
byte *month,
byte *year)
{
  Wire.beginTransmission(DS3231_I2C_ADDRESS);
  Wire.write(0); // set DS3231 register pointer to 00h
  Wire.endTransmission();
  Wire.requestFrom(DS3231_I2C_ADDRESS, 7);
  // request seven bytes of data from DS3231 starting from register 00h
  *second = bcdToDec(Wire.read() & 0x7f);
  *minute = bcdToDec(Wire.read());
  *hour = bcdToDec(Wire.read() & 0x3f);
  *dayOfWeek = bcdToDec(Wire.read());
  *dayOfMonth = bcdToDec(Wire.read());
  *month = bcdToDec(Wire.read());
  *year = bcdToDec(Wire.read());
}
void displayTime()
{
  byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;
  // retrieve data from DS3231
  readDS3231time(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month,
  &year);
  // send it to the serial monitor
  Serial.print(hour, DEC);
  // convert the byte variable to a decimal number when displayed
  Serial.print(":");
  if (minute<10)
  {
    Serial.print("0");
  }
  Serial.print(minute, DEC);
  Serial.print(":");
  if (second<10)
  {
    Serial.print("0");
  }
  Serial.print(second, DEC);
  Serial.print(" ");
  Serial.print(dayOfMonth, DEC);
  Serial.print("/");
  Serial.print(month, DEC);
  Serial.print("/");
  Serial.print(year, DEC);
  Serial.print(" Dia da Semana: ");
  switch(dayOfWeek){
  case 1:
    Serial.println("Dom");
    break;
  case 2:
    Serial.println("Seg");
    break;
  case 3:
    Serial.println("Ter");
    break;
  case 4:
    Serial.println("Qua");
    break;
  case 5:
    Serial.println("Qui");
    break;
  case 6:
    Serial.println("Sex");
    break;
  case 7:
    Serial.println("Sab");
    break;
  }
}
void loop()
{
  displayTime(); // display the real-time clock data on the Serial Monitor,
  delay(1000); // every second
}





Título: Re: Iniciante - juntar codigos
Enviado por: Njay em 16 de Janeiro de 2015, 17:17
Tens literalmente que fundir tudo. Juntar todas as declarações no mesmo programa, fundir o conteúdo dos setup() e o dos loop() num só, acrescentar todas as restantes funções dos vários programas no mesmo. Ficarão adaptações para fazer dentro da loop. Mas para esta tarefa precisas de saber programar; este projecto é bastante avançado para alguém no teu nível de conhecimento, devias começar por coisas mais simples.
Título: Re: Iniciante - juntar codigos
Enviado por: Njay em 16 de Janeiro de 2015, 17:57
Se tiveres alguma pergunta mais especifica.... força!
Título: Re: Iniciante - juntar codigos
Enviado por: Njay em 16 de Janeiro de 2015, 18:11
Tens que procurar que funções é que a biblioteca do LCD tem para imprimir texto ou números no LCD. Parece que existe a print, terás que ver que outras existem, nomeadamente para imprimir números. Se não tiver funções para imprimir números, então tens que converter os teus números para texto (string) e depois já podes usar as funções de texto. Depois é mais ou menos traduzir o que tens para a porta série (os Serial.print....) para chamadas às funções do LCD.
Título: Re: Iniciante - juntar codigos
Enviado por: MRData em 16 de Janeiro de 2015, 18:58
Boas,

Se bem entendi, o que queres é que a data hora que é escrita no serial que vem da função displayTime() passe para o display certo?

Se for isso é relativamente simples, o que tens de fazer, é:

Alterar o tipo de void para string da função displayTime()
Seguidamente, crias uma variavel dentro da funcao para ir "colando" os dados. (no codigo chamei de buf)
Alterei a função abaixo com a variavel buf incluida para construir a "frase" para enviar para o ecra. (acho que esta tudo, mas pode faltar alguma coisa que me tenha escapado visto que aqui não consigo testar).
E no fim devolves essa string como resultado.

Se substituires a função que coloquei abaixo, pela do teu codigo (e eventualmente corrigir algum erro que possa ter deixado)

basta chamares no LOOP a seguinte linha :

 myGLCD.print(displayTime(), CENTER, 1) ;

Isto deve resolver o teu problema.

P.S. - Deixei o texto que inclui na função "desindentado" para veres o que adicionei.

Código: [Seleccione]

String displayTime()
{
  byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;
String buf = "";
  // retrieve data from DS3231
  readDS3231time(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month,
  &year);
  // send it to the serial monitor
  Serial.print(hour, DEC);
buf += hour;
  // convert the byte variable to a decimal number when displayed
  Serial.print(":");
buf += ":";
  if (minute<10)
  {
    Serial.print("0");
buf += "0";
  }
  Serial.print(minute, DEC);
buf += minute;
  Serial.print(":");
buf += ":";
  if (second<10)
  {
    Serial.print("0");
buf += "0";
  }
  Serial.print(second, DEC);
buf += second;
  Serial.print(" ");
buf += " ";
  Serial.print(dayOfMonth, DEC);
buf += dayOfMonth;
  Serial.print("/");
buf += "/";
  Serial.print(month, DEC);
buf += month;
  Serial.print("/");
buf += "/";
  Serial.print(year, DEC);
buf += year;
  Serial.print(" Dia da Semana: ");
buf += " Dia da Semana: ";
  switch(dayOfWeek){
  case 1:
    Serial.println("Dom");
buf += "Dom";
    break;
  case 2:
    Serial.println("Seg");
buf += "Seg";
    break;
  case 3:
    Serial.println("Ter");
buf += "Ter";
    break;
  case 4:
    Serial.println("Qua");
buf += "Qua";
    break;
  case 5:
    Serial.println("Qui");
buf += "Qui";
    break;
  case 6:
    Serial.println("Sex");
buf += "Sex";
    break;
  case 7:
    Serial.println("Sab");
buf += "Sab";
    break;
  }
return buf;
}
Título: Re: Iniciante - juntar codigos
Enviado por: MRData em 16 de Janeiro de 2015, 19:48
Falta-te a linha que adicionei aqui no teu codigo a seguir

      Serial.print(get_temperature(sensors_address));
buf += get_temperature(sensors_address);

E tambem tens de colocar a linha return buf; na ultima linha da função.
No pode ficar a meio, essa tem de ser a ultima linha de codigo daquela função sempre.
Título: Re: Iniciante - juntar codigos
Enviado por: MRData em 16 de Janeiro de 2015, 20:38
Troca a função por esta.

String displayTime()
{
  byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;
String buf = "";
  // retrieve data from DS3231
  readDS3231time(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month,
  &year);
  // send it to the serial monitor
  Serial.print(hour, DEC);
buf += hour;
  // convert the byte variable to a decimal number when displayed
  Serial.print(":");
buf += ":";
  if (minute<10)
  {
    Serial.print("0");
buf += "0";
  }
  Serial.print(minute, DEC);
buf += minute;
  Serial.print(":");
buf += ":";
  if (second<10)
  {
    Serial.print("0");
buf += "0";
    buf += "0";
  }
  Serial.print(second, DEC);
buf += second;
  Serial.print(" ");
buf += " ";
  Serial.print(dayOfMonth, DEC);
buf += dayOfMonth;
  Serial.print("/");
buf += "/";
  Serial.print(month, DEC);
buf += month;
  Serial.print("/");
buf += "/";
  Serial.print(year, DEC);
buf += year;
  Serial.print(" ");
buf += " ";
  switch(dayOfWeek){
  case 1:
    Serial.println("Domingo");
buf += "Domingo";
    break;
  case 2:
    Serial.println("Segunda");
buf += "Segunda";
    break;
  case 3:
    Serial.println("Terça");
buf += "Terça";
    break;
  case 4:
    Serial.println("Quarta");
buf += "Quarta";
    break;
  case 5:
    Serial.println("Quinta");
buf += "Quinta";
    break;
  case 6:
    Serial.println("Sexta");
buf += "Sexta";
    break;
  case 7:
    Serial.println("Sabado");
buf += "Sabado";
    break;
  }

buf += "\r\n";

for(int x=0;x<sensors;x++) {
      Serial.println("Sensor ");
buf += "Sensor ";
      break;
     
      Serial.print(x+1);
buf += x+1;
      Serial.print(" ");
buf += " ";
      Serial.print(get_temperature(sensors_address));
buf += get_temperature(sensors_address);

      Serial.println(" C");
buf += " C\r\n";
    }
    delay(2000);
return buf;
}
Título: Re: Iniciante - juntar codigos
Enviado por: StarRider em 16 de Janeiro de 2015, 21:02

Numa linguagem normal (expecto C#) essa função nunca vai funcionar, pelo simples facto
de que a variável "buf" declarada dentro da função "displayTime" sai fora de scope assim que
a função retorna, o que faz com que o seu destructor seja chamado e o espaço de memória que
a mesma ocupava no stack seja reclamado.
Logo, essa função "displayTime" retorna um ponteiro (em C uma referencia a um membro de
a classe é um ponteiro para esse mesmo membro) para uma zona de memória onde ESTAVA
esse tal "buf". Por vezes pode parecer funcionar pois possivelmente o stack onde estava o
membro da classe String pode ainda não ter sido reutilizado e o seu conteúdo ainda reflecte o
conteúdo da "buf", mas basta existir uma outra chamada a uma qualquer função entretanto e pufff.

O "arduino" faz uma implementação do C++ "estranha", não tem o operador "new" nem "delete" e
como não tem um garbage collector sofisticado como o C# , assumo que o compilador por detrás
(avr-gcc) tem o comportamento que descrevi ...

Abraços,
PA
Título: Re: Iniciante - juntar codigos
Enviado por: MRData em 16 de Janeiro de 2015, 21:15

Numa linguagem normal (expecto C#) essa função nunca vai funcionar, pelo simples facto
de que a variável "buf" declarada dentro da função "displayTime" sai fora de scope assim que
a função retorna, o que faz com que o seu destructor seja chamado e o espaço de memória que
a mesma ocupava no stack seja reclamado.
Logo, essa função "displayTime" retorna um ponteiro (em C uma referencia a um membro de
a classe é um ponteiro para esse mesmo membro) para uma zona de memória onde ESTAVA
esse tal "buf". Por vezes pode parecer funcionar pois possivelmente o stack onde estava o
membro da classe String pode ainda não ter sido reutilizado e o seu conteúdo ainda reflecte o
conteúdo da "buf", mas basta existir uma outra chamada a uma qualquer função entretanto e pufff.

O "arduino" faz uma implementação do C++ "estranha", não tem o operador "new" nem "delete" e
como não tem um garbage collector sofisticado como o C# , assumo que o compilador por detrás
(avr-gcc) tem o comportamento que descrevi ...

Abraços,
PA

StarRider,

Até te podia dar alguma razão simplesmente pela forma como eu lhe disse para chamar a função, mas....
Primeiro o metodo devolve uma string (não é do tipo void), logo passa para a "main" o pointer para o buf.
Segundo e se realmente isso fosse um issue, bastava ele fazer " String newbuf = displayTime(); " e "copiava" a referencia do pointer para a nova variavel, depois fazendo o print, caso alguma vez falhasse...
Terceiro, como passa a função como ref para o pointer, para uma outra função que vai escrever o conteudo num display, mesmo que perca o conteudo da var, ela já vai estar escrita e não é usada para nada.

Que era o que ele queria.

Seja como for, ele disse que testou e funcionou, depois quis adicionar a temperatura e deixou de funcionar porque ele colocou as coisas de forma errada.
Título: Re: Iniciante - juntar codigos
Enviado por: MRData em 16 de Janeiro de 2015, 21:15
MRData, Agora dá erro na compilação  :( o melhor é ir jantar e voltar com mais paciência :D obrigado a todos pela ajuda!
Código: [Seleccione]
#include "Wire.h"
#include <UTFT.h>
#include <OneWire.h>


extern uint8_t SmallFont[];

#define DS3231_I2C_ADDRESS 0x68
// Convert normal decimal numbers to binary coded decimal
const int sensors = 1; //number of temperature sensors on the bus
int sensors_pin = 10; //the pin where the bus its connected to arduino
uint8_t sensors_address[sensors][8]; //here will store the sensors addresses for later use

OneWire  sensor_bus(sensors_pin);

float get_temperature (uint8_t *address);


UTFT myGLCD(ITDB32S,38,39,40,41);

byte decToBcd(byte val)
{
  return( (val/10*16) + (val%10) );
}
// Convert binary coded decimal to normal decimal numbers
byte bcdToDec(byte val)
{
  return( (val/16*10) + (val%16) );
}
void setup()
{
  Wire.begin();
  Serial.begin(9600);
  setDS3231time(30,21,19,6,6,01,15);
  // set the initial time here:
  // DS3231 seconds, minutes, hours, day, date, month, year
  // setDS3231time(30,40,18,5,26,11,14);
  randomSeed(analogRead(0));


  myGLCD.InitLCD();
  myGLCD.setFont(SmallFont);

  int x,y,c=0;
  Serial.println("Starting to look for sensors...");
  for(x=0;x<sensors;x++){
    if(sensor_bus.search(sensors_address[x]))
      c++;
  }
  if(c > 0) {
    Serial.println("Found this sensors : ");
    for(x=0;x<sensors;x++) {
      Serial.print("\tSensor ");
      Serial.print(x+1);
      Serial.print(" at address : ");
      for(y=0;y<8;y++){
        Serial.print(sensors_address[x][y],HEX);
        Serial.print(" ");
      }
      Serial.println();
    }
  }
  else
    Serial.println("Didn't find any sensors");
}
void setDS3231time(byte second, byte minute, byte hour, byte dayOfWeek, byte
dayOfMonth, byte month, byte year)
{
  // sets time and date data to DS3231
  Wire.beginTransmission(DS3231_I2C_ADDRESS);
  Wire.write(0); // set next input to start at the seconds register
  Wire.write(decToBcd(second)); // set seconds
  Wire.write(decToBcd(minute)); // set minutes
  Wire.write(decToBcd(hour)); // set hours
  Wire.write(decToBcd(dayOfWeek)); // set day of week (1=Sunday, 7=Saturday)
  Wire.write(decToBcd(dayOfMonth)); // set date (1 to 31)
  Wire.write(decToBcd(month)); // set month
  Wire.write(decToBcd(year)); // set year (0 to 99)
  Wire.endTransmission();
}
void readDS3231time(byte *second,
byte *minute,
byte *hour,
byte *dayOfWeek,
byte *dayOfMonth,
byte *month,
byte *year)
{
  Wire.beginTransmission(DS3231_I2C_ADDRESS);
  Wire.write(0); // set DS3231 register pointer to 00h
  Wire.endTransmission();
  Wire.requestFrom(DS3231_I2C_ADDRESS, 7);
  // request seven bytes of data from DS3231 starting from register 00h
  *second = bcdToDec(Wire.read() & 0x7f);
  *minute = bcdToDec(Wire.read());
  *hour = bcdToDec(Wire.read() & 0x3f);
  *dayOfWeek = bcdToDec(Wire.read());
  *dayOfMonth = bcdToDec(Wire.read());
  *month = bcdToDec(Wire.read());
  *year = bcdToDec(Wire.read());
}

String displayTime()
{
  byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;
  String buf = "";
  // retrieve data from DS3231
  readDS3231time(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month,
  &year);
  // send it to the serial monitor
  Serial.print(hour, DEC);
  buf += hour;
  // convert the byte variable to a decimal number when displayed
  Serial.print(":");
  buf += ":";
  if (minute<10)
  {
    Serial.print("0");
    buf += "0";
  }
  Serial.print(minute, DEC);
  buf += minute;
  Serial.print(":");
  buf += ":";
  if (second<10)
  {
    Serial.print("0");
    buf += "0";
    buf += "0";
  }
  Serial.print(second, DEC);
  buf += second;
  Serial.print(" ");
  buf += " ";
  Serial.print(dayOfMonth, DEC);
  buf += dayOfMonth;
  Serial.print("/");
  buf += "/";
  Serial.print(month, DEC);
  buf += month;
  Serial.print("/");
  buf += "/";
  Serial.print(year, DEC);
  buf += year;
  Serial.print(" ");
  buf += " ";
  switch(dayOfWeek){
  case 1:
    Serial.println("Domingo");
    buf += "Domingo";
    break;
  case 2:
    Serial.println("Segunda");
    buf += "Segunda";
    break;
  case 3:
    Serial.println("Terça");
    buf += "Terça";
    break;
  case 4:
    Serial.println("Quarta");
    buf += "Quarta";
    break;
  case 5:
    Serial.println("Quinta");
    buf += "Quinta";
    break;
  case 6:
    Serial.println("Sexta");
    buf += "Sexta";
    break;
  case 7:
    Serial.println("Sabado");
    buf += "Sabado";
    break;
  }

  for(int x=0;x<sensors;x++) {
    Serial.println("Sensor ");
    buf += "Sensor";
    break;

    Serial.print(x+1);
    buf += x+1;
    Serial.print(" ");
    buf += " ";
    Serial.print(get_temperature(sensors_address));
    buf += get_temperature(sensors_address);

    Serial.println(" C");
    buf += " C";
  }
  delay(2000);
  return buf;
}

float get_temperature(uint8_t *address) {
  byte data[12];
  int x;
  sensor_bus.reset();
  sensor_bus.select(address);
  sensor_bus.write(0x44,1);

  sensor_bus.reset();
  sensor_bus.select(address);
  sensor_bus.write(0xBE,1);
  for(x=0;x<9;x++){
    data[x] = sensor_bus.read();
  }


  unsigned short tr = data[0];
  tr = tr + data[1]*256;

  if(tr > 0xF000){
    tr = 0 - tr;
  }


  float temperature = (float)tr*(float)0.0625 ;

  return temperature;
}



void loop()
{
  displayTime(); // display the real-time clock data on the Serial Monitor,
  delay(1000); // every second

  int buf[318];
  int x, x2;
  int y, y2;
  int r;


  myGLCD.clrScr();

  myGLCD.setColor(255, 0, 0);
  myGLCD.fillRect(0, 0, 319, 13);
  myGLCD.setColor(64, 64, 64);
  myGLCD.setBackColor(255, 0, 0);
  myGLCD.print(displayTime(), LEFT, 1) ;



  delay (10000);

}



Coloca o erro pff.
Título: Re: Iniciante - juntar codigos
Enviado por: MRData em 16 de Janeiro de 2015, 21:29
Substitui a tua por esta.
Suponho que tenhas mais que um sensor de temperatura?
O erro que estavas a ter parece estar relacionado com o "for" que colocaste dentro dessa função para construir a "frase" com a temperatura, pois não referenciavas qual o indice do array do sensor, e estas a passar o array completo para cada count.

Isto deve resolver, se tiveres problemas diz.

Código: [Seleccione]
String displayTime()
{
  byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;
  String buf = "";
  // retrieve data from DS3231
  readDS3231time(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month,
  &year);
  // send it to the serial monitor
  Serial.print(hour, DEC);
  buf += hour;
  // convert the byte variable to a decimal number when displayed
  Serial.print(":");
  buf += ":";
  if (minute<10)
  {
    Serial.print("0");
    buf += "0";
  }
  Serial.print(minute, DEC);
  buf += minute;
  Serial.print(":");
  buf += ":";
  if (second<10)
  {
    Serial.print("0");
    buf += "0";
    buf += "0";
  }
  Serial.print(second, DEC);
  buf += second;
  Serial.print(" ");
  buf += " ";
  Serial.print(dayOfMonth, DEC);
  buf += dayOfMonth;
  Serial.print("/");
  buf += "/";
  Serial.print(month, DEC);
  buf += month;
  Serial.print("/");
  buf += "/";
  Serial.print(year, DEC);
  buf += year;
  Serial.print(" ");
  buf += " ";
  switch(dayOfWeek){
  case 1:
    Serial.println("Domingo");
    buf += "Domingo";
    break;
  case 2:
    Serial.println("Segunda");
    buf += "Segunda";
    break;
  case 3:
    Serial.println("Terça");
    buf += "Terça";
    break;
  case 4:
    Serial.println("Quarta");
    buf += "Quarta";
    break;
  case 5:
    Serial.println("Quinta");
    buf += "Quinta";
    break;
  case 6:
    Serial.println("Sexta");
    buf += "Sexta";
    break;
  case 7:
    Serial.println("Sabado");
    buf += "Sabado";
    break;
  }

  buf += "\r\n";

  for(int x=0;x<sensors;x++) {
    Serial.println("Sensor ");
    buf += "Sensor ";
    break;

    Serial.print(x+1);
    buf += x+1;
    Serial.print(" ");
    buf += " ";
    Serial.print(get_temperature(sensors_address[x]));
    buf += get_temperature(sensors_address[x]);

    Serial.println(" C");
    buf += " C\r\n";
  }
  delay(2000);
  return buf;
}
Título: Re: Iniciante - juntar codigos
Enviado por: MRData em 16 de Janeiro de 2015, 21:55
Colocaste um break a seguir a palavra sensor... ele ai sai do for ...
Testa com esta.

Código: [Seleccione]
String displayTime()
{
  byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;
  String buf = "";
  // retrieve data from DS3231
  readDS3231time(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month,
  &year);
  // send it to the serial monitor
  Serial.print(hour, DEC);
  buf += hour;
  // convert the byte variable to a decimal number when displayed
  Serial.print(":");
  buf += ":";
  if (minute<10)
  {
    Serial.print("0");
    buf += "0";
  }
  Serial.print(minute, DEC);
  buf += minute;
  Serial.print(":");
  buf += ":";
  if (second<10)
  {
    Serial.print("0");
    buf += "0";
    buf += "0";
  }
  Serial.print(second, DEC);
  buf += second;
  Serial.print(" ");
  buf += " ";
  Serial.print(dayOfMonth, DEC);
  buf += dayOfMonth;
  Serial.print("/");
  buf += "/";
  Serial.print(month, DEC);
  buf += month;
  Serial.print("/");
  buf += "/";
  Serial.print(year, DEC);
  buf += year;
  Serial.print(" ");
  buf += " ";
  switch(dayOfWeek){
  case 1:
    Serial.println("Domingo");
    buf += "Domingo";
    break;
  case 2:
    Serial.println("Segunda");
    buf += "Segunda";
    break;
  case 3:
    Serial.println("Terça");
    buf += "Terça";
    break;
  case 4:
    Serial.println("Quarta");
    buf += "Quarta";
    break;
  case 5:
    Serial.println("Quinta");
    buf += "Quinta";
    break;
  case 6:
    Serial.println("Sexta");
    buf += "Sexta";
    break;
  case 7:
    Serial.println("Sabado");
    buf += "Sabado";
    break;
  }

  for(int x=0;x<sensors;x++) {
    Serial.println("Sensor ");
    buf += " Sensor ";

    Serial.print(x+1);
    buf += x+1;
    Serial.print(" ");
    buf += " ";
    Serial.print(get_temperature(sensors_address[x]));
    buf += get_temperature(sensors_address[x]);

    Serial.println(" C");
    buf += " C";
  }
  delay(2000);
  return buf;
}
Título: Re: Iniciante - juntar codigos
Enviado por: MRData em 16 de Janeiro de 2015, 21:59
Os caracteres esquisitos antes, é porque eu estava a dar o equivalente a um "ENTER" para iniciar numa nova linha, mas já vi que essa funcao que escreve para o display ignora isso.
Se quiseres colocar uma linha nova para o resultado de cada sensor tens de fazer algumas alterações a essa função.
Título: Re: Iniciante - juntar codigos
Enviado por: StarRider em 16 de Janeiro de 2015, 22:06
StarRider,

Até te podia dar alguma razão simplesmente pela forma como eu lhe disse para chamar a função, mas....
Primeiro o metodo devolve uma string (não é do tipo void), logo passa para a "main" o pointer para o buf.

Não, o problema é mesmo esse, nos tipos compostos o C devolve um ponteiro, neste caso um
ponteiro para "nada" pois a tal string já não existe.

Segundo e se realmente isso fosse um issue, bastava ele fazer " String newbuf = displayTime(); " e "copiava" a referencia do pointer para a nova variavel, depois fazendo o print, caso alguma vez falhasse...
Não, uma referencia para um ponteiro é um duplo ponteiro (definido como ** em C), existe ai alguma
confusão, o que acontecia era que a novo membro do classe string recebia o conteúdo de deferência
do suposto ponteiro, mais uma vez podia funcionar somente por pura SORTE.


Terceiro, como passa a função como ref para o pointer, para uma outra função que vai escrever o conteudo num display, mesmo que perca o conteudo da var, ela já vai estar escrita e não é usada para nada.

Esta não percebi, uma função como referencia ? ? ?
Em C uma chamada do tipo "FuncXpto(FuncXXX(), qualquercoisa)" implica que a o compilador execute
os seguintes passos:
-pop stack
-chamar FuncXXX()
-push stack (returno de FuncXXX() num registo, possivelmente R1)
-chamar FuncXpto(R1, qualquercoisa)

Não existe qualquer passagem de "função como referencia" ... por isso não estou a perceber essa
afirmação ... mas em frente.

O que se passa é que esse erro é comum, e como por vezes as coisas até funcionam só com mais
experiência é que se dá por ele, mas quando dá para o torto é que são elas.
De qualquer forma é uma má pratica de programação que devemos alertar para que as pessoas
possam evoluir.

Existem formas mais simples e compactas de resolver a questão, e por vezes usar classes para
tarefas simples (ainda por cima num MCU limitado) nem sempre é a melhor opção, mas como é óbvio
cada cabeça sua sentença, e esta é somente a minha opinião.

Se fosse eu, optava por algo no género, e resolvia a questão com 3 linhas de código:

Código: [Seleccione]
char *daynames[] = {"Domingo", "Segunda", "Terça", "Quarta", "Quinta", "Sexta", "Sabado"};

void displayTime(char *destbuf)
{
   readDS3231time(&sec, &min, &hour, &dow, &dom, &mon, &year);
   sprintf(destbuf,"%02d:%02d:%02d  %02d/%02d/%04d %s\r\n",hour,min,sec,dom,mon,year,dayname[dow]); 
   Serial.println(destbuf);
}


Abraços,
PA
Título: Re: Iniciante - juntar codigos
Enviado por: MRData em 16 de Janeiro de 2015, 22:06
Diz 1 19C porque tu fizeste um Serial.Print(x+1); e eu assumi que querias isso no texto, para destinguires que sensor é que te esta a dar essa leitura.
Se quiseres eliminar, basta apagares a linha : buf += x+1;

Já esta melhor :D mas continua a dizer "Sensor 1 19C" em vez de 19C
Título: Re: Iniciante - juntar codigos
Enviado por: StarRider em 16 de Janeiro de 2015, 22:19
Já consegui. mas tive de remover da função a palavra" sensor"

Código: [Seleccione]
f for(int x=0;x<sensors;x++) {
    Serial.println(" ");
    buf += " ";

   
    Serial.print(" ");
    buf += " ";
    Serial.print(get_temperature(sensors_address[x]));
    buf += get_temperature(sensors_address[x]);

    Serial.println(" C");
    buf += " C";

E aprendeste alguma coisa ? Percebes porque é que não funcionada com a palavra "sensor" ?
Título: Re: Iniciante - juntar codigos
Enviado por: MRData em 16 de Janeiro de 2015, 22:25
Tiveste que apagar a palavra sensor porque esgotavas as letras da primeira linha, porque estas a escrever tudo linear...
Convem fazeres alterações ao teu codigo para poderes escrever em varias linhas.

Já consegui. mas tive de remover da função a palavra" sensor"

Código: [Seleccione]
f for(int x=0;x<sensors;x++) {
    Serial.println(" ");
    buf += " ";

   
    Serial.print(" ");
    buf += " ";
    Serial.print(get_temperature(sensors_address[x]));
    buf += get_temperature(sensors_address[x]);

    Serial.println(" C");
    buf += " C";
Título: Re: Iniciante - juntar codigos
Enviado por: MRData em 16 de Janeiro de 2015, 22:30
Porque no fim da tua função colocaste um delay(2000); que corresponde a teres de esperar 2 segs...
Tenta apagar essa linha..
E deves ter outros delays...
Título: Re: Iniciante - juntar codigos
Enviado por: senso em 16 de Janeiro de 2015, 22:39
Espero bem que não, porque isso significa que o código é mesmo muito horrivel, por outro lado, não me espanta que demore 15 dias a actualizar o ecrã e que mal mandes escrever no ecrã o estejas a mandar apagar tudo.
Título: Re: Iniciante - juntar codigos
Enviado por: MRData em 16 de Janeiro de 2015, 22:44
Coloca aqui o codigo pff.
Título: Re: Iniciante - juntar codigos
Enviado por: StarRider em 16 de Janeiro de 2015, 22:46
Ja tirei mas continua. Não vejo mais onde possa mexer. A frase está mais tempo apagada do que a exibir os valores. Será que é esse o tempo de o arduino correr o codigo?

Em parte sim, tens por ai redundância a dizer chega ...

Começa por retirar o loop "for" para ler os sensores pois se só tens um de nada serve :)
Título: Re: Iniciante - juntar codigos
Enviado por: MRData em 16 de Janeiro de 2015, 22:55
Faz uma coisa primeiro, tira a parte de ler a temperatura e ve se actualiza de seg em seg
Título: Re: Iniciante - juntar codigos
Enviado por: MRData em 16 de Janeiro de 2015, 23:13
Substitui o teu projecto por este :
Eu modifiquei, certifica-te que o delay esta a seguir ao escrever para o ecra.

Código: [Seleccione]
#include "Wire.h"
#include <UTFT.h>
#include <OneWire.h>


extern uint8_t SmallFont[];

#define DS3231_I2C_ADDRESS 0x68
// Convert normal decimal numbers to binary coded decimal
const int sensors = 1; //number of temperature sensors on the bus
int sensors_pin = 10; //the pin where the bus its connected to arduino
uint8_t sensors_address[sensors][8]; //here will store the sensors addresses for later use

OneWire  sensor_bus(sensors_pin);

float get_temperature (uint8_t *address);


UTFT myGLCD(ITDB32S,38,39,40,41);

byte decToBcd(byte val)
{
  return( (val/10*16) + (val%10) );
}
// Convert binary coded decimal to normal decimal numbers
byte bcdToDec(byte val)
{
  return( (val/16*10) + (val%16) );
}
void setup()
{
  Wire.begin();
  Serial.begin(9600);
  setDS3231time(30,21,19,6,6,01,15);
  // set the initial time here:
  // DS3231 seconds, minutes, hours, day, date, month, year
  // setDS3231time(30,40,18,5,26,11,14);
  randomSeed(analogRead(0));


  myGLCD.InitLCD();
  myGLCD.setFont(SmallFont);

  int x,y,c=0;
  Serial.println("Starting to look for sensors...");
  for(x=0;x<sensors;x++){
    if(sensor_bus.search(sensors_address[x]))
      c++;
  }
  if(c > 0) {
    Serial.println("Found this sensors : ");
    for(x=0;x<sensors;x++) {
      Serial.print("\tSensor ");
      Serial.print(x+1);
      Serial.print(" at address : ");
      for(y=0;y<8;y++){
        Serial.print(sensors_address[x][y],HEX);
        Serial.print(" ");
      }
      Serial.println();
    }
  }
  else
    Serial.println("Didn't find any sensors");
}
void setDS3231time(byte second, byte minute, byte hour, byte dayOfWeek, byte
dayOfMonth, byte month, byte year)
{
  // sets time and date data to DS3231
  Wire.beginTransmission(DS3231_I2C_ADDRESS);
  Wire.write(0); // set next input to start at the seconds register
  Wire.write(decToBcd(second)); // set seconds
  Wire.write(decToBcd(minute)); // set minutes
  Wire.write(decToBcd(hour)); // set hours
  Wire.write(decToBcd(dayOfWeek)); // set day of week (1=Sunday, 7=Saturday)
  Wire.write(decToBcd(dayOfMonth)); // set date (1 to 31)
  Wire.write(decToBcd(month)); // set month
  Wire.write(decToBcd(year)); // set year (0 to 99)
  Wire.endTransmission();
}
void readDS3231time(byte *second,
byte *minute,
byte *hour,
byte *dayOfWeek,
byte *dayOfMonth,
byte *month,
byte *year)
{
  Wire.beginTransmission(DS3231_I2C_ADDRESS);
  Wire.write(0); // set DS3231 register pointer to 00h
  Wire.endTransmission();
  Wire.requestFrom(DS3231_I2C_ADDRESS, 7);
  // request seven bytes of data from DS3231 starting from register 00h
  *second = bcdToDec(Wire.read() & 0x7f);
  *minute = bcdToDec(Wire.read());
  *hour = bcdToDec(Wire.read() & 0x3f);
  *dayOfWeek = bcdToDec(Wire.read());
  *dayOfMonth = bcdToDec(Wire.read());
  *month = bcdToDec(Wire.read());
  *year = bcdToDec(Wire.read());
}

String displayTime()
{
  byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;
  String buf = "";
  // retrieve data from DS3231
  readDS3231time(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month,
  &year);
  // send it to the serial monitor
  Serial.print(hour, DEC);
  buf += hour;
  // convert the byte variable to a decimal number when displayed
  Serial.print(" :");
  buf += ":";
  if (minute<10)
  {
    Serial.print("0");
    buf += "0";
  }
  Serial.print(minute, DEC);
  buf += minute;
  Serial.print(":");
  buf += ":";
  if (second<10)
  {
    Serial.print("0");
    buf += "0";
    buf += "0";
  }
  Serial.print(second, DEC);
  buf += second;
  Serial.print(" ");
  buf += " ";
  Serial.print(dayOfMonth, DEC);
  buf += dayOfMonth;
  Serial.print("/");
  buf += "/";
  Serial.print(month, DEC);
  buf += month;
  Serial.print("/");
  buf += "/";
  Serial.print(year, DEC);
  buf += year;
  Serial.print(" ");
  buf += " ";
  switch(dayOfWeek){
  case 1:
    Serial.println("Domingo");
    buf += "Domingo";
    break;
  case 2:
    Serial.println("Segunda");
    buf += "Segunda";
    break;
  case 3:
    Serial.println("Terça");
    buf += "Terça";
    break;
  case 4:
    Serial.println("Quarta");
    buf += "Quarta";
    break;
  case 5:
    Serial.println("Quinta");
    buf += "Quinta";
    break;
  case 6:
    Serial.println("Sexta");
    buf += "Sexta";
    break;
  case 7:
    Serial.println("Sabado");
    buf += "Sabado";
    break;
  }

  for(int x=0;x<sensors;x++) {
    Serial.println(" ");
    buf += " ";

   
    Serial.print(" ");
    buf += " ";
    Serial.print(get_temperature(sensors_address[x]));
    buf += get_temperature(sensors_address[x]);

    Serial.println(" C");
    buf += " C";
  }
 
  return buf;
}


float get_temperature(uint8_t *address) {
  byte data[12];
  int x;
  sensor_bus.reset();
  sensor_bus.select(address);
  sensor_bus.write(0x44,1);

  sensor_bus.reset();
  sensor_bus.select(address);
  sensor_bus.write(0xBE,1);
  for(x=0;x<9;x++){
    data[x] = sensor_bus.read();
  }


  unsigned short tr = data[0];
  tr = tr + data[1]*256;

  if(tr > 0xF000){
    tr = 0 - tr;
  }


  float temperature = (float)tr*(float)0.0625 ;

  return temperature;
}



void loop()
{
  displayTime(); // display the real-time clock data on the Serial Monitor,


  int buf[318];
  int x, x2;
  int y, y2;
  int r;


 

  myGLCD.setColor(255, 0, 0);
  myGLCD.fillRect(0, 0, 319, 13);
  myGLCD.setColor(64, 64, 64);
  myGLCD.setBackColor(255, 0, 0);

  myGLCD.print(displayTime(), CENTER, 1) ;
delay(1000);



 

}


Título: Re: Iniciante - juntar codigos
Enviado por: StarRider em 16 de Janeiro de 2015, 23:35
Boas novamente,

Preferia dar uma cana em vez de dar um peixe, mas agora também estou curioso.

Experimenta este código:
Tem em atenção que não experimentei o mesmo (não tenho o IDE do arduino instalado nem sequer o
avr-gcc pois uso outra toolchian) , pelo que se der erros de compilação diz qualquer coisa.

Código: [Seleccione]
#include "Wire.h"
#include <UTFT.h>
#include <OneWire.h>

/*----- externals */
extern uint8_t SmallFont[];

#define DS3231_I2C_ADDRESS 0x68
// Convert normal decimal numbers to binary coded decimal

/*----- locals */
int sensors_pin = 10; //the pin where the bus its connected to arduino
uint8_t sensor_addres[8]; //here will store the sensors addresses for later use
OneWire  sensor_bus(sensors_pin);
float get_temperature(uint8_t *address);
char *daynames[] = {"Domingo", "Segunda", "Terça", "Quarta", "Quinta", "Sexta", "Sabado"};
UTFT myGLCD(ITDB32S,38,39,40,41);
char timetempbuf[64];
byte sec, min, hour, dow, dom, mon, year;


/*---------------------------------------------------------*/
byte decToBcd(byte val)
{
return( (val/10*16) + (val%10) );
}

/*---------------------------------------------------------*/
byte bcdToDec(byte val)
{
return( (val/16*10) + (val%16) );
}

/*---------------------------------------------------------*/
void setup()
{
Wire.begin();
Serial.begin(9600);
setDS3231time(30,21,19,6,6,01,15);
// set the initial time here:
// DS3231 seconds, minutes, hours, day, date, month, year
// setDS3231time(30,40,18,5,26,11,14);
randomSeed(analogRead(0));

myGLCD.InitLCD();
myGLCD.setFont(SmallFont);

Serial.println("Starting to look for sensors...");
if(sensor_bus.search(sensor_addres))
Serial.println("Found sensor at address : " + sensor_addres);
else
Serial.println("Didn't find any sensors");
}

/*---------------------------------------------------------*/
void setDS3231time(byte second, byte minute, byte hour, byte dayOfWeek, byte dayOfMonth, byte month, byte year)
{
// sets time and date data to DS3231
Wire.beginTransmission(DS3231_I2C_ADDRESS);
Wire.write(0); // set next input to start at the seconds register
Wire.write(decToBcd(second)); // set seconds
Wire.write(decToBcd(minute)); // set minutes
Wire.write(decToBcd(hour)); // set hours
Wire.write(decToBcd(dayOfWeek)); // set day of week (1=Sunday, 7=Saturday)
Wire.write(decToBcd(dayOfMonth)); // set date (1 to 31)
Wire.write(decToBcd(month)); // set month
Wire.write(decToBcd(year)); // set year (0 to 99)
Wire.endTransmission();
}

/*---------------------------------------------------------*/
void readDS3231time(byte *second, byte *minute, byte *hour, byte *dayOfWeek, byte *dayOfMonth, byte *month, byte *year)
{
Wire.beginTransmission(DS3231_I2C_ADDRESS);
Wire.write(0); // set DS3231 register pointer to 00h
Wire.endTransmission();
Wire.requestFrom(DS3231_I2C_ADDRESS, 7);
// request seven bytes of data from DS3231 starting from register 00h
*second = bcdToDec(Wire.read() & 0x7f);
*minute = bcdToDec(Wire.read());
*hour = bcdToDec(Wire.read() & 0x3f);
*dayOfWeek = bcdToDec(Wire.read());
*dayOfMonth = bcdToDec(Wire.read());
*month = bcdToDec(Wire.read());
*year = bcdToDec(Wire.read());
}


/*---------------------------------------------------------*/
float get_temperature(uint8_t *address)
{
byte data[12];
int x;
sensor_bus.reset();
sensor_bus.select(address);
sensor_bus.write(0x44,1);

sensor_bus.reset();
sensor_bus.select(address);
sensor_bus.write(0xBE,1);
for(x=0;x<9;x++){
data[x] = sensor_bus.read();
}

unsigned short tr = data[0];
tr = tr + data[1]*256;

if(tr > 0xF000){
tr = 0 - tr;
}

float temperature = (float)tr*(float)0.0625 ;
return temperature;
}


/*---------------------------------------------------------*/
void loop()
{
readDS3231time(&sec, &min, &hour, &dow, &dom, &mon, &year);
        sprintf(timetempbuf,"%02d:%02d:%02d  %02d/%02d/%04d %s %4.1fC\r\n",hour, min, sec, dom, mon, year, dayname[dow],get_temperature(sensor_addres));

Serial.println(timetempbuf);
myGLCD.setColor(255, 0, 0);
myGLCD.fillRect(0, 0, 319, 13);
myGLCD.setColor(64, 64, 64);
myGLCD.setBackColor(255, 0, 0);
myGLCD.print(timetempbuf, CENTER, 1) ;

delay(1000); // every second

}

/*---------------------------------------------------------*/
/* eof */
Título: Re: Iniciante - juntar codigos
Enviado por: StarRider em 16 de Janeiro de 2015, 23:40
StarRider, deu erro 

 This report would have more information with
  "Show verbose output during compilation"
  enabled in File > Preferences.
Arduino: 1.0.6 (Windows NT (unknown)), Board: "Arduino Mega 2560 or Mega ADK"
sketch_jan16b.ino: In function 'void setup()':
sketch_jan16b:50: error: invalid operands of types 'const char [27]' and 'uint8_t [8]' to binary 'operator+'
sketch_jan16b.ino: In function 'void loop()':
sketch_jan16b:121: error: 'dayname' was not declared in this scope

Ok, deixa-me ver ... estou a apalpar ....
Título: Re: Iniciante - juntar codigos
Enviado por: MRData em 16 de Janeiro de 2015, 23:41
Testa isto pff.
Enquanto o Star corrige o erro.

Código: [Seleccione]
#include "Wire.h"
#include <UTFT.h>
#include <OneWire.h>


extern uint8_t SmallFont[];

#define DS3231_I2C_ADDRESS 0x68
// Convert normal decimal numbers to binary coded decimal
const int sensors = 1; //number of temperature sensors on the bus
int sensors_pin = 10; //the pin where the bus its connected to arduino
uint8_t sensors_address[sensors][8]; //here will store the sensors addresses for later use

OneWire  sensor_bus(sensors_pin);

float get_temperature (uint8_t *address);


UTFT myGLCD(ITDB32S,38,39,40,41);

byte decToBcd(byte val)
{
  return( (val/10*16) + (val%10) );
}
// Convert binary coded decimal to normal decimal numbers
byte bcdToDec(byte val)
{
  return( (val/16*10) + (val%16) );
}
void setup()
{
  Wire.begin();
  Serial.begin(9600);
  setDS3231time(30,21,19,6,6,01,15);
  // set the initial time here:
  // DS3231 seconds, minutes, hours, day, date, month, year
  // setDS3231time(30,40,18,5,26,11,14);
  randomSeed(analogRead(0));


  myGLCD.InitLCD();
  myGLCD.setFont(SmallFont);

  int x,y,c=0;
  Serial.println("Starting to look for sensors...");
  for(x=0;x<sensors;x++){
    if(sensor_bus.search(sensors_address[x]))
      c++;
  }
  if(c > 0) {
    Serial.println("Found this sensors : ");
    for(x=0;x<sensors;x++) {
      Serial.print("\tSensor ");
      Serial.print(x+1);
      Serial.print(" at address : ");
      for(y=0;y<8;y++){
        Serial.print(sensors_address[x][y],HEX);
        Serial.print(" ");
      }
      Serial.println();
    }
  }
  else
    Serial.println("Didn't find any sensors");
}
void setDS3231time(byte second, byte minute, byte hour, byte dayOfWeek, byte
dayOfMonth, byte month, byte year)
{
  // sets time and date data to DS3231
  Wire.beginTransmission(DS3231_I2C_ADDRESS);
  Wire.write(0); // set next input to start at the seconds register
  Wire.write(decToBcd(second)); // set seconds
  Wire.write(decToBcd(minute)); // set minutes
  Wire.write(decToBcd(hour)); // set hours
  Wire.write(decToBcd(dayOfWeek)); // set day of week (1=Sunday, 7=Saturday)
  Wire.write(decToBcd(dayOfMonth)); // set date (1 to 31)
  Wire.write(decToBcd(month)); // set month
  Wire.write(decToBcd(year)); // set year (0 to 99)
  Wire.endTransmission();
}
void readDS3231time(byte *second,
byte *minute,
byte *hour,
byte *dayOfWeek,
byte *dayOfMonth,
byte *month,
byte *year)
{
  Wire.beginTransmission(DS3231_I2C_ADDRESS);
  Wire.write(0); // set DS3231 register pointer to 00h
  Wire.endTransmission();
  Wire.requestFrom(DS3231_I2C_ADDRESS, 7);
  // request seven bytes of data from DS3231 starting from register 00h
  *second = bcdToDec(Wire.read() & 0x7f);
  *minute = bcdToDec(Wire.read());
  *hour = bcdToDec(Wire.read() & 0x3f);
  *dayOfWeek = bcdToDec(Wire.read());
  *dayOfMonth = bcdToDec(Wire.read());
  *month = bcdToDec(Wire.read());
  *year = bcdToDec(Wire.read());
}

String displayTime()
{
  byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;
  String buf = "";
  // retrieve data from DS3231
  readDS3231time(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month,
  &year);
  // send it to the serial monitor
  Serial.print(hour, DEC);
  buf += hour;
  // convert the byte variable to a decimal number when displayed
  Serial.print(" :");
  buf += ":";
  if (minute<10)
  {
    Serial.print("0");
    buf += "0";
  }
  Serial.print(minute, DEC);
  buf += minute;
  Serial.print(":");
  buf += ":";
  if (second<10)
  {
    Serial.print("0");
    buf += "0";
    buf += "0";
  }
  Serial.print(second, DEC);
  buf += second;
  Serial.print(" ");
  buf += " ";
  Serial.print(dayOfMonth, DEC);
  buf += dayOfMonth;
  Serial.print("/");
  buf += "/";
  Serial.print(month, DEC);
  buf += month;
  Serial.print("/");
  buf += "/";
  Serial.print(year, DEC);
  buf += year;
  Serial.print(" ");
  buf += " ";
  switch(dayOfWeek){
  case 1:
    Serial.println("Domingo");
    buf += "Domingo";
    break;
  case 2:
    Serial.println("Segunda");
    buf += "Segunda";
    break;
  case 3:
    Serial.println("Terça");
    buf += "Terça";
    break;
  case 4:
    Serial.println("Quarta");
    buf += "Quarta";
    break;
  case 5:
    Serial.println("Quinta");
    buf += "Quinta";
    break;
  case 6:
    Serial.println("Sexta");
    buf += "Sexta";
    break;
  case 7:
    Serial.println("Sabado");
    buf += "Sabado";
    break;
  }

  for(int x=0;x<sensors;x++) {
    Serial.println(" ");
    buf += " ";

   
    Serial.print(" ");
    buf += " ";
    Serial.print(get_temperature(sensors_address[x]));
    buf += get_temperature(sensors_address[x]);

    Serial.println(" C");
    buf += " C";
  }
 
  return buf;
}


float get_temperature(uint8_t *address) {
  byte data[12];
  int x;
  sensor_bus.reset();
  sensor_bus.select(address);
  sensor_bus.write(0x44,1);

  sensor_bus.reset();
  sensor_bus.select(address);
  sensor_bus.write(0xBE,1);
  for(x=0;x<9;x++){
    data[x] = sensor_bus.read();
  }


  unsigned short tr = data[0];
  tr = tr + data[1]*256;

  if(tr > 0xF000){
    tr = 0 - tr;
  }


  float temperature = (float)tr*(float)0.0625 ;

  return temperature;
}



void loop()
{
  int buf[318];
  int x, x2;
  int y, y2;
  int r;


 

  myGLCD.setColor(255, 0, 0);
  myGLCD.fillRect(0, 0, 319, 13);
  myGLCD.setColor(64, 64, 64);
  myGLCD.setBackColor(255, 0, 0);

  myGLCD.print(displayTime(), CENTER, 1) ;
  delay(1000);
}

Título: Re: Iniciante - juntar codigos
Enviado por: MRData em 16 de Janeiro de 2015, 23:48
Ja agora testa so mais este pff.
Não vai dar os dados da temperatura mas é so para ver se as coisas aparecem no ecra correctamente.

Código: [Seleccione]
#include "Wire.h"
#include <UTFT.h>
#include <OneWire.h>


extern uint8_t SmallFont[];

#define DS3231_I2C_ADDRESS 0x68
// Convert normal decimal numbers to binary coded decimal
const int sensors = 1; //number of temperature sensors on the bus
int sensors_pin = 10; //the pin where the bus its connected to arduino
uint8_t sensors_address[sensors][8]; //here will store the sensors addresses for later use

OneWire  sensor_bus(sensors_pin);

float get_temperature (uint8_t *address);


UTFT myGLCD(ITDB32S,38,39,40,41);

byte decToBcd(byte val)
{
  return( (val/10*16) + (val%10) );
}
// Convert binary coded decimal to normal decimal numbers
byte bcdToDec(byte val)
{
  return( (val/16*10) + (val%16) );
}
void setup()
{
  Wire.begin();
  Serial.begin(9600);
  setDS3231time(30,21,19,6,6,01,15);
  // set the initial time here:
  // DS3231 seconds, minutes, hours, day, date, month, year
  // setDS3231time(30,40,18,5,26,11,14);
  randomSeed(analogRead(0));


  myGLCD.InitLCD();
  myGLCD.setFont(SmallFont);

  int x,y,c=0;
  Serial.println("Starting to look for sensors...");
  for(x=0;x<sensors;x++){
    if(sensor_bus.search(sensors_address[x]))
      c++;
  }
  if(c > 0) {
    Serial.println("Found this sensors : ");
    for(x=0;x<sensors;x++) {
      Serial.print("\tSensor ");
      Serial.print(x+1);
      Serial.print(" at address : ");
      for(y=0;y<8;y++){
        Serial.print(sensors_address[x][y],HEX);
        Serial.print(" ");
      }
      Serial.println();
    }
  }
  else
    Serial.println("Didn't find any sensors");
}
void setDS3231time(byte second, byte minute, byte hour, byte dayOfWeek, byte
dayOfMonth, byte month, byte year)
{
  // sets time and date data to DS3231
  Wire.beginTransmission(DS3231_I2C_ADDRESS);
  Wire.write(0); // set next input to start at the seconds register
  Wire.write(decToBcd(second)); // set seconds
  Wire.write(decToBcd(minute)); // set minutes
  Wire.write(decToBcd(hour)); // set hours
  Wire.write(decToBcd(dayOfWeek)); // set day of week (1=Sunday, 7=Saturday)
  Wire.write(decToBcd(dayOfMonth)); // set date (1 to 31)
  Wire.write(decToBcd(month)); // set month
  Wire.write(decToBcd(year)); // set year (0 to 99)
  Wire.endTransmission();
}
void readDS3231time(byte *second,
byte *minute,
byte *hour,
byte *dayOfWeek,
byte *dayOfMonth,
byte *month,
byte *year)
{
  Wire.beginTransmission(DS3231_I2C_ADDRESS);
  Wire.write(0); // set DS3231 register pointer to 00h
  Wire.endTransmission();
  Wire.requestFrom(DS3231_I2C_ADDRESS, 7);
  // request seven bytes of data from DS3231 starting from register 00h
  *second = bcdToDec(Wire.read() & 0x7f);
  *minute = bcdToDec(Wire.read());
  *hour = bcdToDec(Wire.read() & 0x3f);
  *dayOfWeek = bcdToDec(Wire.read());
  *dayOfMonth = bcdToDec(Wire.read());
  *month = bcdToDec(Wire.read());
  *year = bcdToDec(Wire.read());
}

String displayTime()
{
  byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;
  String buf = "";
  // retrieve data from DS3231
  readDS3231time(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month,
  &year);
  // send it to the serial monitor
  Serial.print(hour, DEC);
  buf += hour;
  // convert the byte variable to a decimal number when displayed
  Serial.print(" :");
  buf += ":";
  if (minute<10)
  {
    Serial.print("0");
    buf += "0";
  }
  Serial.print(minute, DEC);
  buf += minute;
  Serial.print(":");
  buf += ":";
  if (second<10)
  {
    Serial.print("0");
    buf += "0";
    buf += "0";
  }
  Serial.print(second, DEC);
  buf += second;
  Serial.print(" ");
  buf += " ";
  Serial.print(dayOfMonth, DEC);
  buf += dayOfMonth;
  Serial.print("/");
  buf += "/";
  Serial.print(month, DEC);
  buf += month;
  Serial.print("/");
  buf += "/";
  Serial.print(year, DEC);
  buf += year;
  Serial.print(" ");
  buf += " ";
  switch(dayOfWeek){
  case 1:
    Serial.println("Domingo");
    buf += "Domingo";
    break;
  case 2:
    Serial.println("Segunda");
    buf += "Segunda";
    break;
  case 3:
    Serial.println("Terça");
    buf += "Terça";
    break;
  case 4:
    Serial.println("Quarta");
    buf += "Quarta";
    break;
  case 5:
    Serial.println("Quinta");
    buf += "Quinta";
    break;
  case 6:
    Serial.println("Sexta");
    buf += "Sexta";
    break;
  case 7:
    Serial.println("Sabado");
    buf += "Sabado";
    break;
  } 
  return buf;
}


float get_temperature(uint8_t *address) {
  byte data[12];
  int x;
  sensor_bus.reset();
  sensor_bus.select(address);
  sensor_bus.write(0x44,1);

  sensor_bus.reset();
  sensor_bus.select(address);
  sensor_bus.write(0xBE,1);
  for(x=0;x<9;x++){
    data[x] = sensor_bus.read();
  }


  unsigned short tr = data[0];
  tr = tr + data[1]*256;

  if(tr > 0xF000){
    tr = 0 - tr;
  }


  float temperature = (float)tr*(float)0.0625 ;

  return temperature;
}



void loop()
{
  int buf[318];
  int x, x2;
  int y, y2;
  int r;


 

  myGLCD.setColor(255, 0, 0);
  myGLCD.fillRect(0, 0, 319, 13);
  myGLCD.setColor(64, 64, 64);
  myGLCD.setBackColor(255, 0, 0);

  myGLCD.print(displayTime(), CENTER, 1) ;
  delay(1000);
}
Título: Re: Iniciante - juntar codigos
Enviado por: StarRider em 16 de Janeiro de 2015, 23:53
Pensei que já tinha postado ... aqui vai:

Código: [Seleccione]
#include "Wire.h"
#include <UTFT.h>
#include <OneWire.h>

/*----- externals */
extern uint8_t SmallFont[];

#define DS3231_I2C_ADDRESS 0x68
// Convert normal decimal numbers to binary coded decimal

/*----- locals */
int sensors_pin = 10; //the pin where the bus its connected to arduino
uint8_t sensor_addres[8]; //here will store the sensors addresses for later use
OneWire  sensor_bus(sensors_pin);
float get_temperature(uint8_t *address);
char *daynames[] = {"Domingo", "Segunda", "Terça", "Quarta", "Quinta", "Sexta", "Sabado"};
UTFT myGLCD(ITDB32S,38,39,40,41);
char timetempbuf[64];
byte sec, min, hour, dow, dom, mon, year;


/*---------------------------------------------------------*/
byte decToBcd(byte val)
{
return( (val/10*16) + (val%10) );
}

/*---------------------------------------------------------*/
byte bcdToDec(byte val)
{
return( (val/16*10) + (val%16) );
}

/*---------------------------------------------------------*/
void setup()
{
Wire.begin();
Serial.begin(9600);
setDS3231time(30,21,19,6,6,01,15);
// set the initial time here:
// DS3231 seconds, minutes, hours, day, date, month, year
// setDS3231time(30,40,18,5,26,11,14);
randomSeed(analogRead(0));

myGLCD.InitLCD();
myGLCD.setFont(SmallFont);

Serial.println("Starting to look for sensors...");
if(sensor_bus.search(sensor_addres)) {
Serial.print("Found sensor at address : ");
//Serial.println(sensor_addres);
} else
Serial.println("Didn't find any sensors");
}

/*---------------------------------------------------------*/
void setDS3231time(byte second, byte minute, byte hour, byte dayOfWeek, byte dayOfMonth, byte month, byte year)
{
// sets time and date data to DS3231
Wire.beginTransmission(DS3231_I2C_ADDRESS);
Wire.write(0); // set next input to start at the seconds register
Wire.write(decToBcd(second)); // set seconds
Wire.write(decToBcd(minute)); // set minutes
Wire.write(decToBcd(hour)); // set hours
Wire.write(decToBcd(dayOfWeek)); // set day of week (1=Sunday, 7=Saturday)
Wire.write(decToBcd(dayOfMonth)); // set date (1 to 31)
Wire.write(decToBcd(month)); // set month
Wire.write(decToBcd(year)); // set year (0 to 99)
Wire.endTransmission();
}

/*---------------------------------------------------------*/
void readDS3231time(byte *second, byte *minute, byte *hour, byte *dayOfWeek, byte *dayOfMonth, byte *month, byte *year)
{
Wire.beginTransmission(DS3231_I2C_ADDRESS);
Wire.write(0); // set DS3231 register pointer to 00h
Wire.endTransmission();
Wire.requestFrom(DS3231_I2C_ADDRESS, 7);
// request seven bytes of data from DS3231 starting from register 00h
*second = bcdToDec(Wire.read() & 0x7f);
*minute = bcdToDec(Wire.read());
*hour = bcdToDec(Wire.read() & 0x3f);
*dayOfWeek = bcdToDec(Wire.read());
*dayOfMonth = bcdToDec(Wire.read());
*month = bcdToDec(Wire.read());
*year = bcdToDec(Wire.read());
}


/*---------------------------------------------------------*/
float get_temperature(uint8_t *address)
{
byte data[12];
int x;
sensor_bus.reset();
sensor_bus.select(address);
sensor_bus.write(0x44,1);

sensor_bus.reset();
sensor_bus.select(address);
sensor_bus.write(0xBE,1);
for(x=0;x<9;x++){
data[x] = sensor_bus.read();
}

unsigned short tr = data[0];
tr = tr + data[1]*256;

if(tr > 0xF000){
tr = 0 - tr;
}

float temperature = (float)tr*(float)0.0625 ;
return temperature;
}


/*---------------------------------------------------------*/
void loop()
{
readDS3231time(&sec, &min, &hour, &dow, &dom, &mon, &year);
   sprintf(timetempbuf,"%02d:%02d:%02d  %02d/%02d/%04d %s %4.1fC",hour, min, sec, dom, mon, year, daynames[dow],get_temperature(sensor_addres));

Serial.println(timetempbuf);
myGLCD.setColor(255, 0, 0);
myGLCD.fillRect(0, 0, 319, 13);
myGLCD.setColor(64, 64, 64);
myGLCD.setBackColor(255, 0, 0);
myGLCD.print(timetempbuf, CENTER, 1) ;

delay(1000); // every second

}

/*---------------------------------------------------------*/
/* eof */
Título: Re: Iniciante - juntar codigos
Enviado por: MRData em 16 de Janeiro de 2015, 23:56
Faltava uma coisa
Testa com este pff :

Código: [Seleccione]
#include "Wire.h"
#include <UTFT.h>
#include <OneWire.h>


extern uint8_t SmallFont[];

#define DS3231_I2C_ADDRESS 0x68
// Convert normal decimal numbers to binary coded decimal
const int sensors = 1; //number of temperature sensors on the bus
int sensors_pin = 10; //the pin where the bus its connected to arduino
uint8_t sensors_address[sensors][8]; //here will store the sensors addresses for later use

OneWire  sensor_bus(sensors_pin);

float get_temperature (uint8_t *address);


UTFT myGLCD(ITDB32S,38,39,40,41);

byte decToBcd(byte val)
{
  return( (val/10*16) + (val%10) );
}
// Convert binary coded decimal to normal decimal numbers
byte bcdToDec(byte val)
{
  return( (val/16*10) + (val%16) );
}
void setup()
{
  Wire.begin();
  Serial.begin(9600);
  setDS3231time(30,21,19,6,6,01,15);
  // set the initial time here:
  // DS3231 seconds, minutes, hours, day, date, month, year
  // setDS3231time(30,40,18,5,26,11,14);
  randomSeed(analogRead(0));


  myGLCD.InitLCD();
  myGLCD.setFont(SmallFont);

  int x,y,c=0;
  Serial.println("Starting to look for sensors...");
  for(x=0;x<sensors;x++){
    if(sensor_bus.search(sensors_address[x]))
      c++;
  }
  if(c > 0) {
    Serial.println("Found this sensors : ");
    for(x=0;x<sensors;x++) {
      Serial.print("\tSensor ");
      Serial.print(x+1);
      Serial.print(" at address : ");
      for(y=0;y<8;y++){
        Serial.print(sensors_address[x][y],HEX);
        Serial.print(" ");
      }
      Serial.println();
    }
  }
  else
    Serial.println("Didn't find any sensors");
}
void setDS3231time(byte second, byte minute, byte hour, byte dayOfWeek, byte
dayOfMonth, byte month, byte year)
{
  // sets time and date data to DS3231
  Wire.beginTransmission(DS3231_I2C_ADDRESS);
  Wire.write(0); // set next input to start at the seconds register
  Wire.write(decToBcd(second)); // set seconds
  Wire.write(decToBcd(minute)); // set minutes
  Wire.write(decToBcd(hour)); // set hours
  Wire.write(decToBcd(dayOfWeek)); // set day of week (1=Sunday, 7=Saturday)
  Wire.write(decToBcd(dayOfMonth)); // set date (1 to 31)
  Wire.write(decToBcd(month)); // set month
  Wire.write(decToBcd(year)); // set year (0 to 99)
  Wire.endTransmission();
}
void readDS3231time(byte *second,
byte *minute,
byte *hour,
byte *dayOfWeek,
byte *dayOfMonth,
byte *month,
byte *year)
{
  Wire.beginTransmission(DS3231_I2C_ADDRESS);
  Wire.write(0); // set DS3231 register pointer to 00h
  Wire.endTransmission();
  Wire.requestFrom(DS3231_I2C_ADDRESS, 7);
  // request seven bytes of data from DS3231 starting from register 00h
  *second = bcdToDec(Wire.read() & 0x7f);
  *minute = bcdToDec(Wire.read());
  *hour = bcdToDec(Wire.read() & 0x3f);
  *dayOfWeek = bcdToDec(Wire.read());
  *dayOfMonth = bcdToDec(Wire.read());
  *month = bcdToDec(Wire.read());
  *year = bcdToDec(Wire.read());
}

String displayTime()
{
  byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;
  String buf = "";
  // retrieve data from DS3231
  readDS3231time(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month,
  &year);
  // send it to the serial monitor
  Serial.print(hour, DEC);
  buf += hour;
  // convert the byte variable to a decimal number when displayed
  Serial.print(" :");
  buf += ":";
  if (minute<10)
  {
    Serial.print("0");
    buf += "0";
  }
  Serial.print(minute, DEC);
  buf += minute;
  Serial.print(":");
  buf += ":";
  if (second<10)
  {
    Serial.print("0");
    buf += "0";
    buf += "0";
  }
  Serial.print(second, DEC);
  buf += second;
  Serial.print(" ");
  buf += " ";
  Serial.print(dayOfMonth, DEC);
  buf += dayOfMonth;
  Serial.print("/");
  buf += "/";
  Serial.print(month, DEC);
  buf += month;
  Serial.print("/");
  buf += "/";
  Serial.print(year, DEC);
  buf += year;
  Serial.print(" ");
  buf += " ";
  switch(dayOfWeek){
  case 1:
    Serial.println("Domingo");
    buf += "Domingo";
    break;
  case 2:
    Serial.println("Segunda");
    buf += "Segunda";
    break;
  case 3:
    Serial.println("Terça");
    buf += "Terça";
    break;
  case 4:
    Serial.println("Quarta");
    buf += "Quarta";
    break;
  case 5:
    Serial.println("Quinta");
    buf += "Quinta";
    break;
  case 6:
    Serial.println("Sexta");
    buf += "Sexta";
    break;
  case 7:
    Serial.println("Sabado");
    buf += "Sabado";
    break;
  } 

  for(int x=0;x<sensors;x++) {
    Serial.println(" ");
    buf += " ";

   
    Serial.print(" ");
    buf += " ";
    Serial.print(get_temperature(sensors_address[x]));
    buf += get_temperature(sensors_address[x]);

    Serial.println(" C");
    buf += " C";
  }

  return buf;
}


float get_temperature(uint8_t *address) {
  byte data[12];
  int x;
  sensor_bus.reset();
  sensor_bus.select(address);
  sensor_bus.write(0x44,1);

  sensor_bus.reset();
  sensor_bus.select(address);
  sensor_bus.write(0xBE,1);
  for(x=0;x<9;x++){
    data[x] = sensor_bus.read();
  }


  unsigned short tr = data[0];
  tr = tr + data[1]*256;

  if(tr > 0xF000){
    tr = 0 - tr;
  }


  float temperature = (float)tr*(float)0.0625 ;

  return temperature;
}



void loop()
{
  int buf[318];
  int x, x2;
  int y, y2;
  int r;


  myGLCD.clrScr();

  myGLCD.setColor(255, 0, 0);
  myGLCD.fillRect(0, 0, 319, 13);
  myGLCD.setColor(64, 64, 64);
  myGLCD.setBackColor(255, 0, 0);

  myGLCD.print(displayTime(), CENTER, 1) ;
  delay(1000);
}
Título: Re: Iniciante - juntar codigos
Enviado por: MRData em 17 de Janeiro de 2015, 00:01
Testa agora pff.

Código: [Seleccione]
#include "Wire.h"
#include <UTFT.h>
#include <OneWire.h>


extern uint8_t SmallFont[];

#define DS3231_I2C_ADDRESS 0x68
// Convert normal decimal numbers to binary coded decimal
const int sensors = 1; //number of temperature sensors on the bus
int sensors_pin = 10; //the pin where the bus its connected to arduino
uint8_t sensors_address[sensors][8]; //here will store the sensors addresses for later use

OneWire  sensor_bus(sensors_pin);

float get_temperature (uint8_t *address);


UTFT myGLCD(ITDB32S,38,39,40,41);

byte decToBcd(byte val)
{
  return( (val/10*16) + (val%10) );
}
// Convert binary coded decimal to normal decimal numbers
byte bcdToDec(byte val)
{
  return( (val/16*10) + (val%16) );
}
void setup()
{
  Wire.begin();
  Serial.begin(9600);
  setDS3231time(30,21,19,6,6,01,15);
  // set the initial time here:
  // DS3231 seconds, minutes, hours, day, date, month, year
  // setDS3231time(30,40,18,5,26,11,14);
  randomSeed(analogRead(0));


  myGLCD.InitLCD();
  myGLCD.setFont(SmallFont);

  myGLCD.setColor(255, 0, 0);
  myGLCD.fillRect(0, 0, 319, 13);
  myGLCD.setColor(64, 64, 64);
  myGLCD.setBackColor(255, 0, 0);

  int x,y,c=0;
  Serial.println("Starting to look for sensors...");
  for(x=0;x<sensors;x++){
    if(sensor_bus.search(sensors_address[x]))
      c++;
  }
  if(c > 0) {
    Serial.println("Found this sensors : ");
    for(x=0;x<sensors;x++) {
      Serial.print("\tSensor ");
      Serial.print(x+1);
      Serial.print(" at address : ");
      for(y=0;y<8;y++){
        Serial.print(sensors_address[x][y],HEX);
        Serial.print(" ");
      }
      Serial.println();
    }
  }
  else
    Serial.println("Didn't find any sensors");
}
void setDS3231time(byte second, byte minute, byte hour, byte dayOfWeek, byte
dayOfMonth, byte month, byte year)
{
  // sets time and date data to DS3231
  Wire.beginTransmission(DS3231_I2C_ADDRESS);
  Wire.write(0); // set next input to start at the seconds register
  Wire.write(decToBcd(second)); // set seconds
  Wire.write(decToBcd(minute)); // set minutes
  Wire.write(decToBcd(hour)); // set hours
  Wire.write(decToBcd(dayOfWeek)); // set day of week (1=Sunday, 7=Saturday)
  Wire.write(decToBcd(dayOfMonth)); // set date (1 to 31)
  Wire.write(decToBcd(month)); // set month
  Wire.write(decToBcd(year)); // set year (0 to 99)
  Wire.endTransmission();
}
void readDS3231time(byte *second,
byte *minute,
byte *hour,
byte *dayOfWeek,
byte *dayOfMonth,
byte *month,
byte *year)
{
  Wire.beginTransmission(DS3231_I2C_ADDRESS);
  Wire.write(0); // set DS3231 register pointer to 00h
  Wire.endTransmission();
  Wire.requestFrom(DS3231_I2C_ADDRESS, 7);
  // request seven bytes of data from DS3231 starting from register 00h
  *second = bcdToDec(Wire.read() & 0x7f);
  *minute = bcdToDec(Wire.read());
  *hour = bcdToDec(Wire.read() & 0x3f);
  *dayOfWeek = bcdToDec(Wire.read());
  *dayOfMonth = bcdToDec(Wire.read());
  *month = bcdToDec(Wire.read());
  *year = bcdToDec(Wire.read());
}

String displayTime()
{
  byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;
  String buf = "";
  // retrieve data from DS3231
  readDS3231time(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month,
  &year);
  // send it to the serial monitor
  Serial.print(hour, DEC);
  buf += hour;
  // convert the byte variable to a decimal number when displayed
  Serial.print(" :");
  buf += ":";
  if (minute<10)
  {
    Serial.print("0");
    buf += "0";
  }
  Serial.print(minute, DEC);
  buf += minute;
  Serial.print(":");
  buf += ":";
  if (second<10)
  {
    Serial.print("0");
    buf += "0";
    buf += "0";
  }
  Serial.print(second, DEC);
  buf += second;
  Serial.print(" ");
  buf += " ";
  Serial.print(dayOfMonth, DEC);
  buf += dayOfMonth;
  Serial.print("/");
  buf += "/";
  Serial.print(month, DEC);
  buf += month;
  Serial.print("/");
  buf += "/";
  Serial.print(year, DEC);
  buf += year;
  Serial.print(" ");
  buf += " ";
  switch(dayOfWeek){
  case 1:
    Serial.println("Domingo");
    buf += "Domingo";
    break;
  case 2:
    Serial.println("Segunda");
    buf += "Segunda";
    break;
  case 3:
    Serial.println("Terça");
    buf += "Terça";
    break;
  case 4:
    Serial.println("Quarta");
    buf += "Quarta";
    break;
  case 5:
    Serial.println("Quinta");
    buf += "Quinta";
    break;
  case 6:
    Serial.println("Sexta");
    buf += "Sexta";
    break;
  case 7:
    Serial.println("Sabado");
    buf += "Sabado";
    break;
  } 

  for(int x=0;x<sensors;x++) {
    Serial.println(" ");
    buf += " ";

   
    Serial.print(" ");
    buf += " ";
    Serial.print(get_temperature(sensors_address[x]));
    buf += get_temperature(sensors_address[x]);

    Serial.println(" C");
    buf += " C";
  }

  return buf;
}


float get_temperature(uint8_t *address) {
  byte data[12];
  int x;
  sensor_bus.reset();
  sensor_bus.select(address);
  sensor_bus.write(0x44,1);

  sensor_bus.reset();
  sensor_bus.select(address);
  sensor_bus.write(0xBE,1);
  for(x=0;x<9;x++){
    data[x] = sensor_bus.read();
  }


  unsigned short tr = data[0];
  tr = tr + data[1]*256;

  if(tr > 0xF000){
    tr = 0 - tr;
  }


  float temperature = (float)tr*(float)0.0625 ;

  return temperature;
}



void loop()
{
  int buf[318];
  int x, x2;
  int y, y2;
  int r;


  myGLCD.clrScr();



  myGLCD.print(displayTime(), CENTER, 1) ;
  delay(1000);
}
Título: Re: Iniciante - juntar codigos
Enviado por: StarRider em 17 de Janeiro de 2015, 00:05
Yap, estou na corda bamba ... nunca programei para "arduino" ... pelos visto o "Serial.println" não tem overload para uint8_t

Se tiveres pachorra, comenta a linha 51, deve ficar assim:

//Serial.println(sensor_addres);

Título: Re: Iniciante - juntar codigos
Enviado por: MRData em 17 de Janeiro de 2015, 00:09
O ultimo codigo que te mandei funcionou?

Código: [Seleccione]
#include "Wire.h"
#include <UTFT.h>
#include <OneWire.h>


extern uint8_t SmallFont[];

#define DS3231_I2C_ADDRESS 0x68
// Convert normal decimal numbers to binary coded decimal
const int sensors = 1; //number of temperature sensors on the bus
int sensors_pin = 10; //the pin where the bus its connected to arduino
uint8_t sensors_address[sensors][8]; //here will store the sensors addresses for later use

OneWire  sensor_bus(sensors_pin);

float get_temperature (uint8_t *address);


UTFT myGLCD(ITDB32S,38,39,40,41);

byte decToBcd(byte val)
{
  return( (val/10*16) + (val%10) );
}
// Convert binary coded decimal to normal decimal numbers
byte bcdToDec(byte val)
{
  return( (val/16*10) + (val%16) );
}
void setup()
{
  Wire.begin();
  Serial.begin(9600);
  setDS3231time(30,21,19,6,6,01,15);
  // set the initial time here:
  // DS3231 seconds, minutes, hours, day, date, month, year
  // setDS3231time(30,40,18,5,26,11,14);
  randomSeed(analogRead(0));


  myGLCD.InitLCD();
  myGLCD.setFont(SmallFont);

  myGLCD.setColor(255, 0, 0);
  myGLCD.fillRect(0, 0, 319, 13);
  myGLCD.setColor(64, 64, 64);
  myGLCD.setBackColor(255, 0, 0);

  int x,y,c=0;
  Serial.println("Starting to look for sensors...");
  for(x=0;x<sensors;x++){
    if(sensor_bus.search(sensors_address[x]))
      c++;
  }
  if(c > 0) {
    Serial.println("Found this sensors : ");
    for(x=0;x<sensors;x++) {
      Serial.print("\tSensor ");
      Serial.print(x+1);
      Serial.print(" at address : ");
      for(y=0;y<8;y++){
        Serial.print(sensors_address[x][y],HEX);
        Serial.print(" ");
      }
      Serial.println();
    }
  }
  else
    Serial.println("Didn't find any sensors");
}
void setDS3231time(byte second, byte minute, byte hour, byte dayOfWeek, byte
dayOfMonth, byte month, byte year)
{
  // sets time and date data to DS3231
  Wire.beginTransmission(DS3231_I2C_ADDRESS);
  Wire.write(0); // set next input to start at the seconds register
  Wire.write(decToBcd(second)); // set seconds
  Wire.write(decToBcd(minute)); // set minutes
  Wire.write(decToBcd(hour)); // set hours
  Wire.write(decToBcd(dayOfWeek)); // set day of week (1=Sunday, 7=Saturday)
  Wire.write(decToBcd(dayOfMonth)); // set date (1 to 31)
  Wire.write(decToBcd(month)); // set month
  Wire.write(decToBcd(year)); // set year (0 to 99)
  Wire.endTransmission();
}
void readDS3231time(byte *second,
byte *minute,
byte *hour,
byte *dayOfWeek,
byte *dayOfMonth,
byte *month,
byte *year)
{
  Wire.beginTransmission(DS3231_I2C_ADDRESS);
  Wire.write(0); // set DS3231 register pointer to 00h
  Wire.endTransmission();
  Wire.requestFrom(DS3231_I2C_ADDRESS, 7);
  // request seven bytes of data from DS3231 starting from register 00h
  *second = bcdToDec(Wire.read() & 0x7f);
  *minute = bcdToDec(Wire.read());
  *hour = bcdToDec(Wire.read() & 0x3f);
  *dayOfWeek = bcdToDec(Wire.read());
  *dayOfMonth = bcdToDec(Wire.read());
  *month = bcdToDec(Wire.read());
  *year = bcdToDec(Wire.read());
}

String displayTime()
{
  byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;
  String buf = "";
  // retrieve data from DS3231
  readDS3231time(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month,
  &year);
  // send it to the serial monitor
  Serial.print(hour, DEC);
  buf += hour;
  // convert the byte variable to a decimal number when displayed
  Serial.print(" :");
  buf += ":";
  if (minute<10)
  {
    Serial.print("0");
    buf += "0";
  }
  Serial.print(minute, DEC);
  buf += minute;
  Serial.print(":");
  buf += ":";
  if (second<10)
  {
    Serial.print("0");
    buf += "0";
    buf += "0";
  }
  Serial.print(second, DEC);
  buf += second;
  Serial.print(" ");
  buf += " ";
  Serial.print(dayOfMonth, DEC);
  buf += dayOfMonth;
  Serial.print("/");
  buf += "/";
  Serial.print(month, DEC);
  buf += month;
  Serial.print("/");
  buf += "/";
  Serial.print(year, DEC);
  buf += year;
  Serial.print(" ");
  buf += " ";
  switch(dayOfWeek){
  case 1:
    Serial.println("Domingo");
    buf += "Domingo";
    break;
  case 2:
    Serial.println("Segunda");
    buf += "Segunda";
    break;
  case 3:
    Serial.println("Terça");
    buf += "Terça";
    break;
  case 4:
    Serial.println("Quarta");
    buf += "Quarta";
    break;
  case 5:
    Serial.println("Quinta");
    buf += "Quinta";
    break;
  case 6:
    Serial.println("Sexta");
    buf += "Sexta";
    break;
  case 7:
    Serial.println("Sabado");
    buf += "Sabado";
    break;
  } 

  for(int x=0;x<sensors;x++) {
    Serial.println(" ");
    buf += " ";

   
    Serial.print(" ");
    buf += " ";
    Serial.print(get_temperature(sensors_address[x]));
    buf += get_temperature(sensors_address[x]);

    Serial.println(" C");
    buf += " C";
  }

  return buf;
}


float get_temperature(uint8_t *address) {
  byte data[12];
  int x;
  sensor_bus.reset();
  sensor_bus.select(address);
  sensor_bus.write(0x44,1);

  sensor_bus.reset();
  sensor_bus.select(address);
  sensor_bus.write(0xBE,1);
  for(x=0;x<9;x++){
    data[x] = sensor_bus.read();
  }


  unsigned short tr = data[0];
  tr = tr + data[1]*256;

  if(tr > 0xF000){
    tr = 0 - tr;
  }


  float temperature = (float)tr*(float)0.0625 ;

  return temperature;
}



void loop()
{
  int buf[318];
  int x, x2;
  int y, y2;
  int r;


  myGLCD.clrScr();



  myGLCD.print(displayTime(), CENTER, 1) ;
  delay(1000);
}
Título: Re: Iniciante - juntar codigos
Enviado por: MRData em 17 de Janeiro de 2015, 00:16
Mas faz upload deste codigo e testa pff.

Código: [Seleccione]
#include "Wire.h"
#include <UTFT.h>
#include <OneWire.h>


extern uint8_t SmallFont[];

#define DS3231_I2C_ADDRESS 0x68
// Convert normal decimal numbers to binary coded decimal
const int sensors = 1; //number of temperature sensors on the bus
int sensors_pin = 10; //the pin where the bus its connected to arduino
uint8_t sensors_address[sensors][8]; //here will store the sensors addresses for later use

OneWire  sensor_bus(sensors_pin);

float get_temperature (uint8_t *address);


UTFT myGLCD(ITDB32S,38,39,40,41);

byte decToBcd(byte val)
{
  return( (val/10*16) + (val%10) );
}
// Convert binary coded decimal to normal decimal numbers
byte bcdToDec(byte val)
{
  return( (val/16*10) + (val%16) );
}
void setup()
{
  Wire.begin();
  Serial.begin(9600);
  setDS3231time(30,21,19,6,6,01,15);
  // set the initial time here:
  // DS3231 seconds, minutes, hours, day, date, month, year
  // setDS3231time(30,40,18,5,26,11,14);
  randomSeed(analogRead(0));


  myGLCD.InitLCD();
  myGLCD.setFont(SmallFont);

  myGLCD.setColor(255, 0, 0);
  myGLCD.fillRect(0, 0, 319, 13);
  myGLCD.setColor(64, 64, 64);
  myGLCD.setBackColor(255, 0, 0);

  int x,y,c=0;
  Serial.println("Starting to look for sensors...");
  for(x=0;x<sensors;x++){
    if(sensor_bus.search(sensors_address[x]))
      c++;
  }
  if(c > 0) {
    Serial.println("Found this sensors : ");
    for(x=0;x<sensors;x++) {
      Serial.print("\tSensor ");
      Serial.print(x+1);
      Serial.print(" at address : ");
      for(y=0;y<8;y++){
        Serial.print(sensors_address[x][y],HEX);
        Serial.print(" ");
      }
      Serial.println();
    }
  }
  else
    Serial.println("Didn't find any sensors");
}
void setDS3231time(byte second, byte minute, byte hour, byte dayOfWeek, byte
dayOfMonth, byte month, byte year)
{
  // sets time and date data to DS3231
  Wire.beginTransmission(DS3231_I2C_ADDRESS);
  Wire.write(0); // set next input to start at the seconds register
  Wire.write(decToBcd(second)); // set seconds
  Wire.write(decToBcd(minute)); // set minutes
  Wire.write(decToBcd(hour)); // set hours
  Wire.write(decToBcd(dayOfWeek)); // set day of week (1=Sunday, 7=Saturday)
  Wire.write(decToBcd(dayOfMonth)); // set date (1 to 31)
  Wire.write(decToBcd(month)); // set month
  Wire.write(decToBcd(year)); // set year (0 to 99)
  Wire.endTransmission();
}
void readDS3231time(byte *second,
byte *minute,
byte *hour,
byte *dayOfWeek,
byte *dayOfMonth,
byte *month,
byte *year)
{
  Wire.beginTransmission(DS3231_I2C_ADDRESS);
  Wire.write(0); // set DS3231 register pointer to 00h
  Wire.endTransmission();
  Wire.requestFrom(DS3231_I2C_ADDRESS, 7);
  // request seven bytes of data from DS3231 starting from register 00h
  *second = bcdToDec(Wire.read() & 0x7f);
  *minute = bcdToDec(Wire.read());
  *hour = bcdToDec(Wire.read() & 0x3f);
  *dayOfWeek = bcdToDec(Wire.read());
  *dayOfMonth = bcdToDec(Wire.read());
  *month = bcdToDec(Wire.read());
  *year = bcdToDec(Wire.read());
}

String displayTime()
{
  byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;
  String buf = "";
  // retrieve data from DS3231
  readDS3231time(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month,
  &year);
  // send it to the serial monitor
  Serial.print(hour, DEC);
  buf += hour;
  // convert the byte variable to a decimal number when displayed
  Serial.print(" :");
  buf += ":";
  if (minute<10)
  {
    Serial.print("0");
    buf += "0";
  }
  Serial.print(minute, DEC);
  buf += minute;
  Serial.print(":");
  buf += ":";
  if (second<10)
  {
    Serial.print("0");
    buf += "0";
    buf += "0";
  }
  Serial.print(second, DEC);
  buf += second;
  Serial.print(" ");
  buf += " ";
  Serial.print(dayOfMonth, DEC);
  buf += dayOfMonth;
  Serial.print("/");
  buf += "/";
  Serial.print(month, DEC);
  buf += month;
  Serial.print("/");
  buf += "/";
  Serial.print(year, DEC);
  buf += year;
  Serial.print(" ");
  buf += " ";
  switch(dayOfWeek){
  case 1:
    Serial.println("Domingo");
    buf += "Domingo";
    break;
  case 2:
    Serial.println("Segunda");
    buf += "Segunda";
    break;
  case 3:
    Serial.println("Terça");
    buf += "Terça";
    break;
  case 4:
    Serial.println("Quarta");
    buf += "Quarta";
    break;
  case 5:
    Serial.println("Quinta");
    buf += "Quinta";
    break;
  case 6:
    Serial.println("Sexta");
    buf += "Sexta";
    break;
  case 7:
    Serial.println("Sabado");
    buf += "Sabado";
    break;
  } 

  for(int x=0;x<sensors;x++) {
    Serial.println(" ");
    buf += " ";

   
    Serial.print(" ");
    buf += " ";
    Serial.print(get_temperature(sensors_address[x]));
    buf += get_temperature(sensors_address[x]);

    Serial.println(" C");
    buf += " C";
  }

  return buf;
}


float get_temperature(uint8_t *address) {
  byte data[12];
  int x;
  sensor_bus.reset();
  sensor_bus.select(address);
  sensor_bus.write(0x44,1);

  sensor_bus.reset();
  sensor_bus.select(address);
  sensor_bus.write(0xBE,1);
  for(x=0;x<9;x++){
    data[x] = sensor_bus.read();
  }


  unsigned short tr = data[0];
  tr = tr + data[1]*256;

  if(tr > 0xF000){
    tr = 0 - tr;
  }


  float temperature = (float)tr*(float)0.0625 ;

  return temperature;
}



void loop()
{
  int buf[318];
  int x, x2;
  int y, y2;
  int r;


  myGLCD.clrScr();



  myGLCD.print(displayTime(), CENTER, 1) ;
  delay(1000);
}
Título: Re: Iniciante - juntar codigos
Enviado por: MRData em 17 de Janeiro de 2015, 00:17
MRData, funciona, exibe a infomação no tft, mas pisca. vê como esta no video

Ja tinha visto, fiz uma alteração neste ultimo
Título: Re: Iniciante - juntar codigos
Enviado por: MRData em 17 de Janeiro de 2015, 00:20
Se não der, vou-te pedir só para testar mais uma coisa e desisto  :-\
Título: Re: Iniciante - juntar codigos
Enviado por: StarRider em 17 de Janeiro de 2015, 00:24
Esse piscar é "quase normal" ... não podes esperar muito desempenho, tendo em conta os 16Mhz e
o GRANDE overhead das libs que estás a usar.

Abraços,
PA
Título: Re: Iniciante - juntar codigos
Enviado por: MRData em 17 de Janeiro de 2015, 00:26
Código: [Seleccione]
Não, o problema é mesmo esse, nos tipos compostos o C devolve um ponteiro, neste caso um
ponteiro para "nada" pois a tal string já não existe.

StarRider
Já agora explica-me uma coisa, porque é que na referencia do arduino dizem para fazer com returntype?

http://playground.arduino.cc/Code/Function (http://playground.arduino.cc/Code/Function)
http://arduino.cc/en/Reference/FunctionDeclaration (http://arduino.cc/en/Reference/FunctionDeclaration)
Título: Re: Iniciante - juntar codigos
Enviado por: MRData em 17 de Janeiro de 2015, 00:28
Essa era a minha ultima tentativa.
Como não sei como o ecra funciona, nao sabia se era necessario fazer o clear sempre.

O que te estava a fazer piscar era o clear no loop, e estares sempre a escolher os parametros do ecra no loop tambem.

Se reparares coloquei-os no setup.

Código: [Seleccione]
  myGLCD.setColor(255, 0, 0);
  myGLCD.fillRect(0, 0, 319, 13);
  myGLCD.setColor(64, 64, 64);
  myGLCD.setBackColor(255, 0, 0);

Este funcionou, mas tive de retirar isto " myGLCD.clrScr();" isto deve causar problemas ao apresentar botões não? Tipo não limpa a imagem...
Título: Re: Iniciante - juntar codigos
Enviado por: StarRider em 17 de Janeiro de 2015, 00:49
Código: [Seleccione]
Não, o problema é mesmo esse, nos tipos compostos o C devolve um ponteiro, neste caso um
ponteiro para "nada" pois a tal string já não existe.

StarRider
Já agora explica-me uma coisa, porque é que na referencia do arduino dizem para fazer com returntype?

http://playground.arduino.cc/Code/Function (http://playground.arduino.cc/Code/Function)
http://arduino.cc/en/Reference/FunctionDeclaration (http://arduino.cc/en/Reference/FunctionDeclaration)

Boas,

Resumidamente, existe dois "types" básicos de dados: escalares e compostos.
Os escalares são os "tipos base" char, int, double, float, double double, enum e claro os ponteiros que
não são mais do que um int32 (ou int16).
Os compostos são todos os outros que são constituídos por vários escalares, struc, union, class,
namespace, interface, etc.

Em todas as linguagem em todos os sistemas uma função somente pode retornar um escalar, pois como
deves compreender esse tipo da dado deve poder caber num registo ou ser endereçado por um ponteiro que
possa caber num registo (ou conjunto de 2 no caso de far pointer em sistemas de 8 e 16 bits).

Quando uma função retorna uma class, uma estructura, etc , está a retornar um ponteiro para esse
datatype composto. Apesar do "returntype" poder ser uma classe o avr-gcc retorna um ponteiro para o
membro dessa classe ... no fundo uma variável de uma classe nada mais é do que um ponteiro para
um membro da classe.

PS: Existem em algumas linguagens a possibilidade de efectuar o retorno de um composto, no C# por
exemplo, isto é feito puxando todos os elementos que constituem o composto para o stack pela função
chamada sendo estes elementos depois retirados do stack pela função que chamou (isto é transparente
para o programador claro) mas isto não acontece no arduino ... que coitado tem um stack minúsculo.

Quando defines uma variável dentro de uma função, ou mesmo dentro de um bloco {}, essa variável
sai de scope assim que a execução sai fora do bloco ou função, e sendo um membro de uma classe, o
"arduino" gera codigo para chamar automaticamente o destructor para esse membro.
Podes fazer um teste muito simples, crias uma classe e implementas um destructor que nada mais é do
que uma função com um "til" e o nome da classe, e nesse destructor metes um print para enviar uma
mensagem para a porta serie. Depois crias uma var dessa classe dentro de uma função e vais ver que
quando o programa sair dessa função o tal print vai ser executado.

Abraços,
PA

Título: Re: Iniciante - juntar codigos
Enviado por: MRData em 17 de Janeiro de 2015, 01:19
Ok, já entedi. Obrigado pela explicação.

Abraço
Título: Re: Iniciante - juntar codigos
Enviado por: senso em 17 de Janeiro de 2015, 13:16
Os ds18b20 no modo de 12 bits(ou lá quanto é a resolução máxima) demora 750ms a fazer uma conversão, eu quando os uso dou o comando para ele fazer a conversão e continuo o código e só depois de ele dar a flag de conversão concluida é que o leio, se não são 750ms á espera sem fazer nada.
Título: Re: Iniciante - juntar codigos
Enviado por: senso em 17 de Janeiro de 2015, 13:18
Outra coisa, estás a usar SPI nativo ou é pinos á sorte e tem de fazer o spi em software?
Título: Re: Iniciante - juntar codigos
Enviado por: artur36 em 17 de Janeiro de 2015, 23:12
Fazes um digitalwrite ao rele no setup, o Arduino ao arrancar corre a função de setup e liga a bomba logo.
Título: Re: Iniciante - juntar codigos
Enviado por: Kristey em 18 de Janeiro de 2015, 15:59
Porque não fazes um código simples para faZer essa escrita depois unes tudo? Mas código feito por ti... Procuras as funções que precisas na documentação da biblioteca e vais implementando. Se tiveres dúvidas em relação a alguma função perguntas.
Aprendes mais, das menos trabalho e é mais simples para quem te quer ajudar.
Eu estou a faZer um projecto grande também. E não estou a fazer tudo de uma vez. Uma coisa de cada vez testada à parte e depois sim junto...
Se fores tu a fazer de tais os pequenos códigos depois vais saber juntar porque sabes exactamente o que precisas.
Título: Re: Iniciante - juntar codigos
Enviado por: Kristey em 18 de Janeiro de 2015, 22:44
Podes copiar mas pelo que eu vi no tópico, deves estar a juntar mal as coisas, ou seja, até mesmo a estrutura do código em si estas com dificuldades de interpretar.
Tinha um professor que dizia, o vosso melhor amigo contra os erros não é o compilador, é a folha e o lápis ao lado do rato.
É o homem tinha razão. Tenta fazer um desenho de todo o processo. Um desenho sequencial de todas as funções. Eu por exemplo comecei a fazer algumas coisas em LCD há pouco tempo e estava com um erro estupido. E se tivesse feito o desenho tinha poupado alguns minutos de pesquisa.

Neste momento não posso ajudar mais porque eu venho ao fórum pelo telemóvel e isto não dá jeito nenhum.
Título: Re: Iniciante - juntar codigos
Enviado por: MRData em 19 de Janeiro de 2015, 01:00
Boas,

Parece teres isto trocado
  //botao 2   
            if (((y>=90) && (y<=130)) && ((x>=150) && (x<=120)))

Devias ter  :
  //botao 2   
            if (((y>=90) && (y<=130)) && ((x>=120) && (x<=150)))

O X nao pode ser maior que 150 e menor que 120 ;)
Título: Re: Iniciante - juntar codigos
Enviado por: MRData em 19 de Janeiro de 2015, 18:46
Boas,

Ve se funciona o codigo, antes de testares no fim do teu codigo tens as linhas abaixo, onde diz "pin" tens de colocar o pin do RELE que queres ligar as 17h00 e o mesmo pin no codigo para desligar as 01h00 (esta a vermelho o que tens de substituir)

  getTime(second, minute, hour, dayOfWeek, dayOfMonth, month, year);
  if ((hour == 17) && (minute == 00) && releState == false))
  {
    digitalWrite(pin,HIGH);
    releState = true;
  }
  if ((hour == 1) && (minute == 00) && (releState == true))
  {
    digitalWrite(pin,LOW);
    releState = false;
  }


Código: [Seleccione]
#define VT100_MODE  1
#define DS3231_I2C_ADDRESS 0x68
#include "Wire.h"
#include <UTFT.h>
#include <OneWire.h>
#include <UTouch.h>

// declaração das fontes que serão utilizadas
extern uint8_t SmallFont[];
extern uint8_t BigFont[];


// Convert normal decimal numbers to binary coded decimal
const int sensors = 1; //number of temperature sensors on the bus
int sensors_pin = 10; //the pin where the bus its connected to arduino
uint8_t sensors_address[sensors][8]; //here will store the sensors addresses for later use


const char *dayname[] = {"Domingo", "Segunda", "Terça", "Quarta", "Quinta", "Sexta", "Sabado"};
byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;

boolean releState = false;

UTFT myGLCD(ITDB32S,38,39,40,41);
UTouch  myTouch(6,5,4,3,2); // pinagem do touch

int rele2 = 12; //rele pin 12

OneWire  sensor_bus(sensors_pin);

float get_temperature (uint8_t *address);


byte decToBcd(byte val)
{
  return( (val/10*16) + (val%10) );
}
// Convert binary coded decimal to normal decimal numbers
byte bcdToDec(byte val)
{
  return( (val/16*10) + (val%16) );
}
void setup()
{
  Wire.begin();
  Serial.begin(9600);
  //setDS3231time(30,10,19,7,17,01,15);
  // set the initial time here:
  // DS3231 seconds, minutes, hours, day, date, month, year
  // setDS3231time(30,40,18,5,26,11,14);
  randomSeed(analogRead(0));

  pinMode(13, OUTPUT);            // pin relay do termostato


  myGLCD.InitLCD();
  myGLCD.clrScr(); //limpa o lcd quando carregado novo codigo
  myGLCD.setFont(SmallFont);
  myGLCD.setColor(255, 0, 0);
  myGLCD.fillRect(0, 0, 319, 13);
  myGLCD.setColor(64, 64, 64);
  myGLCD.setBackColor(255, 0, 0);
  myGLCD.setColor(255, 255, 255);
  myGLCD.setBackColor(255, 0, 0);

  pinMode(rele2, OUTPUT); //rele pinv12

  myGLCD.InitLCD();
  myGLCD.setFont(SmallFont);

  myTouch.InitTouch();
  myTouch.setPrecision(PREC_HI);

  //definições de cores e imagem inicial
  myGLCD.clrScr();              //limpar ecra
  myGLCD.setColor(0, 255, 255); //cor das letras
  myGLCD.setBackColor(0, 0, 255);  //cor de fundo
  myGLCD.print("Return Pump", 10, 60);


  //resolução ecra 320x240
  // desenho do BOTAO ligar
  myGLCD.setColor(64, 64, 128);             //cor roxa R,G,B
  myGLCD.fillRoundRect(10, 90, 40, 130);  //função fazer retangulo com cantos redondos  (ponto inicio horizontal,ponto inicio vertical, 319, 239);
  myGLCD.setColor(255, 255, 255);           //cor branco
  myGLCD.drawRoundRect(10, 90, 40, 130);  //função fazer BORDAS retangulo com cantos redondos
  myGLCD.setBackColor(64, 64, 128);
  myGLCD.print("ON", 14, 100); // myGLCD.print("palavra a escrever", eixo X, eixo Y);
  myGLCD.setBackColor(0, 0, 0);

  // FAZER O BOTAO desligar
  myGLCD.setColor(64, 64, 128);             //cor roxa R,G,B
  myGLCD.fillRoundRect(45, 90, 75, 130); //função fazer retangulo com cantos redondos  (ponto inicio horizontal,ponto inicio vertical, 319, 239);
  myGLCD.setColor(255, 255, 255);           //cor branco
  myGLCD.drawRoundRect(45, 90, 75, 130); //função fazer BORDAS retangulo com cantos redondos
  myGLCD.setBackColor(64, 64, 128);
  myGLCD.print("OFF", 50, 100); // myGLCD.print("palavra a escrever", eixo X, eixo Y);
  myGLCD.setBackColor(0, 0, 0);

  //Definir o pin 13 ON no arranque

  digitalWrite(rele2, HIGH);


  int x,y,c=0;
  Serial.println("Starting to look for sensors...");
  for(x=0;x<sensors;x++){
    if(sensor_bus.search(sensors_address[x]))
      c++;
  }
  if(c > 0) {
    Serial.println("Found this sensors : ");
    for(x=0;x<sensors;x++) {
      Serial.print("\tSensor ");
      Serial.print(x+1);
      Serial.print(" at address : ");
      for(y=0;y<8;y++){
        Serial.print(sensors_address[x][y],HEX);
        Serial.print(" ");
      }
      Serial.println();
    }
  }
  else
    Serial.println("Didn't find any sensors");
}
void setDS3231time(byte second, byte minute, byte hour, byte dayOfWeek, byte
dayOfMonth, byte month, byte year)
{

  // Relogio
  // sets time and date data to DS3231

  Wire.beginTransmission(DS3231_I2C_ADDRESS);
  Wire.write(0); // set next input to start at the seconds register
  Wire.write(decToBcd(second)); // set seconds
  Wire.write(decToBcd(minute)); // set minutes
  Wire.write(decToBcd(hour)); // set hours
  Wire.write(decToBcd(dayOfWeek)); // set day of week (1=Sunday, 7=Saturday)
  Wire.write(decToBcd(dayOfMonth)); // set date (1 to 31)
  Wire.write(decToBcd(month)); // set month
  Wire.write(decToBcd(year)); // set year (0 to 99)
  Wire.endTransmission();
}
void readDS3231time(byte *second,
byte *minute,
byte *hour,
byte *dayOfWeek,
byte *dayOfMonth,
byte *month,
byte *year)
{
  Wire.beginTransmission(DS3231_I2C_ADDRESS);
  Wire.write(0); // set DS3231 register pointer to 00h
  Wire.endTransmission();
  Wire.requestFrom(DS3231_I2C_ADDRESS, 7);
  // request seven bytes of data from DS3231 starting from register 00h
  *second = bcdToDec(Wire.read() & 0x7f);
  *minute = bcdToDec(Wire.read());
  *hour = bcdToDec(Wire.read() & 0x3f);
  *dayOfWeek = bcdToDec(Wire.read());
  *dayOfMonth = bcdToDec(Wire.read());
  *month = bcdToDec(Wire.read());
  *year = bcdToDec(Wire.read());
}

String displayTime()
{
  String buf = "";
  // retrieve data from DS3231
  readDS3231time(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month,
  &year);
  // send it to the serial monitor
  Serial.print(hour, DEC);
  buf += hour;
  // convert the byte variable to a decimal number when displayed
  Serial.print(":");
  buf += ":";
  if (minute<10)
  {
    Serial.print("0");
    buf += "0";
  }
  Serial.print(minute, DEC);
  buf += minute;
  Serial.print(":");
  buf += ":";
  if (second<10)
  {
    Serial.print("0");
    buf += "0";
    buf += "0";
  }
  Serial.print(second, DEC);
  buf += second;
  Serial.print(" ");
  buf += " ";
  Serial.print(dayOfMonth, DEC);
  buf += dayOfMonth;
  Serial.print("/");
  buf += "/";
  Serial.print(month, DEC);
  buf += month;
  Serial.print("/");
  buf += "/";
  Serial.print(year, DEC);
  buf += year;
  Serial.print(" ");
  buf += " ";
  switch(dayOfWeek){
  case 1:
    Serial.println("Domingo");
    buf += "Domingo";
    break;
  case 2:
    Serial.println("Segunda");
    buf += "Segunda";
    break;
  case 3:
    Serial.println("Terça");
    buf += "Terça";
    break;
  case 4:
    Serial.println("Quarta");
    buf += "Quarta";
    break;
  case 5:
    Serial.println("Quinta");
    buf += "Quinta";
    break;
  case 6:
    Serial.println("Sexta");
    buf += "Sexta";
    break;
  case 7:
    Serial.println("Sabado");
    buf += "Sabado";
    break;
  } 

  for(int x=0;x<sensors;x++) {
    Serial.println(" ");
    buf += " ";


    Serial.print(" ");
    buf += " ";
    Serial.print(get_temperature(sensors_address[x]));
    buf += get_temperature(sensors_address[x]);

    Serial.println("C");
    buf += "C";
  }

  return buf;
}


float get_temperature(uint8_t *address) {
  byte data[12];
  int x;
  sensor_bus.reset();
  sensor_bus.select(address);
  sensor_bus.write(0x44,1);

  sensor_bus.reset();
  sensor_bus.select(address);
  sensor_bus.write(0xBE,1);
  for(x=0;x<9;x++){
    data[x] = sensor_bus.read();
  }


  unsigned short tr = data[0];
  tr = tr + data[1]*256;

  if(tr > 0xF000){
    tr = 0 - tr;
  }


  float temperature = (float)tr*(float)0.0625 ;

  //controlo temp
  if (temperature > 20){//temperatura selecionada
    digitalWrite(13, LOW);

  }
  else
    digitalWrite(13,HIGH);


  return temperature;




}

void getTime(byte &second, byte &minute, byte &hour, byte &dayOfWeek, byte &dayOfMonth, byte &month, byte &year)
{
  readDS3231time(second, minute, hour, dayOfWeek, dayOfMonth, month, year);
}



void loop()
{



  int buf[318];
  int x, x2;
  int y, y2;
  int r;


  //chama linha com info para o tft
  myGLCD.print(displayTime(), CENTER, 1) ;

  if (myTouch.dataAvailable())
  {
    myTouch.read();
    x=myTouch.getX();
    y=myTouch.getY();

    //botao 1
    if (((y>=90) && (y<=130)) && ((x>=10) && (x<=40)))
    {       
      digitalWrite(rele2, HIGH);

      myGLCD.setColor (255, 0, 0);
      myGLCD.drawRoundRect(10, 90, 40, 130);

    }
    else {
      myGLCD.setColor (255,255, 255);
      myGLCD.drawRoundRect(10, 90, 40, 130);
    }

    //botao 2
    if (((y>=90) && (y<=130)) && ((x>=45) && (x<=75)))
    {       
      digitalWrite(rele2, LOW);

      myGLCD.setColor (255, 0, 0);
      myGLCD.drawRoundRect(45, 90, 75, 130);

    }
    else {
      myGLCD.setColor (255, 255, 255);
      myGLCD.drawRoundRect(45, 90, 75, 130);
    }

  }
  //-----------------------------------------------------------------

  getTime(second, minute, hour, dayOfWeek, dayOfMonth, month, year);
  if ((hour == 17) && (minute == 00) && releState == false))
  {
    digitalWrite(pin,HIGH);
    releState = true;
  }
  if ((hour == 1) && (minute == 00) && (releState == true))
  {
    digitalWrite(pin,LOW);
    releState = false;
  }
}
Título: Re: Iniciante - juntar codigos
Enviado por: MRData em 20 de Janeiro de 2015, 01:03
Tenta com este, tens de fazer a mesma alteração do PIN do rele.

Código: [Seleccione]
#define VT100_MODE  1
#define DS3231_I2C_ADDRESS 0x68
#include "Wire.h"
#include <UTFT.h>
#include <OneWire.h>
#include <UTouch.h>

// declaração das fontes que serão utilizadas
extern uint8_t SmallFont[];
extern uint8_t BigFont[];


// Convert normal decimal numbers to binary coded decimal
const int sensors = 1; //number of temperature sensors on the bus
int sensors_pin = 10; //the pin where the bus its connected to arduino
uint8_t sensors_address[sensors][8]; //here will store the sensors addresses for later use


const char *dayname[] = {"Domingo", "Segunda", "Terça", "Quarta", "Quinta", "Sexta", "Sabado"};
byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;

boolean releState = false;

UTFT myGLCD(ITDB32S,38,39,40,41);
UTouch  myTouch(6,5,4,3,2); // pinagem do touch

int rele2 = 12; //rele pin 12

OneWire  sensor_bus(sensors_pin);

float get_temperature (uint8_t *address);


byte decToBcd(byte val)
{
  return( (val/10*16) + (val%10) );
}
// Convert binary coded decimal to normal decimal numbers
byte bcdToDec(byte val)
{
  return( (val/16*10) + (val%16) );
}
void setup()
{
  Wire.begin();
  Serial.begin(9600);
  //setDS3231time(30,10,19,7,17,01,15);
  // set the initial time here:
  // DS3231 seconds, minutes, hours, day, date, month, year
  // setDS3231time(30,40,18,5,26,11,14);
  randomSeed(analogRead(0));

  pinMode(13, OUTPUT);            // pin relay do termostato


  myGLCD.InitLCD();
  myGLCD.clrScr(); //limpa o lcd quando carregado novo codigo
  myGLCD.setFont(SmallFont);
  myGLCD.setColor(255, 0, 0);
  myGLCD.fillRect(0, 0, 319, 13);
  myGLCD.setColor(64, 64, 64);
  myGLCD.setBackColor(255, 0, 0);
  myGLCD.setColor(255, 255, 255);
  myGLCD.setBackColor(255, 0, 0);

  pinMode(rele2, OUTPUT); //rele pinv12

  myGLCD.InitLCD();
  myGLCD.setFont(SmallFont);

  myTouch.InitTouch();
  myTouch.setPrecision(PREC_HI);

  //definições de cores e imagem inicial
  myGLCD.clrScr();              //limpar ecra
  myGLCD.setColor(0, 255, 255); //cor das letras
  myGLCD.setBackColor(0, 0, 255);  //cor de fundo
  myGLCD.print("Return Pump", 10, 60);


  //resolução ecra 320x240
  // desenho do BOTAO ligar
  myGLCD.setColor(64, 64, 128);             //cor roxa R,G,B
  myGLCD.fillRoundRect(10, 90, 40, 130);  //função fazer retangulo com cantos redondos  (ponto inicio horizontal,ponto inicio vertical, 319, 239);
  myGLCD.setColor(255, 255, 255);           //cor branco
  myGLCD.drawRoundRect(10, 90, 40, 130);  //função fazer BORDAS retangulo com cantos redondos
  myGLCD.setBackColor(64, 64, 128);
  myGLCD.print("ON", 14, 100); // myGLCD.print("palavra a escrever", eixo X, eixo Y);
  myGLCD.setBackColor(0, 0, 0);

  // FAZER O BOTAO desligar
  myGLCD.setColor(64, 64, 128);             //cor roxa R,G,B
  myGLCD.fillRoundRect(45, 90, 75, 130); //função fazer retangulo com cantos redondos  (ponto inicio horizontal,ponto inicio vertical, 319, 239);
  myGLCD.setColor(255, 255, 255);           //cor branco
  myGLCD.drawRoundRect(45, 90, 75, 130); //função fazer BORDAS retangulo com cantos redondos
  myGLCD.setBackColor(64, 64, 128);
  myGLCD.print("OFF", 50, 100); // myGLCD.print("palavra a escrever", eixo X, eixo Y);
  myGLCD.setBackColor(0, 0, 0);

  //Definir o pin 13 ON no arranque

  digitalWrite(rele2, HIGH);


  int x,y,c=0;
  Serial.println("Starting to look for sensors...");
  for(x=0;x<sensors;x++){
    if(sensor_bus.search(sensors_address[x]))
      c++;
  }
  if(c > 0) {
    Serial.println("Found this sensors : ");
    for(x=0;x<sensors;x++) {
      Serial.print("\tSensor ");
      Serial.print(x+1);
      Serial.print(" at address : ");
      for(y=0;y<8;y++){
        Serial.print(sensors_address[x][y],HEX);
        Serial.print(" ");
      }
      Serial.println();
    }
  }
  else
    Serial.println("Didn't find any sensors");
}
void setDS3231time(byte second, byte minute, byte hour, byte dayOfWeek, byte
dayOfMonth, byte month, byte year)
{

  // Relogio
  // sets time and date data to DS3231

  Wire.beginTransmission(DS3231_I2C_ADDRESS);
  Wire.write(0); // set next input to start at the seconds register
  Wire.write(decToBcd(second)); // set seconds
  Wire.write(decToBcd(minute)); // set minutes
  Wire.write(decToBcd(hour)); // set hours
  Wire.write(decToBcd(dayOfWeek)); // set day of week (1=Sunday, 7=Saturday)
  Wire.write(decToBcd(dayOfMonth)); // set date (1 to 31)
  Wire.write(decToBcd(month)); // set month
  Wire.write(decToBcd(year)); // set year (0 to 99)
  Wire.endTransmission();
}
void readDS3231time(byte *second,
byte *minute,
byte *hour,
byte *dayOfWeek,
byte *dayOfMonth,
byte *month,
byte *year)
{
  Wire.beginTransmission(DS3231_I2C_ADDRESS);
  Wire.write(0); // set DS3231 register pointer to 00h
  Wire.endTransmission();
  Wire.requestFrom(DS3231_I2C_ADDRESS, 7);
  // request seven bytes of data from DS3231 starting from register 00h
  *second = bcdToDec(Wire.read() & 0x7f);
  *minute = bcdToDec(Wire.read());
  *hour = bcdToDec(Wire.read() & 0x3f);
  *dayOfWeek = bcdToDec(Wire.read());
  *dayOfMonth = bcdToDec(Wire.read());
  *month = bcdToDec(Wire.read());
  *year = bcdToDec(Wire.read());
}

String displayTime()
{
  String buf = "";
  // retrieve data from DS3231
  readDS3231time(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month,
  &year);
  // send it to the serial monitor
  Serial.print(hour, DEC);
  buf += hour;
  // convert the byte variable to a decimal number when displayed
  Serial.print(":");
  buf += ":";
  if (minute<10)
  {
    Serial.print("0");
    buf += "0";
  }
  Serial.print(minute, DEC);
  buf += minute;
  Serial.print(":");
  buf += ":";
  if (second<10)
  {
    Serial.print("0");
    buf += "0";
    buf += "0";
  }
  Serial.print(second, DEC);
  buf += second;
  Serial.print(" ");
  buf += " ";
  Serial.print(dayOfMonth, DEC);
  buf += dayOfMonth;
  Serial.print("/");
  buf += "/";
  Serial.print(month, DEC);
  buf += month;
  Serial.print("/");
  buf += "/";
  Serial.print(year, DEC);
  buf += year;
  Serial.print(" ");
  buf += " ";
  switch(dayOfWeek){
  case 1:
    Serial.println("Domingo");
    buf += "Domingo";
    break;
  case 2:
    Serial.println("Segunda");
    buf += "Segunda";
    break;
  case 3:
    Serial.println("Terça");
    buf += "Terça";
    break;
  case 4:
    Serial.println("Quarta");
    buf += "Quarta";
    break;
  case 5:
    Serial.println("Quinta");
    buf += "Quinta";
    break;
  case 6:
    Serial.println("Sexta");
    buf += "Sexta";
    break;
  case 7:
    Serial.println("Sabado");
    buf += "Sabado";
    break;
  } 

  for(int x=0;x<sensors;x++) {
    Serial.println(" ");
    buf += " ";


    Serial.print(" ");
    buf += " ";
    Serial.print(get_temperature(sensors_address[x]));
    buf += get_temperature(sensors_address[x]);

    Serial.println("C");
    buf += "C";
  }

  return buf;
}


float get_temperature(uint8_t *address) {
  byte data[12];
  int x;
  sensor_bus.reset();
  sensor_bus.select(address);
  sensor_bus.write(0x44,1);

  sensor_bus.reset();
  sensor_bus.select(address);
  sensor_bus.write(0xBE,1);
  for(x=0;x<9;x++){
    data[x] = sensor_bus.read();
  }


  unsigned short tr = data[0];
  tr = tr + data[1]*256;

  if(tr > 0xF000){
    tr = 0 - tr;
  }


  float temperature = (float)tr*(float)0.0625 ;

  //controlo temp
  if (temperature > 20){//temperatura selecionada
    digitalWrite(13, LOW);

  }
  else
    digitalWrite(13,HIGH);


  return temperature;




}

void getTime()
{
  readDS3231time(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month,&year);
}



void loop()
{



  int buf[318];
  int x, x2;
  int y, y2;
  int r;


  //chama linha com info para o tft
  myGLCD.print(displayTime(), CENTER, 1) ;

  if (myTouch.dataAvailable())
  {
    myTouch.read();
    x=myTouch.getX();
    y=myTouch.getY();

    //botao 1
    if (((y>=90) && (y<=130)) && ((x>=10) && (x<=40)))
    {       
      digitalWrite(rele2, HIGH);

      myGLCD.setColor (255, 0, 0);
      myGLCD.drawRoundRect(10, 90, 40, 130);

    }
    else {
      myGLCD.setColor (255,255, 255);
      myGLCD.drawRoundRect(10, 90, 40, 130);
    }

    //botao 2
    if (((y>=90) && (y<=130)) && ((x>=45) && (x<=75)))
    {       
      digitalWrite(rele2, LOW);

      myGLCD.setColor (255, 0, 0);
      myGLCD.drawRoundRect(45, 90, 75, 130);

    }
    else {
      myGLCD.setColor (255, 255, 255);
      myGLCD.drawRoundRect(45, 90, 75, 130);
    }

  }
  //-----------------------------------------------------------------

  getTime();
  if ((hour == 17) && (minute == 00) && releState == false))
  {
    digitalWrite(pin,HIGH);
    releState = true;
  }
  if ((hour == 1) && (minute == 00) && (releState == true))
  {
    digitalWrite(pin,LOW);
    releState = false;
  }
}
Título: Re: Iniciante - juntar codigos
Enviado por: jm_araujo em 20 de Janeiro de 2015, 10:50
 ::)
É só contar os parênteses....
Título: Re: Iniciante - juntar codigos
Enviado por: MRData em 20 de Janeiro de 2015, 14:37
Sim é isso
Título: Re: Iniciante - juntar codigos
Enviado por: senso em 23 de Janeiro de 2015, 20:49
Pesquisa por arduino menu system, maior parte será para lcd's 16x2 e afins.
Título: Re: Iniciante - juntar codigos
Enviado por: senso em 23 de Janeiro de 2015, 21:22
O conceito é o mesmo, é fazer uma máquina de estados, ideia muito por alto.
Estado 1 ( o ecra principal).
>Sub menu 1
>Sub menu 2
>Sub menu 3

SM = Sub Menu

Se clica em SM 1 usas um if e metes o texto relevante a esse SM, e por ai adiante, quando estás dentro do SM fazes os prints respectivos de cada sub menu, já tens ai o código base para saber se clicaste num botão, agarras nesse if que está ai anteriormente e crias uma função para verificar se uma zona(botão foi clicada).
Título: Re: Iniciante - juntar codigos
Enviado por: StarRider em 25 de Janeiro de 2015, 15:38
Boas,

Para fazer o menu tive de começar de novo. Tenho um novo sketch com o menu e relógio, falta juntar o código para o sensor de temperatura. Já tentei juntar mas fica num constante loop.

Alguém pode dar uma vista de olhos nos códigos em anexo ?

Agradeço desde já o tempo despendido.

Esse source já vai nas 700 linhas de código (sem contar includes e libs), e cada vez que "enxertas"  mais
alguma funcionalidade copiada da net vens pedir que alguém meta o mesmo a funcionar, depois de um
tópico com 5 paginas de ajuda dá para perceber que ainda não aprendeste nada e que nem sequer tentas
resolver os problemas ... se calhar está na altura de parares e estudar e ler um pouco sobre programação
e arduino antes de avançar mais.

Uma coisa é ajudar numa ou outra situação, outra coisa é estares à espera que seja a boa vontade dos outros
a fazer o teu programa TODO, se calhar não estás à altura de tal projecto e devias optar por algo mais
simples ... pensa nisso.

Abraços,
PA
Título: Re: Iniciante - juntar codigos
Enviado por: KammutierSpule em 25 de Janeiro de 2015, 16:52
barrma, varias coisas:

Se objectivos deste tipo de forums fosse partilhar conhecimentos, seria bom entao partilhar tambem os teus conhecimentos. E desde que aqui chegaste, o teu objectivo tem sido apenas "safar-te o teu projecto".
Mesmo que seja o caso em ca vir so pedir ajuda, quem ajuda, nao 'e em troca de nada, e' porque acredita em alguma coisa. Há pessoas que podem acreditar na satisfação das outras pessoas que ajuda, outras acreditam que ao ajudar estão a ajudar a outra pessoa a evoluir e a crescer no conhecimento. algo para o futuro da pessoa.. e que sao aquela motivação extra para crescer as suas capacidades e nao apenas "safar uma necessidade momentânea".

O StarRider ja te respondeu e esclareceu varias duvidas neste post e que tu agradeces-te. Se calhar ele esperava ver algum retorno nessa ajuda que as pessoas aqui tem dado e do tempo da vida delas que estao a gastar num projecto que nao e' o delas.


Relativamente ao teu projecto:
"é muito complexo" vs "nunca seria em tempo útil" vs "para uso pessoal" vs "o orçamento que me deram foi absurdo"
Se calhar agora começas a ver que nao sera' tao absurdo assim o orçamento pedido.
Existe um esquema (em anexo) que ilustra bem esta situação, agora so tens de saber em que ponto do esquema estas.

Neste teu projecto, a melhor pessoa para resolver os problemas és tu. Torna-se realmente absurdo que chegue a uma situação que por cada iteração (problema que tenhas) venhas aqui colocar o projecto todo e pedir as pessoas que deixem de fazer os seus projectos e dedicar-se a olhar para o teu.

Força ai e muito trabalho!
Título: Re: Iniciante - juntar codigos
Enviado por: senso em 25 de Janeiro de 2015, 16:59
É impressão minha ou falta aqui pelo menos um post no tópico?