Je bloque sur une bêtise...
Actuellement mon programme fait les choses suivante :
Création des variables et objets
|setup(){
Initialisation de celles ci
|}loop(){
Récupération de l'heure et Température
|
Préparation de l'affichage via le buffer de la matrice
|
Affichage sur la matrice.
|}
Mon problème est que la sonde de température peux mètre plus d'1 seconde avant donner la valeur de la sonde du coup sa bloque le programme et l'affichage en même temps.
Je n'arrive pas à trouver l'astuce pour faire du multi tache... pour l'instant je fais du basique mais quand il me faudra affiché un Texte déroulant ou une image animé (météo de la pluie) sa me bloquera tout le reste...
HELP.
#include <WProgram.h>
#include <Wire.h>
#include <DS1307.h>
#include <ht1632c.h>
// Pour la température
#include <OneWire.h>
#include <DallasTemperature.h>
// Data wire is plugged into port 2 on the Arduino
#define ONE_WIRE_BUS 31
// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
OneWire oneWire(ONE_WIRE_BUS);
// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);
// -----------------------
// Déclaration des Objets
ht1632c ledMatrix = ht1632c(PORTB, 0, 2, 1, 3, GEOM_32x16, 2);
DS1307 RTC=DS1307();
const int bp2 = 2; // the number of the pushbutton pin
const int bp0 = 0;
const int ledPin = 13; // the number of the LED pin
int buttonState = 1;
int buttonState0 = 1;
int pwm=0;
int sec=0;
int secdiff=0;
void setup() {
Serial.begin(9600);
// Initialisation de la Temp.
sensors.begin();
// initialisation de l'affichage
ledMatrix.clear();
ledMatrix.pwm(5); // Valeurs de 0-15
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(bp2, INPUT);
digitalWrite(bp2, HIGH); // résistance de rappel
pinMode(bp0, INPUT);
digitalWrite(bp0, HIGH); // résistance de rappel
}
void loop() {
// Lecture de l'état du bouton:
buttonState = digitalRead(bp2);
buttonState0 = digitalRead(bp0);
// Actualisation de la connexion a la sonde
sensors.requestTemperatures();
int temp = sensors.getTempCByIndex(0);
//Serial.println(temp);
if (!buttonState0){
pwm++;
//delay(1000);
if(pwm>15){
pwm=0;
}
}
// Si le bouton est appuyé
if (buttonState) {
// turn LED off:
digitalWrite(ledPin, LOW);
secdiff = sec;
int hours = RTC.get(DS1307_HR,true);
int mins = RTC.get(DS1307_MIN,false);
sec = RTC.get(DS1307_SEC,false);
/*
Fonction clignotement ne marche pas. sa va trop vite
if(sec!=secdiff){
ledMatrix.plot(15,1,0);
ledMatrix.plot(15,2,0);
ledMatrix.plot(16,1,0);
ledMatrix.plot(16,2,0);
ledMatrix.plot(15,4,0);
ledMatrix.plot(15,5,0);
ledMatrix.plot(16,4,0);
ledMatrix.plot(16,5,0);
}
else{
ledMatrix.plot(15,1,1);
ledMatrix.plot(15,2,1);
ledMatrix.plot(16,1,1);
ledMatrix.plot(16,2,1);
ledMatrix.plot(15,4,1);
ledMatrix.plot(15,5,1);
ledMatrix.plot(16,4,1);
ledMatrix.plot(16,5,1);
}
*/
char buffer[3];
itoa(hours,buffer,10);
// fix - as otherwise if num has leading zero, e.g. "03" hours, itoa coverts this to chars with space "3 ".
if (hours < 10) {
buffer[1] = buffer[0];
buffer[0] = '0';
}
ledMatrix.putchar(3, 0, buffer[0], RED);
ledMatrix.putchar(9, 0, buffer[1], RED);
itoa(mins,buffer,10);
// fix - as otherwise if num has leading zero, e.g. "03" hours, itoa coverts this to chars with space "3 ".
if (mins < 10) {
buffer[1] = buffer[0];
buffer[0] = '0';
}
ledMatrix.putchar(18, 0, buffer[0], RED);
ledMatrix.putchar(24, 0, buffer[1], RED);
ledMatrix.plot(15,1,1);
ledMatrix.plot(15,2,1);
ledMatrix.plot(16,1,1);
ledMatrix.plot(16,2,1);
ledMatrix.plot(15,4,1);
ledMatrix.plot(15,5,1);
ledMatrix.plot(16,4,1);
ledMatrix.plot(16,5,1);
itoa(sec,buffer,10);
// fix - as otherwise if num has leading zero, e.g. "03" hours, itoa coverts this to chars with space "3 ".
if (sec < 10) {
buffer[1] = buffer[0];
buffer[0] = '0';
}
ledMatrix.putchar(34, 0, buffer[0], RED);
ledMatrix.putchar(40, 0, buffer[1], RED);
ledMatrix.putchar(47, 0, 's',1);
ledMatrix.putchar(53, 0, 'e',1);
ledMatrix.putchar(59, 0, 'c',1);
// Affichage Température
itoa(temp,buffer,10);
if (temp < 10) {
buffer[1] = buffer[0];
buffer[0] = '0';
}
ledMatrix.putchar(45, 8, buffer[0], 3);
ledMatrix.putchar(51, 8, buffer[1], 3);
ledMatrix.putchar(56, 8, 'C', 3);
}
else {
// turn LED on:
digitalWrite(ledPin, HIGH);
ledMatrix.plot(0,0,2);
ledMatrix.plot(32,0,1);
}
ledMatrix.pwm(pwm);
ledMatrix.sendframe(); // Actualisation de la matrice LED
}