/* SevSeg Counter Example
Copyright 2017 Dean Reading
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
This example demonstrates a very simple use of the SevSeg library with a 4
digit display. It displays a counter that counts up, showing deci-seconds.
*/
/*int BrocheA0 = A0; // déclaration de l'entrée du potentiomètre
uint16_t val_pot;
#include "SevSeg.h"
SevSeg sevseg; //Instantiate a seven segment controller object
void setup() {
Serial.begin(115200);
pinMode(BrocheA0,INPUT_PULLUP);
val_pot = analogRead(BrocheA0);
byte numDigits = 4;
byte digitPins[] = {2, 3, 4, 5};
byte segmentPins[] = {6, 7, 8, 9, 10, 11, 12, 13};
bool resistorsOnSegments = false; // 'false' means resistors are on digit pins
byte hardwareConfig = COMMON_ANODE; // See README.md for options
bool updateWithDelays = false; // Default 'false' is Recommended
bool leadingZeros = false; // Use 'true' if you'd like to keep the leading zeros
bool disableDecPoint = false; // Use 'true' if your decimal point doesn't exist or isn't connected
sevseg.begin(hardwareConfig, numDigits, digitPins, segmentPins, resistorsOnSegments,
updateWithDelays, leadingZeros, disableDecPoint);
sevseg.setBrightness(90);
}
void loop() {
piloter_afficheur ();
}
// piloter l'afficheur à partir du potentiomètre.
void piloter_afficheur ()
{
static unsigned long timer = millis();
static int deciSeconds = 0;
val_pot = analogRead(BrocheA0); // récupération de la valeur du potentiomètre
sevseg.setNumber(val_pot, 1); // écrire la
sevseg.refreshDisplay();
}*/
// Utilisation du programme avec CATHODE COMMUNE
byte numDigits = 4;
byte digitPins[] = {2, 3, 4, 5};
byte numSegments = 8;
byte segmentPins[] = {6, 7, 8, 9, 10, 11, 12, 13};
byte tabDeco7seg[]={0x3f,0x06,0x5b,0x4F,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
int BrocheA0 = A0 ;
byte digits[4] = {25, 8, 15, 10};
byte dots = 1;
//////////////////////////////////////////
void setDigit(unsigned char ndigitActif, unsigned char nSegsActif)
{
/*
désactiver tous les digits avant de changer les segments
piloter les segments en utilisant les valeurs des bits de nSegsActif
activer le bon digit
*/
for ( int i = 0 ; i < numDigits ; i++)
{
digitalWrite(digitPins[i],HIGH);
}
for ( int i = 0 ; i < numSegments ; i++)
{
digitalWrite(segmentPins[i],(nSegsActif>>i)&1);
}
digitalWrite(digitPins[ndigitActif],LOW);
}
void digit_sans_dp()
{
for ( int i =0 ; i < 4 ; i++)
{
uint8_t value = digits[i] ;
if ( value <= 15 )
{
setDigit(i,tabDeco7seg[value]);
}
}
}
void digit_avec_dp()
{
for ( int i =0 ; i < 4 ; i++)
{
uint8_t value = digits[i] ;
if ( value <= 15 )
{
setDigit(i,tabDeco7seg[value]);
if ( dots == i+1)
{
setDigit(i,tabDeco7seg[value]|0x80);
}
}
}
}
void setNumber(unsigned int val)
{
for ( int i = 0 ; i < 4 ; i++)
{
digits[3-i] = (val%10);
val = val/10;
}
}
void tache1(){
setNumber(7895);
delay(25);
}
///////////////////////////
void tache2(){
dots = 3;
digit_avec_dp();
}
// code d'affichage de quelques segments
/*
digitalWrite(segmentPins[0],HIGH); // activation du segments à l'état HAUT
digitalWrite(segmentPins[4],HIGH); // activation du segments à l'état HAUT
digitalWrite(digitPins[0],LOW); // Activation du digit à l'état BAS
*/
//////////////////////////////////////////
void setup() {
Serial.begin(115200);
Serial.println("debut");
for ( int i = 0 ; i <= (numDigits-1) ; i++)
{
pinMode(digitPins[i],OUTPUT);
digitalWrite(digitPins[i],HIGH);
}
for ( int i = 0 ; i <= (numSegments-1) ; i++)
{
pinMode(segmentPins[i],OUTPUT);
digitalWrite(segmentPins[i],LOW);
}
}
void loop()
{
unsigned int periodiciteTache1=100; //100ms entre chaque incrémentation de la valeur à afficher
unsigned int periodiciteTache2=4; //4ms pour l'affichage de chaque digit
static unsigned long timerTache1 = millis();
static unsigned long timerTache2 = millis();
if (millis() - timerTache1 >= periodiciteTache1) {
timerTache1 += periodiciteTache1;
tache1();
}
if (millis() - timerTache2 >= periodiciteTache2) {
timerTache2 += periodiciteTache2;
tache2();
}
}
//setDigit(2,tabDeco7seg[15]);
/// END ///