TUGAS :
Mari kita buat file simulasi untuk menguji kode kita di Proteus. Kita memilih Proteus untuk
tujuan ini karena sifat simulasi waktu nyata dan kemampuan untuk mensimulasikan kode
Arduino cukup baik. Sebagian besar waktu ketika simulasi berjalan di Proteus, itu berarti ada
kemungkinan besar kode akan bekerja secara real time ( secara praktikum lanbgsung ) . Berikut
ini adalah diagram dan file simulasi serta hasil running dari simulasi.
Kode Program
/*
*/
#define NUM_OF_DISPLAY 4
char shiftOutBuffer[NUM_OF_DISPLAY]={0};
byte segChar[]={
0b00111111,
0b00000110,
0b01011011,
0b01001111,
0b01100110,
0b01101101,
0b01111101,
0b00000111,
0b01111111,
0b01101111,
0b00000000,
};
void update_display()
int i=0;
digitalWrite(strobePin, LOW);
for(i=NUM_OF_DISPLAY-1;i>-1;i--)
digitalWrite(strobePin, HIGH);
void reset_digits(){
int i=0;
for(i=0;i<NUM_OF_DISPLAY;i++)
shiftOutBuffer[i]=0;
update_display();
void setup() {
int i=0;
pinMode(strobePin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(dataPin, OUTPUT);
for(i=0;i<NUM_OF_DISPLAY;i++)
shiftOutBuffer[i]=i+1;
update_display();
void loop() {
}
2. Dengan Menggunakan Shift Reigiter 74HC595 ( TTL )
CATATAN !
Jika dibuat pada real hardware perhatikan sambungan pin Q7' dan MR dan OE pada ic shift register
/*
* By Fickry Muhammad
*/
int o,p,q,r;
int z= 99;
void setup()
pinMode(latchpin, OUTPUT);
pinMode(clockpin, OUTPUT);
pinMode(datapin, OUTPUT);
void loop()
digitalWrite(latchpin, LOW);
digitalWrite(latchpin, HIGH);
r = z % 10;
c. Verify program arduino,apabila tidak terjadi error lanjut dengan proses upload
d. Upload program,apabila succes akan muncul tulisan done uploading,apabila ada yang belum tahu
bagaimana cara upload code/sketch ke board arduino bisa baca disini
Berikut Proyek ini bekerja dengan mengaktifkan digit pertama, kemudian mengirimkan data
ke register geser, yang mengirimkannya ke digit yang diaktifkan. Kemudian digit pertama
dinonaktifkan, digit kedua diaktifkan dan proses diulang.
Kode Program
int latchPin = 5;
int dataPin = 4;
int clockPin = 6;
const float segSpeed = .05; //How quickly to flash each led segment.
const int digLoop = 100; //How many times to repeat the segment sequence.
const int nextPin = 200; //Delay before moving to the next digit on the
display.
const int repeatSeq = 300; //Delay before starting over from the first digit.
const int pinArray[4] = {3, 9, 10, 11}; //Defines PWM pins, the pins that
activate each digiti.
const int digArray[11][9] = {
{127, 191, 223, 239, 247, 251, 255, 254, 255}, //0: 127 top led segment
{255, 191, 223, 255, 255, 255, 255, 254, 255}, //1: 191 top right seg
{127, 191, 255, 239, 247, 255, 253, 254, 255}, //2: 255 is NO segment
{127, 191, 223, 239, 255, 255, 253, 254, 255}, //3: 223 bottom right seg
{255, 191, 223, 255, 255, 251, 253, 254, 255}, //4:
{127, 255, 223, 239, 255, 251, 253, 254, 255}, //5: 239 bottom seg
{127, 191, 223, 239, 247, 255, 253, 254, 255}, //6: 247 bottom left seg
{127, 191, 223, 255, 255, 255, 255, 254, 255}, //7:
/*Example for the number 7:
* 127: |_ON |
* 251:OFF ON:191
* 253: OFF | |
* 247:OFF ON:223
* 239: OFF |_|
*/
{127, 191, 223, 239, 247, 251, 253, 254, 255}, //8: 251 top left seg
{127, 191, 223, 239, 255, 251, 253, 254, 255}, //9: 253 center seg
{255, 255, 255, 255, 255, 255, 255, 254, 255}, //DP: Decimal Point seg
};
const int arrHeight = 9; // (0-9) 9 displays digits 0-9.
const int arrWidth = 6; // (0-8) how many segments from each row to use. 7 will
add the decimal row.
void setup() {
//Serial.begin(9600); //which port to output serial display data. unused.
slows display down.
pinMode(latchPin, OUTPUT);
pinMode(dataPin, OUTPUT);
pinMode(clockPin, OUTPUT);
}
void loop() {
for (int i = 0; i <= 3; i++) { //cycles through all PWM pins
for (int k = 0; k <= arrHeight; k++) { //cycles through countTo number of
digArray rows
analogWrite((pinArray[i]), 255); //turns PWM pin(i) on
for (int h = 0; h <= digLoop; h++) { //how many times to cycle through
columns
for (int j = 0; j <= arrWidth; j++) { //cycles through all displayed
column data
digitalWrite(latchPin, HIGH);
shiftOut(dataPin, clockPin, MSBFIRST, digArray[k][j]);
digitalWrite(latchPin, LOW);
delay(segSpeed); //delay until next segment displayed sequence
}
}
analogWrite((pinArray[i]), 0); //turns PWM pin(i) off
delay(nextPin); //delay until next displayed digit sequence
}
}
delay(repeatSeq); //delay until everything is started over again
}