Forum de LAPLLA.net

Version complète : Afficheur 8 digits
Vous consultez actuellement la version basse qualité d'un document. Voir la version complète avec le bon formatage.
[attachment=27]

Code :
// 1 = LED on, 0 = LED off, in this order:
//                                              Arduino pin: 2,3,4,5,6,7,8,9
byte seven_seg_digits[10][8] = {                           { 1,1,0,1,1,1,0,1 },  // = 0
                                                           { 0,0,0,0,0,1,0,1 },  // = 1
                                                           { 1,1,1,0,1,1,0,0 },  // = 2
                                                           { 1,0,1,0,1,1,0,1 },  // = 3
                                                           { 0,0,1,1,0,1,0,1 },  // = 4
                                                           { 1,0,1,1,1,0,0,1 },  // = 5
                                                           { 1,1,1,1,1,0,0,1 },  // = 6
                                                           { 0,0,0,0,1,1,0,1 },  // = 7
                                                           { 1,1,1,1,1,1,0,1 },  // = 8
                                                           { 1,0,1,1,1,1,0,1 }   // = 9
                                                           };
#define BUTTON_PIN        1  // Button
int count = 0;      

void setup() {                
  pinMode(2, OUTPUT);
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(6, OUTPUT);
  pinMode(7, OUTPUT);
  pinMode(8, OUTPUT);
  pinMode(9, OUTPUT);
  //writeDot(0);  // start with the "dot" off //?

  //Button
  pinMode(BUTTON_PIN, INPUT);
  digitalWrite(BUTTON_PIN, HIGH); // connect internal pull-up
  sevenSegWrite(0); //display a 0 by default
}

void writeDot(byte dot) {
  digitalWrite(9, dot);
}
    
void sevenSegWrite(byte digit) {
  byte pin = 2;
  for (byte segCount = 0; segCount < 8; ++segCount) {
    digitalWrite(pin, seven_seg_digits[digit][segCount]);
    ++pin;
  }
}

boolean handle_button(){
  int button_pressed = !digitalRead(BUTTON_PIN); // pin low -> pressed
  return button_pressed;
}


void loop() {
  // handle button
  boolean button_pressed = handle_button();

  digitalWrite(0, 9);
  if (button_pressed) {
    if (count < 10) {
      delay(200);
      sevenSegWrite(count);
      Serial.print(count);
      count++;
    } else {
      delay(200);
      count = 0;
      sevenSegWrite(count);
      count++;
    }
  }
  
  delay(100);

  
}
L'afficheur 8 digits pour Fritzing : http://laplla.net/forum/uploads/manuels/...splay.fzpz
URLs de référence