0% found this document useful (0 votes)
50 views12 pages

Kelompok 5 Unit 6 MicroController

This document summarizes three programs for a microcontroller practical involving seven segment displays and dot matrix displays: 1. A program to display letters on a seven segment display using buttons to cycle through the letters. 2. A program to display numbers on a dot matrix display using buttons to increment and decrement the number. 3. A program to simulate a counter display on a dot matrix using easing animation when incrementing digits.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
50 views12 pages

Kelompok 5 Unit 6 MicroController

This document summarizes three programs for a microcontroller practical involving seven segment displays and dot matrix displays: 1. A program to display letters on a seven segment display using buttons to cycle through the letters. 2. A program to display numbers on a dot matrix display using buttons to increment and decrement the number. 3. A program to simulate a counter display on a dot matrix using easing animation when incrementing digits.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

LAPORAN SEMENTARA

PRAKTIKUM MICROCONTROLLER
UNIT 6
SEVEN SEGMENT & DOT MATRIX

Oleh:
Nama : M Arifin Wardana

David Danendra R

Hilmi Pramono Adi


NIM : 22/493045/SV/20655

22/496884/SV/21041

22/503024/SV/21463
Kelas : RE3A1

Dosen Pengampu : Budi Bayu Murti, S.T., M.T

Asisten : 1. Faizal Azmi Nurwardani

2. Abi Azka Najasyi

Laboran : Sugeng Julianto, S.ST.

Hari, Tangal : Senin, 25 September 2023

PROGRAMSTUDITEKNOLOGIREKAYASAELEKTRO
DEPARTEMENTEKNIKELEKTRODANINFORMATIKA
SEKOLAHVOKASI
UNIVERSITASGADJAHMADA
2023
UNIT 6
SEVEN SEGMENT & DOT MATRIX

FlowChart
Program 1
Program 2
PROGRAM 3
PROGRAM 1

const int buttonAPin = 2; // Pin untuk tombol A


const int buttonBPin = 3; // Pin untuk tombol B

const int segA = 4;


const int segB = 5;
const int segC = 6;
const int segD = 7;
const int segE = 8;
const int segF = 9;
const int segG = 10;

char letters[] = {'d', 'a', 'v', 'i', 'd'}; // Array karakter "david"
int currentLetterIndex = 0; // Indeks huruf saat ini

void setup() {
pinMode(buttonAPin, INPUT_PULLUP);
pinMode(buttonBPin, INPUT_PULLUP);

pinMode(segA, OUTPUT);
pinMode(segB, OUTPUT);
pinMode(segC, OUTPUT);
pinMode(segD, OUTPUT);
pinMode(segE, OUTPUT);
pinMode(segF, OUTPUT);
pinMode(segG, OUTPUT);
}

void displayCharacter(char character) {


// Segmen-segmen tampilan tujuh akan dinyalakan sesuai dengan karakter yang ditampilkan
switch (character) {
case 'd':
digitalWrite(segA, HIGH);
digitalWrite(segB, LOW);
digitalWrite(segC, LOW);
digitalWrite(segD, LOW);
digitalWrite(segE, LOW);
digitalWrite(segF, HIGH);
digitalWrite(segG, LOW);
break;
case 'a':
digitalWrite(segA, LOW);
digitalWrite(segB, LOW);
digitalWrite(segC, LOW);
digitalWrite(segD, LOW);
digitalWrite(segE, LOW);
digitalWrite(segF, HIGH);
digitalWrite(segG, LOW);
break;
case 'v':
digitalWrite(segA, HIGH);
digitalWrite(segB, LOW);
digitalWrite(segC, LOW);
digitalWrite(segD, LOW);
digitalWrite(segE, LOW);
digitalWrite(segF, LOW);
digitalWrite(segG, HIGH);
break;
case 'i':
digitalWrite(segA, HIGH);
digitalWrite(segB, HIGH);
digitalWrite(segC, HIGH);
digitalWrite(segD, HIGH);
digitalWrite(segE, LOW);
digitalWrite(segF, LOW);
digitalWrite(segG, HIGH);
break;
case 'd 1':
digitalWrite(segA, HIGH);
digitalWrite(segB, LOW);
digitalWrite(segC, LOW);
digitalWrite(segD, LOW);
digitalWrite(segE, LOW);
digitalWrite(segF, HIGH);
digitalWrite(segG, LOW);
break;
default:
// Matikan semua segmen jika karakter tidak dikenali
digitalWrite(segA, LOW);
digitalWrite(segB, LOW);
digitalWrite(segC, LOW);
digitalWrite(segD, LOW);
digitalWrite(segE, LOW);
digitalWrite(segF, LOW);
digitalWrite(segG, LOW);
}
}

void loop() {
// Baca tombol A
if (digitalRead(buttonAPin) == LOW) {
// Tampilkan huruf berikutnya
currentLetterIndex = (currentLetterIndex + 1) % 4;
}

// Baca tombol B
if (digitalRead(buttonBPin) == LOW) {
// Tampilkan huruf sebelumnya
currentLetterIndex = (currentLetterIndex - 1 + 4) % 4;
}

// Tampilkan huruf saat ini


displayCharacter(letters[currentLetterIndex]);

delay(100); // Tambahkan delay agar tombol tidak membounce terlalu cepat


}
PROGRAM 2

#include <LedControl.h>

int DIN = 12;


int CS = 11;
int CLK = 10;
LedControl lc = LedControl(DIN, CLK, CS, 0);

