Horloge DIY

Parlez nous de vos projets et de vos idées, imaginez des applications

Horloge DIY

Message non lude EricDuino » Jeu 16 Aoû 2012 22:08

F> Encore une création inutile ?
H> Non, une horloge c'est utile...
F> Oui, mais on en a beaucoup, c'est un truc qui existe et ce n'est pas cher ?
H> Celle-ci est innovante, unique et réparable, on peut y programmer plus que l'heure de réveil mais aussi la reproduire et même l'améliorer...

horl1.jpg
horl1.jpg (173.67 Kio) Vu 1301 fois


horl2.jpg
horl2.jpg (141.89 Kio) Vu 1301 fois


horl3.jpg
horl3.jpg (202.99 Kio) Vu 1301 fois


Et le code :

Code: Tout sélectionner
// EricDuino le 8/8/12
// reprise debug et portage cablage basé sur afficheur de récup d'un démo tnt métronic
//portage sur plaque à pastille


// This clock engine is based of of code from nootropicdesign.com - thanks!
// Jeremy Saglimbeni 2011 - thecustomgeek.com
// These are indexes into the groundPins array


#include "pitches.h"

// notes in the melody:
int melody[] = {
  NOTE_C4, NOTE_G3,NOTE_G3, NOTE_A3, NOTE_G3,0, NOTE_B3, NOTE_C4};

// note durations: 4 = quarter note, 8 = eighth note, etc.:
int noteDurations[] = {
  4, 8, 8, 4,4,4,4,4 };






#define MIDDLE 0 // G
#define UPPER_L 1 // F
#define LOWER_L 2 // E
#define BOTTOM 3 // D
#define LOWER_R 4 // C
#define UPPER_R 5 // B
#define TOP 6 // A
//  the colon between the hours and minutes sur PIN 4 afficheur et GND sur 12
int groundPins[7] = {18, 9, 14, 15, 10, 19, 11}; // G, F, E, D, C, B, A
int digitPins[4] = {12, 13, 16, 17}; // dig 4,3,2,1 :positive voltage supply for each of the 4 digits --17 is RIGHT most digit--
int ON = HIGH; // HIGH for CA, LOW for CC
int OFF = LOW; // LOW for CA, HIGH for CC
int number[10][7]; // holds information about which segments are needed for each of the 10 numbers
int digit[4]; // holds values for each of the 4 display digits


int hours = 12;
int minutes = 00;
int elapsedMinutes = 0;
int seconds = 0;
int secon;
int separateur = 8; //pin
int hourset = 2; //pin
int hoursetv = 0;
int minuteset = 3;//pin
int minutesetv = 0;
int showsw = 4;//pin
int showswv = 0;
unsigned long prevtime;
int showtime = 16380;
int delaytime = 100;
void setup()
{
  pinMode(separateur, OUTPUT);
  digitalWrite(separateur, HIGH);
  pinMode(hourset, INPUT);
  pinMode(minuteset, INPUT);
  pinMode(showsw, INPUT);
  digitalWrite(hourset, HIGH);
  digitalWrite(minuteset, HIGH);
  digitalWrite(showsw, HIGH);
  initNumber();
  for(int i=0; i < 7; i++) {
    pinMode(groundPins[i], OUTPUT);
    digitalWrite(groundPins[i], HIGH); // HIGH for CA, LOW for CC
  }
  for(int i=0; i < 4; i++) {
    pinMode(digitPins[i], OUTPUT);
    digitalWrite(digitPins[i], LOW); // LOW for CA, HIGH for CC
  }
    Musique();
}   // Fin de setup

void loop() {
  int n = 0;
  unsigned long time = millis() - (elapsedMinutes * 60000);
  seconds = (time / 1000);
  if (seconds > 60) {
    seconds = 0;
    minutes++;
    elapsedMinutes++;
 
   
    if (minutes >= 60) {
      minutes = 0;
      hours++;
      if (hours > 12) {
        hours = 1;
      }
    }
  }
  n = (hours * 100) + minutes;
  setDigit(n);

  for(int g=0; g < 7; g++) {
    digitalWrite(groundPins[g], LOW); // LOW for CA, HIGH for CC
    for(int i=0; i < 4; i++) {
      if (digit[i] < 0) {
        continue;
      }
      digitalWrite(digitPins[i], number[digit[i]][g]);
    }
    getDelay(); // delay multiplexing function
    digitalWrite(groundPins[g], HIGH); // HIGH for CA, LOW for CC
  }
  if (time - prevtime > 500) { // toggle a second flag to blink the colon
    prevtime = time;
    if (secon == 1) {
      secon = 0;
      return;
    }
    if (secon == 0) {
      secon = 1;
      return;
    }
  }
if (secon == 1) {
  digitalWrite(separateur, HIGH);
}
if (secon == 0) {
  digitalWrite(separateur, LOW);
}
hoursetv = digitalRead(hourset); // hour set button
if (hoursetv == LOW) {
hours++;
delay(400);
if (hours > 12) {
  hours = 1;
}
}
minutesetv = digitalRead(minuteset); // minute set button
if (minutesetv == LOW) {
minutes++;
delay(400);
if (minutes > 59) {
  minutes = 0;
}
}
showswv = digitalRead(showsw); // button to slow the multiplexing down
if (showswv == LOW) {
showtime = 16380; //
delaytime = 100;
}
}

void setDigit(int n) {
  n = n % 2000;
  digit[0] = n % 10;
  digit[1] = (n / 10) % 10;
  if ((digit[1] == 0) && (n < 10)) {
    digit[1] = -1;
  }
  digit[2] = (n / 100) % 10;
  if ((digit[2] == 0) && (n < 100)) {
    digit[2] = -1;
  }
  digit[3] = (n / 1000) % 10;
  if (digit[3] == 0) {
    digit[3] = -1;
  }
}

void getDelay() { //stutter the multiplexing refresh
  if (delaytime >= 7) {
  delay(delaytime);
  delaytime -= 1;
}
  if (delaytime < 7) {
  delayMicroseconds(showtime);
  showtime -= 35;
  if (showtime <= 1001) {
  showtime = 1000;
  }
  }
}

void initNumber() {
  number[0][MIDDLE]  = OFF;
  number[0][UPPER_L] = ON;
  number[0][LOWER_L] = ON;
  number[0][BOTTOM]  = ON;
  number[0][LOWER_R] = ON;
  number[0][UPPER_R] = ON;
  number[0][TOP]     = ON;

  number[1][MIDDLE]  = OFF;
  number[1][UPPER_L] = OFF;
  number[1][LOWER_L] = OFF;
  number[1][BOTTOM]  = OFF;
  number[1][LOWER_R] = ON;
  number[1][UPPER_R] = ON;
  number[1][TOP]     = OFF;

  number[2][MIDDLE]  = ON;
  number[2][UPPER_L] = OFF;
  number[2][LOWER_L] = ON;
  number[2][BOTTOM]  = ON;
  number[2][LOWER_R] = OFF;
  number[2][UPPER_R] = ON;
  number[2][TOP]     = ON;

  number[3][MIDDLE]  = ON;
  number[3][UPPER_L] = OFF;
  number[3][LOWER_L] = OFF;
  number[3][BOTTOM]  = ON;
  number[3][LOWER_R] = ON;
  number[3][UPPER_R] = ON;
  number[3][TOP]     = ON;

  number[4][MIDDLE]  = ON;
  number[4][UPPER_L] = ON;
  number[4][LOWER_L] = OFF;
  number[4][BOTTOM]  = OFF;
  number[4][LOWER_R] = ON;
  number[4][UPPER_R] = ON;
  number[4][TOP]     = OFF;

  number[5][MIDDLE]  = ON;
  number[5][UPPER_L] = ON;
  number[5][LOWER_L] = OFF;
  number[5][BOTTOM]  = ON;
  number[5][LOWER_R] = ON;
  number[5][UPPER_R] = OFF;
  number[5][TOP]     = ON;

  number[6][MIDDLE]  = ON;
  number[6][UPPER_L] = ON;
  number[6][LOWER_L] = ON;
  number[6][BOTTOM]  = ON;
  number[6][LOWER_R] = ON;
  number[6][UPPER_R] = OFF;
  number[6][TOP]     = ON;

  number[7][MIDDLE]  = OFF;
  number[7][UPPER_L] = OFF;
  number[7][LOWER_L] = OFF;
  number[7][BOTTOM]  = OFF;
  number[7][LOWER_R] = ON;
  number[7][UPPER_R] = ON;
  number[7][TOP]     = ON;

  number[8][MIDDLE]  = ON;
  number[8][UPPER_L] = ON;
  number[8][LOWER_L] = ON;
  number[8][BOTTOM]  = ON;
  number[8][LOWER_R] = ON;
  number[8][UPPER_R] = ON;
  number[8][TOP]     = ON;

  number[9][MIDDLE]  = ON;
  number[9][UPPER_L] = ON;
  number[9][LOWER_L] = OFF;
  number[9][BOTTOM]  = ON;
  number[9][LOWER_R] = ON;
  number[9][UPPER_R] = ON;
  number[9][TOP]     = ON;
}

