Je débute sur arduino, je cherche à faire un petit thermomètre digital pour afficher la température extérieure.
Pour l'instant je suis sur un arduino UNO avant de passer sur un plus petit une fois que ça marche.
J'ai réussi à faire marcher le 4*7 segments avec ce code :
int digit1 = 13; //PWM Display pin 1
int digit2 = 12; //PWM Display pin 2
int digit3 = 11; //PWM Display pin 6
int digit4 = 10; //PWM Display pin 8
int p = 9;
int segA = 2; //Display pin 14
int segB = 3; //Display pin 16
int segC = 4; //Display pin 13
int segD = 6; //Display pin 3
int segE = 5; //Display pin 5
int segF = 7; //Display pin 11
int segG = 8; //Display pin 15
void setup() {
pinMode(segA, OUTPUT);
pinMode(segB, OUTPUT);
pinMode(segC, OUTPUT);
pinMode(segD, OUTPUT);
pinMode(segE, OUTPUT);
pinMode(segF, OUTPUT);
pinMode(segG, OUTPUT);
pinMode(digit1, OUTPUT);
pinMode(digit2, OUTPUT);
pinMode(digit3, OUTPUT);
pinMode(digit4, OUTPUT);
pinMode(p, OUTPUT);
pinMode(13, OUTPUT);
}
void loop() {
//long startTime = millis();
displayNumber(millis()/1000);
//while( (millis() - startTime) < 2000) {
//displayNumber(1217);
//}
//delay(1000);
}
//Given a number, we display 10:22
//After running through the 4 numbers, the display is left turned off
//Display brightness
//Each digit is on for a certain amount of microseconds
//Then it is off until we have reached a total of 20ms for the function call
//Let's assume each digit is on for 1000us
//Each digit is on for 1ms, there are 4 digits, so the display is off for 16ms.
//That's a ratio of 1ms to 16ms or 6.25% on time (PWM).
//Let's define a variable called brightness that varies from:
//5000 blindingly bright (15.7mA current draw per digit)
//2000 shockingly bright (11.4mA current draw per digit)
//1000 pretty bright (5.9mA)
//500 normal (3mA)
//200 dim but readable (1.4mA)
//50 dim but readable (0.56mA)
//5 dim but readable (0.31mA)
//1 dim but readable in dark (0.28mA)
void displayNumber(int toDisplay) {
#define DISPLAY_BRIGHTNESS 500
#define DIGIT_ON HIGH
#define DIGIT_OFF LOW
long beginTime = millis();
for(int digit = 4 ; digit > 0 ; digit--) {
//Turn on a digit for a short amount of time
switch(digit) {
case 1:
digitalWrite(digit1, DIGIT_ON);
break;
case 2:
digitalWrite(digit2, DIGIT_ON);
break;
case 3:
digitalWrite(digit3, DIGIT_ON);
break;
case 4:
digitalWrite(digit4, DIGIT_ON);
break;
}
//Turn on the right segments for this digit
lightNumber(toDisplay % 10);
toDisplay /= 10;
delayMicroseconds(DISPLAY_BRIGHTNESS);
//Display digit for fraction of a second (1us to 5000us, 500 is pretty good)
//Turn off all segments
lightNumber(10);
//Turn off all digits
digitalWrite(digit1, DIGIT_OFF);
digitalWrite(digit2, DIGIT_OFF);
digitalWrite(digit3, DIGIT_OFF);
digitalWrite(digit4, DIGIT_OFF);
}
while( (millis() - beginTime) < 10) ;
//Wait for 20ms to pass before we paint the display again
}
//Given a number, turns on those segments
//If number == 10, then turn off number
void lightNumber(int numberToDisplay) {
#define SEGMENT_ON LOW
#define SEGMENT_OFF HIGH
switch (numberToDisplay){
case 0:
digitalWrite(segA, SEGMENT_ON);
digitalWrite(segB, SEGMENT_ON);
digitalWrite(segC, SEGMENT_ON);
digitalWrite(segD, SEGMENT_ON);
digitalWrite(segE, SEGMENT_ON);
digitalWrite(segF, SEGMENT_ON);
digitalWrite(segG, SEGMENT_OFF);
break;
case 1:
digitalWrite(segA, SEGMENT_OFF);
digitalWrite(segB, SEGMENT_ON);
digitalWrite(segC, SEGMENT_ON);
digitalWrite(segD, SEGMENT_OFF);
digitalWrite(segE, SEGMENT_OFF);
digitalWrite(segF, SEGMENT_OFF);
digitalWrite(segG, SEGMENT_OFF);
break;
case 2:
digitalWrite(segA, SEGMENT_ON);
digitalWrite(segB, SEGMENT_ON);
digitalWrite(segC, SEGMENT_OFF);
digitalWrite(segD, SEGMENT_ON);
digitalWrite(segE, SEGMENT_ON);
digitalWrite(segF, SEGMENT_OFF);
digitalWrite(segG, SEGMENT_ON);
break;
case 3:
digitalWrite(segA, SEGMENT_ON);
digitalWrite(segB, SEGMENT_ON);
digitalWrite(segC, SEGMENT_ON);
digitalWrite(segD, SEGMENT_ON);
digitalWrite(segE, SEGMENT_OFF);
digitalWrite(segF, SEGMENT_OFF);
digitalWrite(segG, SEGMENT_ON);
break;
case 4:
digitalWrite(segA, SEGMENT_OFF);
digitalWrite(segB, SEGMENT_ON);
digitalWrite(segC, SEGMENT_ON);
digitalWrite(segD, SEGMENT_OFF);
digitalWrite(segE, SEGMENT_OFF);
digitalWrite(segF, SEGMENT_ON);
digitalWrite(segG, SEGMENT_ON);
break;
case 5:
digitalWrite(segA, SEGMENT_ON);
digitalWrite(segB, SEGMENT_OFF);
digitalWrite(segC, SEGMENT_ON);
digitalWrite(segD, SEGMENT_ON);
digitalWrite(segE, SEGMENT_OFF);
digitalWrite(segF, SEGMENT_ON);
digitalWrite(segG, SEGMENT_ON);
break;
case 6:
digitalWrite(segA, SEGMENT_ON);
digitalWrite(segB, SEGMENT_OFF);
digitalWrite(segC, SEGMENT_ON);
digitalWrite(segD, SEGMENT_ON);
digitalWrite(segE, SEGMENT_ON);
digitalWrite(segF, SEGMENT_ON);
digitalWrite(segG, SEGMENT_ON);
break;
case 7:
digitalWrite(segA, SEGMENT_ON);
digitalWrite(segB, SEGMENT_ON);
digitalWrite(segC, SEGMENT_ON);
digitalWrite(segD, SEGMENT_OFF);
digitalWrite(segE, SEGMENT_OFF);
digitalWrite(segF, SEGMENT_OFF);
digitalWrite(segG, SEGMENT_OFF);
break;
case 8:
digitalWrite(segA, SEGMENT_ON);
digitalWrite(segB, SEGMENT_ON);
digitalWrite(segC, SEGMENT_ON);
digitalWrite(segD, SEGMENT_ON);
digitalWrite(segE, SEGMENT_ON);
digitalWrite(segF, SEGMENT_ON);
digitalWrite(segG, SEGMENT_ON);
break;
case 9:
digitalWrite(segA, SEGMENT_ON);
digitalWrite(segB, SEGMENT_ON);
digitalWrite(segC, SEGMENT_ON);
digitalWrite(segD, SEGMENT_ON);
digitalWrite(segE, SEGMENT_OFF);
digitalWrite(segF, SEGMENT_ON);
digitalWrite(segG, SEGMENT_ON);
break;
case 10:
digitalWrite(segA, SEGMENT_OFF);
digitalWrite(segB, SEGMENT_OFF);
digitalWrite(segC, SEGMENT_OFF);
digitalWrite(segD, SEGMENT_OFF);
digitalWrite(segE, SEGMENT_OFF);
digitalWrite(segF, SEGMENT_OFF);
digitalWrite(segG, SEGMENT_OFF);
break;
}
}
Puis le capteur LM35
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
float voltage = analogRead(A0);
float temperature = (5.0 * voltage * 100.0)/1024.0;
Serial.print(temperature);
Serial.print("C");
Serial.println();
delay(1000);
}
Je cherche maintenant a combiner les deux pour que la température soit affichée sur le 4*7 segments mais je n'y arrive pas même en suivant des tuto en anglais plus ou moins bien fait.
Je voudrais également ajouter un capteur de luminosité qui adaptera le DISPLAY_BRIGHTNESS en fonction de la luminosité.
Avez-vous une idée de la durée de vie d'une batterie 6F22 9V avec ce système sur un arduino mini V3 ?
Tu as une fonction displayNumber qui te permet d'afficher un nombre.
Il te suffit de l'appeler avec la température comme argument.
Tu pourrais éventuellement multiplier la température par 100 pour que 34.21°C soit affiché comme le nombre 3421.
Et pour faire encore mieux, il faudrait activer le dot d'un des afficheur de façon à placer un point en plein milieux de 3421 pour que l'on puisse lire 34.21
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
float voltage = analogRead(A0);
float temperature = (5.0 * voltage * 100.0)/1024.0;
}
Pour afficher des températures négatives avec un LM35, il faut une tension négative. Tu devrais préférer le LM335 dont la sortie est de 10mV/°K soit 2,73V pour 0°C.
Je suis en première est pour mon TPE on veut afficher une masse sur un afficheur ( le même que celui que tu utilise) mais je ne sais pas comment m'y prendre car j'ai a peine les bases (et encore les bases de chez bases), je voulais savoir si c'était possible que tu partage ton programme afin que je puisse le réutiliser (en modifiant les choses nécessaires, mais ca je me débrouillerais )
si tu ne veux pas le partager je comprend bien sûr
Ducoup j'ai bidouillé le code afin de faire fonctionner le système correctement, et par je ne sais quel miracle ca fonctionne par contre je sais pas si j'ai pas mis des lignes de codes inutiles... est-ce que pourrait essayer de me dire ce qui peut etre enlever et essayer de m'expliquer comment ca marche car ce n'est pas mes prof de SI qui vont m'aider sur ça (ils sont assez faignants...)
Ca ne serait pas un tableau associatif, mais un tableau tout court.
int leds[] = {
B0000001, // segment G à droite
B0011000,
...
};
combiné avec un tableau de (pins de) segments
int segments[] = {
A1, 3, 4, 5, A2, 7, 8
};
Ca devrait donner du code beaucoup plus court.
- Edité par michelbillaud 18 février 2018 à 12:50:18
Arduino : Température sur 4 digits 7 segments
× Après avoir cliqué sur "Répondre" vous serez invité à vous connecter pour que votre message soit publié.
× Attention, ce sujet est très ancien. Le déterrer n'est pas forcément approprié. Nous te conseillons de créer un nouveau sujet pour poser ta question.
Voila, je sais qu'il manque des choses pour que le programme soit fonctionnel, mais quoi ?
Celui ci