int currentNumber = 0;
byte digitPatterns[10][8] = {
{0x3E, 0x45, 0x49, 0x51, 0x61, 0x41, 0x3E, 0x00}, // 0
{0x04, 0x0C, 0x14, 0x04, 0x04, 0x04, 0x1F, 0x00}, // 1
{0x1E, 0x21, 0x01, 0x02, 0x0C, 0x10, 0x3F, 0x00}, // 2
{0x1E, 0x21, 0x01, 0x0E, 0x01, 0x21, 0x1E, 0x00}, // 3
{0x08, 0x18, 0x28, 0x48, 0x7F, 0x08, 0x08, 0x00}, // 4
{0x3F, 0x20, 0x20, 0x3E, 0x01, 0x21, 0x1E, 0x00}, // 5
{0x1C, 0x02, 0x01, 0x3F, 0x21, 0x21, 0x1E, 0x00}, // 6
{0x3F, 0x01, 0x02, 0x04, 0x08, 0x10, 0x10, 0x00}, // 7
{0x1E, 0x21, 0x21, 0x1E, 0x21, 0x21, 0x1E, 0x00}, // 8
{0x1E, 0x21, 0x21, 0x3E, 0x20, 0x10, 0x0E, 0x00} // 9
};

const int buttonPlusPin = 5; // Pin untuk tombol penambah


const int buttonMinusPin = 6; // Pin untuk tombol pengurang

void setup(){
lc.shutdown(0, false);
lc.setIntensity(0, 15);

pinMode(buttonPlusPin, INPUT_PULLUP); // Mengatur tombol penambah sebagai input


dengan pull-up resistor
pinMode(buttonMinusPin, INPUT_PULLUP); // Mengatur tombol pengurang sebagai input
dengan pull-up resistor
}

void loop(){
// Mengecek tombol penambah dan pengurang
if (digitalRead(buttonPlusPin) == LOW) {
currentNumber = (currentNumber + 1) % 10;
displayNumber(currentNumber);
delay(500); // Debouncing delay
}

if (digitalRead(buttonMinusPin) == LOW) {
currentNumber = (currentNumber + 9) % 10;
displayNumber(currentNumber);
delay(500); // Debouncing delay
}
}

void displayNumber(int number) {


byte digit[8];

for (int i = 0; i < 8; i++) {


digit[i] = digitPatterns[number][i];
}

for (int i = 0; i < 8; i++) {


lc.setRow(0, i, digit[i]);
}
}
PROGRAM 3

#include <Arduino.h>
#include <U8g2lib.h>

U8G2_MAX7219_32X8_F_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 11, /* data=*/ 12, /*


cs=*/ 10, /* dc=*/ U8X8_PIN_NONE, /* reset=*/ U8X8_PIN_NONE);

// 'matrix_display_counter', 32x8px
const unsigned char epd_bitmap_matrix_display_counter [] = {
0x7e, 0x67, 0x75, 0x77, 0xef, 0x21, 0x15, 0x44, 0xe7, 0x21, 0x15, 0x44, 0xe3, 0x27,
0x77, 0x77,
0xe7, 0x24, 0x11, 0x15, 0xef, 0x24, 0x11, 0x15, 0x7e, 0x77, 0x71, 0x77, 0x00, 0x00,
0x00, 0x00
};

byte digits[6] = {0, 0, 0, 0, 0, 0}; // individual digits to be displayed on the matrix display
byte digits_offset_perc[6] = {0, 0, 0, 0, 0, 0}; // y offset for the individual digits - percentage
0-100%
char digit_char[2]; // helper array for storing C-style string
char digit_char_next[2]; // helper array for storing C-style string

float y_offset; // y pixel offset for digit

void setup(void) {
u8g2.begin(); // begin function is required for u8g2 library
u8g2.setContrast(10*16); // set display contrast 0-255

pinMode(7, INPUT_PULLUP);
}

void loop(void) {

if (digitalRead(7) == LOW) { // button is pressed


if (digits_offset_perc[5] == 0) { // no animation is currently playing for the last digit
digits_offset_perc[5] = 2; // in that case, animate the last digit (increment the last digit)
}
}

u8g2.clearBuffer(); // clear the internal u8g2 memory


u8g2.setFont(u8g2_font_minuteconsole_tr); // choose a suitable font with digits 3px
wide

for (int i=5; i>=0; i--) { // go from the last digit to the first digit

if (digits_offset_perc[i] > 0) { // animate the digit


digits_offset_perc[i] = digits_offset_perc[i] + 2; // increase the percentage offset

if ((digits[i] == 9) && (digits_offset_perc[i-1] == 0) && (digits_offset_perc[i] > 20)) {


digits_offset_perc[i-1] = 2; // digit is 9 turning to 0 = increase digit on the left side
}

if (digits_offset_perc[i] >= 100) { // animation is complete, switch to the next digit


digits_offset_perc[i] = 0; // stop the animation
digits[i] = digits[i] + 1; // switch to the next digit

if (digits[i] == 10) { // if the digit goes over 9, go back to 0


digits[i] = 0;
}
}
}

// linear movement of digits - looks boring


//y_offset = round((digits_offset_perc[i] / 100.0) * 8.0); // calculate the Y pixel offset
// easing using the power function - looks strange for continuous animation
//y_offset = round(pow((digits_offset_perc[i] / 100.0), 0.4) * 8.0);
// easing using the cosine function - looks great
y_offset = round((1-((cos(digits_offset_perc[i] / 100.0 * 3.141592654) / 2.0)+0.5)) * 8.0);

itoa(digits[i], digit_char, 10); // convert digit number to helper C-style string array
itoa((digits[i]+1) % 10, digit_char_next, 10); // convert next digit number to helper C-style
string array

u8g2.drawStr(9 + i*4, 7 - y_offset, digit_char); // draw the current character to the


display
u8g2.drawStr(9 + i*4, 7 - y_offset + 8, digit_char_next); // draw the next character to the
display
}

u8g2.sendBuffer(); // transfer internal memory to the display


}

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy