Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // --------------------------------------------------------------------------------
- // Ecran BACK TO THE FUTURE _ Ajustement par BP
- // --------------------------------------------------------------------------------
- // Objectif : créer un affichage type "Retour vers le Futur"
- // https://media.giphy.com/media/dgEIhYAo3lZiE/giphy.gif
- // avec possibilité d'ajuster la date avec des boutons poussoirs
- // A ma disposition :
- // https://www.elecfreaks.com/learn-en/microbitOctopus/sensor/octopus_ef04056.html
- // Un mini clavier 5 boutons poussoirs DFR0075
- // https://wiki.dfrobot.com/ADKeyboard_Module__SKU__DFR0075_
- // sur Arduino Mega
- // ---------------------------------------------------------------------------------
- // --------------------------------------------
- // Instructions de montage --------------------
- // --------------------------------------------
- // Afficheur 7 digits 4 segments OCTOPUS EF04056
- // --------------------------------------------
- // D14 (CLK)
- // D15 (DIO)
- // 5V
- // GND
- //
- // --------------------------------------------
- // ADKeyboard DFR0075
- // --------------------------------------------
- // A0
- // 5V
- // Gnd
- // --------------------------------------------
- // Chargement des librairies nécessaires -------------------------------------------
- #include <Wire.h> // Librairie de câblage simplifié (??)
- #include <TM1637Display.h> // Librairie d'affichage pour afficheur LCD OCTOPUS EF04056
- // --------------------------------------------------------------------------------------------------------
- // Afficheur LCD Octopus EF04056
- // --------------------------------------------------------------------------------------------------------
- // on définit le pin de connexion sur lequel est CLK
- #define CLK 14
- // on définit le pin de connexion sur lequel est DIO
- #define DIO 15
- int annee = 1956;
- uint8_t positionPoint ;
- const uint8_t posPoint[4] = {0b10000000 , 0b01000000, 0b00100000, 0b00010000};
- int curseur = 0;
- // on initialise l'afficheur
- TM1637Display display(CLK, DIO);
- // --------------------------------------------------------------------------------------------------------
- // AD keyboard DFR0075
- // --------------------------------------------------------------------------------------------------------
- int adc_key_val[5] = {600, 650, 700, 800, 900 };
- int NUM_KEYS = 5;
- int adc_key_in;
- int key = -1;
- int oldkey = -1;
- void setup() {
- Serial.begin(9600); // on initialise et synchronise la communication entre le PC et Arduino
- display.clear();
- display.setBrightness(1);
- display.showNumberDecEx(annee, false, false, 4, 0);
- }
- void loop() {
- ajustAffichage();
- }
- // --------------------------------------------------------------------------------------------------------
- // - Fonctions -------------------------------------------------------------------------------- Fonctions -
- // --------------------------------------------------------------------------------------------------------
- void ajustAffichage() {
- adc_key_in = analogRead(0); // read the value from the sensor
- digitalWrite(13, LOW);
- key = get_key(adc_key_in); // convert into key press
- if (key != oldkey) // if keypress is detected
- {
- delay(50); // wait for debounce time
- adc_key_in = analogRead(0); // read the value from the sensor
- key = get_key(adc_key_in); // convert into key press
- if (key != oldkey)
- {
- oldkey = key;
- if (key >= 0) {
- digitalWrite(13, HIGH);
- switch (key)
- {
- case 0: Serial.println("S1 OK");
- aGauche ();
- break;
- case 1: Serial.println("S2 OK");
- moinsUn ();
- break;
- case 2: Serial.println("S3 OK");
- aDroite();
- break;
- case 3: Serial.println("S4 OK");
- plusUn();
- break;
- case 4: Serial.println("S5 OK");
- afficheAnnee();
- break;
- }
- }
- }
- }
- delay(100);
- }
- void afficheAnnee (){
- // on efface les donnée à afficher
- display.clear();
- // on règle la luminosité à la moitié
- display.setBrightness(3);
- // on détermine la position du curseur en marquant le point
- positionPoint = posPoint[0];
- curseur=0;
- // on affiche
- display.showNumberDecEx(annee, positionPoint, false, 4, 0);
- }
- void aDroite (){
- // on efface les donnée à afficher
- display.clear();
- // on règle la luminosité à la moitié
- display.setBrightness(3);
- // on détermine la position du curseur en marquant le point
- if (curseur < 3){
- curseur += 1;
- }else{
- curseur = 0;
- }
- positionPoint = posPoint[curseur];
- // on affiche
- display.showNumberDecEx(annee, positionPoint, false, 4, 0);
- }
- void aGauche (){
- // on efface les donnée à afficher
- display.clear();
- // on règle la luminosité à la moitié
- display.setBrightness(3);
- // on détermine la position du curseur en marquant le point
- if (curseur > 0){
- curseur -= 1;
- }else{
- curseur = 3;
- }
- positionPoint = posPoint[curseur];
- // on affiche
- display.showNumberDecEx(annee, positionPoint, false, 4, 0);
- }
- void plusUn () {
- // on efface les donnée à afficher
- display.clear();
- // on règle la luminosité à la moitié
- display.setBrightness(3);
- // on détermine la position du curseur en marquant le point
- if (curseur == 3){
- annee += 1;
- } else if (curseur == 2){
- annee += 10;
- } else if (curseur == 1){
- annee += 100;
- } else if (curseur == 0){
- annee += 1000;
- }
- positionPoint = posPoint[curseur];
- // on affiche
- display.showNumberDecEx(annee, positionPoint, false, 4, 0);
- }
- void moinsUn () {
- // on efface les donnée à afficher
- display.clear();
- // on règle la luminosité à la moitié
- display.setBrightness(3);
- // on détermine la position du curseur en marquant le point
- if (curseur == 3){
- annee -= 1;
- } else if (curseur == 2){
- annee -= 10;
- } else if (curseur == 1){
- annee -= 100;
- } else if (curseur == 0){
- annee -= 1000;
- }
- positionPoint = posPoint[curseur];
- // on affiche
- display.showNumberDecEx(annee, positionPoint, false, 4, 0);
- }
- int get_key(unsigned int input)
- {
- int k;
- for (k = 0; k < NUM_KEYS; k++)
- {
- if (input < adc_key_val[k])
- {
- return k;
- }
- }
- if (k >= NUM_KEYS)k = -1; // No valid key pressed
- return k;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement