Arduino – 7 Segment Display Devresi

Merhaba, arduino devre elemanlarını tanımaya ve onların bağlantı şekillerini öğrenmeye devam ediyoruz.

 

Görselde gösterildiği gibi bir devre kuracak olursanız devrenin tamamlanmış olduğunu göreceksiniz.

 

Test Kodu –>

 

// Include Libraries
#include "Arduino.h"
#include "SevSeg.h"


// Pin Definitions
#define S7SEG_PIN_A 2
#define S7SEG_PIN_B 3
#define S7SEG_PIN_C 4
#define S7SEG_PIN_D 5
#define S7SEG_PIN_E 11
#define S7SEG_PIN_F 12
#define S7SEG_PIN_G 13
#define S7SEG_PIN_DECIMAL 6
#define S7SEG_PIN_DIG1 7
#define S7SEG_PIN_DIG2 8
#define S7SEG_PIN_DIG3 9
#define S7SEG_PIN_DIG4 10

// Global variables and defines
int s7segCounter = 0; 
unsigned long s7segTimer = millis();
byte s7segDigitPins[] = { S7SEG_PIN_DIG1, S7SEG_PIN_DIG2, S7SEG_PIN_DIG3, S7SEG_PIN_DIG4 };
byte s7segSegmentPins[] = { S7SEG_PIN_A, S7SEG_PIN_B, S7SEG_PIN_C, S7SEG_PIN_D, S7SEG_PIN_E, S7SEG_PIN_F ,S7SEG_PIN_G, S7SEG_PIN_DECIMAL };
// object initialization
SevSeg s7seg(s7segDigitPins, s7segSegmentPins);

// define vars for testing menu
const int timeout = 10000; //define timeout of 10 sec
char menuOption = 0;
long time0;

// Setup the essentials for your circuit to work. It runs first every time your circuit is powered with electricity.
void setup() 
{
 // Setup Serial which is useful for debugging
 // Use the Serial Monitor to view printed messages
 Serial.begin(9600);
 while (!Serial) ; // wait for serial port to connect. Needed for native USB
 Serial.println("start");
 
 s7seg.setBrightness(90); //Seven-Segment LED brightness 0 - 100
 menuOption = menu();
 
}

// Main logic of your circuit. It defines the interaction between the components you selected. After setup, it runs over and over again, in an eternal loop.
void loop() 
{
 
 
 if(menuOption == '1') {
 // 7-Segment Display - 20mm - Test Code
 if (millis() - s7segTimer >= 50) 
 {
 s7segTimer = millis();
 s7segCounter++; //increment counter
 s7seg.setNumber(s7segCounter, 1); //set display value
 }
 s7seg.refreshDisplay(); // Must run repeatedly
 }
 
 
 
 if (millis() - time0 > timeout)
 {
 menuOption = menu();
 }
 
}

// Menu function for selecting the components to be tested
// Follow serial monitor for instrcutions
char menu()
{

Serial.println(F("\nWhich component would you like to test?"));
 Serial.println(F("(1) 7-Segment Display - 20mm"));
 Serial.println(F("(menu) send anything else or press on board reset button\n"));
 while (!Serial.available());

// Read data from serial monitor if received
 while (Serial.available()) 
 {
 char c = Serial.read();
 if (isAlphaNumeric(c)) 
 {
 if(c == '1') 
 Serial.println(F("Now Testing 7-Segment Display - 20mm"));
 else
 {
 Serial.println(F("illegal input!"));
 return 0;
 }
 time0 = millis();
 return c;
 }
 }
 }

Bir cevap yazın

E-posta hesabınız yayımlanmayacak. Gerekli alanlar * ile işaretlenmişlerdir