void Musique() {
  // iterate over the notes of the melody:
  for (int thisNote = 0; thisNote < 8; thisNote++) {

    // to calculate the note duration, take one second
    // divided by the note type.
    //e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc.
    int noteDuration = 1000/noteDurations[thisNote];
    tone(7, melody[thisNote],noteDuration);

    // to distinguish the notes, set a minimum time between them.
    // the note's duration + 30% seems to work well:
    int pauseBetweenNotes = noteDuration * 1.30;
    delay(pauseBetweenNotes);
    // stop the tone playing:
    noTone(7);
  }
}


et le pitches.h

Code: Tout sélectionner
/*************************************************
 * Public Constants
 *************************************************/

#define NOTE_B0  31
#define NOTE_C1  33
#define NOTE_CS1 35
#define NOTE_D1  37
#define NOTE_DS1 39
#define NOTE_E1  41
#define NOTE_F1  44
#define NOTE_FS1 46
#define NOTE_G1  49
#define NOTE_GS1 52
#define NOTE_A1  55
#define NOTE_AS1 58
#define NOTE_B1  62
#define NOTE_C2  65
#define NOTE_CS2 69
#define NOTE_D2  73
#define NOTE_DS2 78
#define NOTE_E2  82
#define NOTE_F2  87
#define NOTE_FS2 93
#define NOTE_G2  98
#define NOTE_GS2 104
#define NOTE_A2  110
#define NOTE_AS2 117
#define NOTE_B2  123
#define NOTE_C3  131
#define NOTE_CS3 139
#define NOTE_D3  147
#define NOTE_DS3 156
#define NOTE_E3  165
#define NOTE_F3  175
#define NOTE_FS3 185
#define NOTE_G3  196
#define NOTE_GS3 208
#define NOTE_A3  220
#define NOTE_AS3 233
#define NOTE_B3  247
#define NOTE_C4  262
#define NOTE_CS4 277
#define NOTE_D4  294
#define NOTE_DS4 311
#define NOTE_E4  330
#define NOTE_F4  349
#define NOTE_FS4 370
#define NOTE_G4  392
#define NOTE_GS4 415
#define NOTE_A4  440
#define NOTE_AS4 466
#define NOTE_B4  494
#define NOTE_C5  523
#define NOTE_CS5 554
#define NOTE_D5  587
#define NOTE_DS5 622
#define NOTE_E5  659
#define NOTE_F5  698
#define NOTE_FS5 740
#define NOTE_G5  784
#define NOTE_GS5 831
#define NOTE_A5  880
#define NOTE_AS5 932
#define NOTE_B5  988
#define NOTE_C6  1047
#define NOTE_CS6 1109
#define NOTE_D6  1175
#define NOTE_DS6 1245
#define NOTE_E6  1319
#define NOTE_F6  1397
#define NOTE_FS6 1480
#define NOTE_G6  1568
#define NOTE_GS6 1661
#define NOTE_A6  1760
#define NOTE_AS6 1865
#define NOTE_B6  1976
#define NOTE_C7  2093
#define NOTE_CS7 2217
#define NOTE_D7  2349
#define NOTE_DS7 2489
#define NOTE_E7  2637
#define NOTE_F7  2794
#define NOTE_FS7 2960
#define NOTE_G7  3136
#define NOTE_GS7 3322
#define NOTE_A7  3520
#define NOTE_AS7 3729
#define NOTE_B7  3951
#define NOTE_C8  4186
#define NOTE_CS8 4435
#define NOTE_D8  4699
#define NOTE_DS8 4978


Avatar de l’utilisateur
EricDuino
 
Messages: 225
Inscription: Sam 5 Mai 2012 10:10
Localisation: Toulouse

Retourner vers Vos projets, vos idées

Qui est en ligne

Utilisateurs parcourant ce forum: Aucun utilisateur enregistré et 1 invité

cron