Pada kesempatan yang berbahagia kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang fungsinya untuk mendeteksi warna, baik itu warna primer maupun sekunder, alat ini digunakan untuk pelatihan anak-anak dalam pengenalan warna baik itu di sekolah maupun di luar sekolah. alat ini bisa berbicara dalam dua bahasa, yaitu indonesia dan inggris, selain itu ada 2 menu pilihan lain yaitu Latihan dan kuis, jika latihan maka anak-anak akan disuruh untuk menghafal warna-warna yang dideteksi, jika kuis maka anak-anak disuruh untuk menebak suara yang di inginkan oleh alat. alat ini bisa mengeluarkan suara sesuai warna yang dideteksi.
a, Minimum System ATMega
b. Modul Sensor TCS3200
c. Modul WP3A (Wav Player)
Supply = 5v
Port COM = RX-TX
Baudrate = 19200
Play Code = "l"+"nama_file.wav" = "lcoba.wav"
d. Program CV AVR ( Code Vision AVR )
/*****************************************************
This program was produced by the
CodeWizardAVR V2.05.0 Professional
Automatic Program Generator
© Copyright 1998-2010 Pavel Haiduc, HP InfoTech s.r.l.
http://www.hpinfotech.com
Project :
Version :
Date : 8/2/2016
Author : NeVaDa
Company :
Comments:
Chip type : ATmega32
Program type : Application
AVR Core Clock frequency: 11.059200 MHz
Memory model : Small
External RAM size : 0
Data Stack size : 512
*****************************************************/
#include <mega32.h>
#include <delay.h>
#include <stdlib.h>
// Alphanumeric LCD Module functions
#include <alcd.h>
// Standard Input/Output functions
#include <stdio.h>
#define redref (27795/255)
#define greenref (33066.7/255)
#define blueref (34720/255)
unsigned char lcd_buffer[33];
unsigned int count, red, green, blue,a=0,b=0,c=0,ww =1, zero, ok=0, batas=0, cv=1;
float periode, frekuensi;
char temp[10];
void red_filter()
{
PORTA.5=0;
PORTA.6=0;
for(a=0; a<=5; a++)
{
while(PINB.1 == 0){}
while(PINB.1 == 1){}
}
while(PINB.1 == 0)
{
count++;
}
while(PINB.1 == 1)
{
count++;
}
periode = ((float)count*0.0000014400921658986175115207373271889);
frekuensi = ((float)1/periode);
red = (frekuensi/redref);
count=0;
}
void green_filter()
{
PORTA.5=1;
PORTA.6=1;
for(b=0; b<=5; b++)
{
while(PINB.1 == 0){}
while(PINB.1 == 1){}
}
while(PINB.1 == 0)
{
count++;
}
while(PINB.1 == 1)
{
count++;
}
periode = ((float)count*0.0000014400921658986175115207373271889);
frekuensi = ((float)1/periode);
green = (frekuensi/greenref);
count=0;
}
void blue_filter()
{
PORTA.5=0;
PORTA.6=1;
for(c=0; c<=5; c++)
{
while(PINB.1 == 0){}
while(PINB.1 == 1){}
}
while(PINB.1 == 0)
{
count++;
}
while(PINB.1 == 1)
{
count++;
}
periode = ((float)count*0.0000014400921658986175115207373271889);
frekuensi = ((float)1/periode);
blue = (frekuensi/blueref);
count=0;
}
// Declare your global variables here
void quizx(){
cv = 1;
if(zero == 1){
while(1){
lcd_gotoxy(0,0);
lcd_putsf("FIND RED");
if(cv == 1){
printf("lfind.wav\r");
delay_ms(200);
printf("lred.wav\r");
delay_ms(200);
cv = 2;
}
red_filter();
delay_ms(500);
green_filter();
delay_ms(500);
blue_filter();
delay_ms(500);
a=0; b=0; c=0;
//merah
if((red > 100)&&(red < 125)&&(green > 90)&&(green < 110)&&(blue > 90)&&(blue < 110)&&(batas == 0)){
lcd_gotoxy(0,3);
lcd_putsf("RED");
ok = ok + 1;
batas = 1;
}
if(PIND.3 == 0){
cv = 1;
batas = 0;
delay_ms(500);
lcd_clear();
while(1){
lcd_gotoxy(0,0);
lcd_putsf("FIND YELLOW");
if(cv == 1){
printf("lfind.wav\r");
delay_ms(200);
printf("lyellow.wav\r");
delay_ms(200);
cv = 2;
}
red_filter();
delay_ms(500);
green_filter();
delay_ms(500);
blue_filter();
delay_ms(500);
a=0; b=0; c=0;
//kuning
if((red > 290)&&(red < 320)&&(green > 275)&&(green < 300)&&(blue > 260)&&(blue < 290)&&(batas==0)){
lcd_gotoxy(0,3);
lcd_putsf("YELLOW");
ok = ok + 1;
batas = 1;
}
if(PIND.3 == 0){
cv = 1;
batas = 0;
delay_ms(500);
lcd_clear();
while(1){
lcd_gotoxy(0,0);
lcd_putsf("FIND WHITE");
if(cv == 1){
printf("lfind.wav\r");
delay_ms(200);
printf("lwhite.wav\r");
delay_ms(200);
cv = 2;
}
red_filter();
delay_ms(500);
green_filter();
delay_ms(500);
blue_filter();
delay_ms(500);
a=0; b=0; c=0;
//putih
if((red > 400)&&(red < 440)&&(green > 400)&&(green < 450)&&(blue > 380)&&(blue < 450)&&(batas == 0)){
lcd_gotoxy(0,3);
lcd_putsf("WHITE");
ok = ok + 1;
batas = 1;
}
if(PIND.3 == 0){
cv = 1;
batas == 0;
delay_ms(500);
lcd_clear();
while(1){
lcd_gotoxy(0,0);
lcd_putsf("FIND BLACK");
if(cv == 1){
printf("lfind.wav\r");
delay_ms(200);
printf("lblack.wav\r");
delay_ms(200);
cv = 2;
}
red_filter();
delay_ms(500);
green_filter();
delay_ms(500);
blue_filter();
delay_ms(500);
a=0; b=0; c=0;
//hitam
if((red > 50)&&(red < 110)&&(green > 40)&&(green < 70)&&(blue > 40)&&(blue < 70)&&(batas == 0)){
lcd_gotoxy(0,3);
lcd_putsf("BLACK");
ok = ok + 1;
batas = 1;
}
if(PIND.3 == 0){
cv = 1;
batas = 0;
delay_ms(500);
lcd_clear();
while(1){
lcd_gotoxy(0,0);
lcd_putsf("FIND GREEN");
if(cv == 1){
printf("lfind.wav\r");
delay_ms(200);
printf("lgreen.wav\r");
delay_ms(200);
cv = 2;
}
red_filter();
delay_ms(500);
green_filter();
delay_ms(500);
blue_filter();
delay_ms(500);
a=0; b=0; c=0;
//hijau
if((red > 187)&&(red < 360)&&(green > 162)&&(green < 190)&&(blue > 154)&&(blue < 190)&&(batas == 0)){
lcd_gotoxy(0,3);
lcd_putsf("GREEN");
ok = ok + 1;
batas = 1;
}
if(PIND.3 == 0){
cv = 1;
batas = 0;
delay_ms(500);
lcd_clear();
while(1){
lcd_gotoxy(0,0);
lcd_putsf("FIND BLUE NAVY");
if(cv == 1){
printf("lfind.wav\r");
delay_ms(200);
printf("lbluenavy.wav\r");
delay_ms(200);
cv = 2;
}
red_filter();
delay_ms(500);
green_filter();
delay_ms(500);
blue_filter();
delay_ms(500);
a=0; b=0; c=0;
//biru dongker
if((red > 150)&&(red < 170)&&(green > 130)&&(green < 160)&&(blue > 120)&&(blue < 150)&&(batas == 0)){
lcd_gotoxy(0,3);
lcd_putsf("BLUE NAVY");
ok = ok + 1;
batas = 1;
}
if(PIND.3 == 0){
cv = 1;
batas = 0;
delay_ms(500);
lcd_clear();
while(1){
lcd_gotoxy(0,0);
lcd_putsf("FIND MAROON");
if(cv == 1){
printf("lfind.wav\r");
delay_ms(200);
printf("lmaroon.wav\r");
delay_ms(200);
cv = 2;
}
red_filter();
delay_ms(500);
green_filter();
delay_ms(500);
blue_filter();
delay_ms(500);
a=0; b=0; c=0;
//marun
if((red > 90)&&(red < 120)&&(green > 80)&&(green < 100)&&(blue > 70)&&(blue < 100)&&(batas == 0)){
lcd_gotoxy(0,3);
lcd_putsf("MAROON");
ok = ok + 1;
batas = 1;
}
if(PIND.3 == 0){
cv = 1;
batas = 0;
delay_ms(500);
lcd_clear();
while(1){
lcd_gotoxy(0,0);
lcd_putsf("FIND GOLD");
if(cv == 1){
printf("lfind.wav\r");
delay_ms(200);
printf("lgold.wav\r");
delay_ms(200);
cv = 2;
}
red_filter();
delay_ms(500);
green_filter();
delay_ms(500);
blue_filter();
delay_ms(500);
a=0; b=0; c=0;
//emas
if((red > 230)&&(red < 26)&&(green > 230)&&(green < 250)&&(blue > 200)&&(blue < 240)&&(batas ==0)){
lcd_gotoxy(0,3);
lcd_putsf("GOLD");
ok = ok + 1;
batas = 1;
}
if(PIND.3 == 0){
cv = 1;
batas = 0;
delay_ms(500);
lcd_clear();
while(1){
lcd_gotoxy(0,0);
lcd_putsf("FIND BROWN");
if(cv == 1){
printf("lfind.wav\r");
delay_ms(200);
printf("lbrown.wav\r");
delay_ms(200);
cv = 2;
}
red_filter();
delay_ms(500);
green_filter();
delay_ms(500);
blue_filter();
delay_ms(500);
a=0; b=0; c=0;
//coklat
if((red > 80)&&(red < 100)&&(green > 70)&&(green < 90)&&(blue > 60)&&(blue < 80)&&(batas == 0)){
lcd_gotoxy(0,3);
lcd_putsf("BROWN");
ok = ok + 1;
batas = 1;
}
if(PIND.3 == 0){
cv = 1;
batas = 0;
delay_ms(500);
lcd_clear();
while(1){
lcd_gotoxy(0,0);
lcd_putsf("FIND ORANGE");
if(cv == 1){
printf("lfind.wav\r");
delay_ms(200);
printf("lorange.wav\r");
delay_ms(200);
cv = 2;
}
red_filter();
delay_ms(500);
green_filter();
delay_ms(500);
blue_filter();
delay_ms(500);
a=0; b=0; c=0;
//orange
if((red > 130)&&(red < 150)&&(green > 110)&&(green < 130)&&(blue > 100)&&(blue < 130)&&(batas == 0)){
lcd_gotoxy(0,3);
lcd_putsf("ORANGE");
ok = ok + 1;
batas = 1;
}
if(PIND.3 == 0){
delay_ms(500);
lcd_clear();
while(1){
lcd_gotoxy(0,0);
lcd_putsf("SCORE= ");
itoa(ok,temp);
lcd_puts(temp);
if(PIND.4 == 0){
delay_ms(500);
ok = 0;
batas = 0;
return;
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
void practice(){
while(1){
red_filter();
delay_ms(500);
green_filter();
delay_ms(500);
blue_filter();
delay_ms(500);
lcd_gotoxy(0,0);
lcd_clear();
sprintf(lcd_buffer,"R:%d G:%d B:%d",red,green,blue);
lcd_puts(lcd_buffer);
a=0; b=0; c=0;
//hijau
if((red > 187)&&(red < 360)&&(green > 162)&&(green < 190)&&(blue > 154)&&(blue < 190)){
lcd_gotoxy(0,3);
lcd_putsf("GREEN");
delay_ms(200);
printf("lgreen.wav\r");
}
//kuning
if((red > 290)&&(red < 320)&&(green > 275)&&(green < 300)&&(blue > 260)&&(blue < 290)){
lcd_gotoxy(0,3);
lcd_putsf("YELLOW");
delay_ms(200);
printf("lyellow.wav\r");
}
//merah
if((red > 100)&&(red < 125)&&(green > 90)&&(green < 110)&&(blue > 90)&&(blue < 110)){
lcd_gotoxy(0,3);
lcd_putsf("RED");
delay_ms(200);
printf("lred.wav\r");
}
//hitam
if((red > 50)&&(red < 110)&&(green > 40)&&(green < 70)&&(blue > 40)&&(blue < 70)){
lcd_gotoxy(0,3);
lcd_putsf("BLACK");
delay_ms(200);
printf("lblack.wav\r");
}
//putih
if((red > 400)&&(red < 440)&&(green > 400)&&(green < 450)&&(blue > 380)&&(blue < 450)){
lcd_gotoxy(0,3);
lcd_putsf("WHITE");
delay_ms(200);
printf("lwhite.wav\r");
}
//orange
if((red > 130)&&(red < 150)&&(green > 110)&&(green < 130)&&(blue > 100)&&(blue < 130)){
lcd_gotoxy(0,3);
lcd_putsf("ORANGE");
delay_ms(200);
printf("lorange.wav\r");
}
//coklat
if((red > 80)&&(red < 100)&&(green > 70)&&(green < 90)&&(blue > 60)&&(blue < 80)){
lcd_gotoxy(0,3);
lcd_putsf("BROWN");
delay_ms(200);
printf("lbrown.wav\r");
}
//biru dongker
if((red > 150)&&(red < 170)&&(green > 130)&&(green < 160)&&(blue > 120)&&(blue < 150)){
lcd_gotoxy(0,3);
lcd_putsf("BLUE NAVY");
delay_ms(200);
printf("lbluenavy.wav\r");
}
//emas
if((red > 230)&&(red < 26)&&(green > 230)&&(green < 250)&&(blue > 200)&&(blue < 240)){
lcd_gotoxy(0,3);
lcd_putsf("GOLD");
delay_ms(200);
printf("lgold.wav\r");
}
//marun
if((red > 90)&&(red < 120)&&(green > 80)&&(green < 100)&&(blue > 70)&&(blue < 100)){
lcd_gotoxy(0,3);
lcd_putsf("MAROON");
delay_ms(200);
printf("lmaroon.wav\r");
}
if(PIND.4==0){
lcd_clear();
return;
}
}
}
void kuis(){
if(zero == 1){
while(1){
lcd_gotoxy(0,0);
lcd_putsf("CARI MERAH");
if(cv == 1){
printf("lcari.wav\r");
delay_ms(200);
printf("lmerah.wav\r");
delay_ms(200);
cv = 2;
}
red_filter();
delay_ms(500);
green_filter();
delay_ms(500);
blue_filter();
delay_ms(500);
a=0; b=0; c=0;
//merah
if((red > 100)&&(red < 125)&&(green > 90)&&(green < 110)&&(blue > 90)&&(blue < 110)&&(batas == 0)){
lcd_gotoxy(0,3);
lcd_putsf("MERAH");
ok = ok + 1;
batas = 1;
}
if(PIND.3 == 0){
cv = 1;
batas = 0;
delay_ms(500);
lcd_clear();
while(1){
lcd_gotoxy(0,0);
lcd_putsf("CARI KUNING");
if(cv == 1){
printf("lcari.wav\r");
delay_ms(200);
printf("lkuning.wav\r");
delay_ms(200);
cv = 2;
}
red_filter();
delay_ms(500);
green_filter();
delay_ms(500);
blue_filter();
delay_ms(500);
a=0; b=0; c=0;
//kuning
if((red > 290)&&(red < 320)&&(green > 275)&&(green < 300)&&(blue > 260)&&(blue < 290)&&(batas==0)){
lcd_gotoxy(0,3);
lcd_putsf("KUNING");
ok = ok + 1;
batas = 1;
}
if(PIND.3 == 0){
cv = 1;
batas = 0;
delay_ms(500);
lcd_clear();
while(1){
lcd_gotoxy(0,0);
lcd_putsf("CARI PUTIH");
if(cv == 1){
printf("lcari.wav\r");
delay_ms(200);
printf("lputih.wav\r");
delay_ms(200);
cv = 2;
}
red_filter();
delay_ms(500);
green_filter();
delay_ms(500);
blue_filter();
delay_ms(500);
a=0; b=0; c=0;
//putih
if((red > 400)&&(red < 440)&&(green > 400)&&(green < 450)&&(blue > 380)&&(blue < 450)&&(batas == 0)){
lcd_gotoxy(0,3);
lcd_putsf("PUTIH");
ok = ok + 1;
batas = 1;
}
if(PIND.3 == 0){
cv = 1;
batas == 0;
delay_ms(500);
lcd_clear();
while(1){
lcd_gotoxy(0,0);
lcd_putsf("CARI HITAM");
if(cv == 1){
printf("lcari.wav\r");
delay_ms(200);
printf("lhitam.wav\r");
delay_ms(200);
cv = 2;
}
red_filter();
delay_ms(500);
green_filter();
delay_ms(500);
blue_filter();
delay_ms(500);
a=0; b=0; c=0;
//hitam
if((red > 50)&&(red < 110)&&(green > 40)&&(green < 70)&&(blue > 40)&&(blue < 70)&&(batas == 0)){
lcd_gotoxy(0,3);
lcd_putsf("HITAM");
ok = ok + 1;
batas = 1;
}
if(PIND.3 == 0){
cv = 1;
batas = 0;
delay_ms(500);
lcd_clear();
while(1){
lcd_gotoxy(0,0);
lcd_putsf("CARI HIJAU");
if(cv == 1){
printf("lcari.wav\r");
delay_ms(200);
printf("lhijau.wav\r");
delay_ms(200);
cv = 2;
}
red_filter();
delay_ms(500);
green_filter();
delay_ms(500);
blue_filter();
delay_ms(500);
a=0; b=0; c=0;
//hijau
if((red > 187)&&(red < 360)&&(green > 162)&&(green < 190)&&(blue > 154)&&(blue < 190)&&(batas == 0)){
lcd_gotoxy(0,3);
lcd_putsf("HIJAU");
ok = ok + 1;
batas = 1;
}
if(PIND.3 == 0){
cv = 1;
batas = 0;
delay_ms(500);
lcd_clear();
while(1){
lcd_gotoxy(0,0);
lcd_putsf("CARI BIRU DONGKER");
if(cv == 1){
printf("lcari.wav\r");
delay_ms(200);
printf("ldongker.wav\r");
delay_ms(200);
cv = 2;
}
red_filter();
delay_ms(500);
green_filter();
delay_ms(500);
blue_filter();
delay_ms(500);
a=0; b=0; c=0;
//biru dongker
if((red > 150)&&(red < 170)&&(green > 130)&&(green < 160)&&(blue > 120)&&(blue < 150)&&(batas == 0)){
lcd_gotoxy(0,3);
lcd_putsf("BIRU DONGKER");
ok = ok + 1;
batas = 1;
}
if(PIND.3 == 0){
cv = 1;
batas = 0;
delay_ms(500);
lcd_clear();
while(1){
lcd_gotoxy(0,0);
lcd_putsf("CARI MARUN");
if(cv == 1){
printf("lcari.wav\r");
delay_ms(200);
printf("lmerah m.wav\r");
delay_ms(200);
cv = 2;
}
red_filter();
delay_ms(500);
green_filter();
delay_ms(500);
blue_filter();
delay_ms(500);
a=0; b=0; c=0;
//marun
if((red > 90)&&(red < 120)&&(green > 80)&&(green < 100)&&(blue > 70)&&(blue < 100)&&(batas == 0)){
lcd_gotoxy(0,3);
lcd_putsf("MARUN");
ok = ok + 1;
batas = 1;
}
if(PIND.3 == 0){
cv = 1;
batas = 0;
delay_ms(500);
lcd_clear();
while(1){
lcd_gotoxy(0,0);
lcd_putsf("CARI EMAS");
if(cv == 1){
printf("lcari.wav\r");
delay_ms(200);
printf("lemas.wav\r");
delay_ms(200);
cv = 2;
}
red_filter();
delay_ms(500);
green_filter();
delay_ms(500);
blue_filter();
delay_ms(500);
a=0; b=0; c=0;
//emas
if((red > 230)&&(red < 26)&&(green > 230)&&(green < 250)&&(blue > 200)&&(blue < 240)&&(batas ==0)){
lcd_gotoxy(0,3);
lcd_putsf("EMAS");
ok = ok + 1;
batas = 1;
}
if(PIND.3 == 0){
cv = 1;
batas = 0;
delay_ms(500);
lcd_clear();
while(1){
lcd_gotoxy(0,0);
lcd_putsf("CARI COKLAT");
if(cv == 1){
printf("lcari.wav\r");
delay_ms(200);
printf("lcoklat.wav\r");
delay_ms(200);
cv = 2;
}
red_filter();
delay_ms(500);
green_filter();
delay_ms(500);
blue_filter();
delay_ms(500);
a=0; b=0; c=0;
//coklat
if((red > 80)&&(red < 100)&&(green > 70)&&(green < 90)&&(blue > 60)&&(blue < 80)&&(batas == 0)){
lcd_gotoxy(0,3);
lcd_putsf("COKLAT");
ok = ok + 1;
batas = 1;
}
if(PIND.3 == 0){
cv = 1;
batas = 0;
delay_ms(500);
lcd_clear();
while(1){
lcd_gotoxy(0,0);
lcd_putsf("CARI ORANGE");
if(cv == 1){
printf("lcari.wav\r");
delay_ms(200);
printf("loranye.wav\r");
delay_ms(200);
cv = 2;
}
red_filter();
delay_ms(500);
green_filter();
delay_ms(500);
blue_filter();
delay_ms(500);
a=0; b=0; c=0;
//orange
if((red > 130)&&(red < 150)&&(green > 110)&&(green < 130)&&(blue > 100)&&(blue < 130)&&(batas == 0)){
lcd_gotoxy(0,3);
lcd_putsf("ORANGE");
ok = ok + 1;
batas = 1;
}
if(PIND.3 == 0){
delay_ms(500);
lcd_clear();
while(1){
lcd_gotoxy(0,0);
lcd_putsf("SCORE= ");
itoa(ok,temp);
lcd_puts(temp);
if(PIND.4 == 0){
delay_ms(500);
ok = 0;
batas = 0;
return;
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
void latihan(){
while(1){
red_filter();
delay_ms(500);
green_filter();
delay_ms(500);
blue_filter();
delay_ms(500);
lcd_gotoxy(0,0);
lcd_clear();
sprintf(lcd_buffer,"R:%d G:%d B:%d",red,green,blue);
lcd_puts(lcd_buffer);
a=0; b=0; c=0;
//hijau
if((red > 187)&&(red < 360)&&(green > 162)&&(green < 190)&&(blue > 154)&&(blue < 190)){
lcd_gotoxy(0,3);
lcd_putsf("HIJAU");
delay_ms(200);
printf("lhijau.wav\r");
}
//kuning
if((red > 290)&&(red < 320)&&(green > 275)&&(green < 300)&&(blue > 260)&&(blue < 290)){
lcd_gotoxy(0,3);
lcd_putsf("KUNING");
delay_ms(200);
printf("lkuning.wav\r");
}
//merah
if((red > 100)&&(red < 125)&&(green > 90)&&(green < 110)&&(blue > 90)&&(blue < 110)){
lcd_gotoxy(0,3);
lcd_putsf("MERAH");
delay_ms(200);
printf("lmerah.wav\r");
}
//hitam
if((red > 50)&&(red < 110)&&(green > 40)&&(green < 70)&&(blue > 40)&&(blue < 70)){
lcd_gotoxy(0,3);
lcd_putsf("HITAM");
delay_ms(200);
printf("lhitam.wav\r");
}
//putih
if((red > 400)&&(red < 440)&&(green > 400)&&(green < 450)&&(blue > 380)&&(blue < 450)){
lcd_gotoxy(0,3);
lcd_putsf("PUTIH");
delay_ms(200);
printf("lputih.wav\r");
}
//orange
if((red > 130)&&(red < 150)&&(green > 110)&&(green < 130)&&(blue > 100)&&(blue < 130)){
lcd_gotoxy(0,3);
lcd_putsf("ORANGE");
delay_ms(200);
printf("loranye.wav\r");
}
//coklat
if((red > 80)&&(red < 100)&&(green > 70)&&(green < 90)&&(blue > 60)&&(blue < 80)){
lcd_gotoxy(0,3);
lcd_putsf("COKLAT");
delay_ms(200);
printf("lcoklat.wav\r");
}
//biru dongker
if((red > 150)&&(red < 170)&&(green > 130)&&(green < 160)&&(blue > 120)&&(blue < 150)){
lcd_gotoxy(0,3);
lcd_putsf("BIRU DONGKER");
delay_ms(200);
printf("ldongker.wav\r");
}
//emas
if((red > 230)&&(red < 26)&&(green > 230)&&(green < 250)&&(blue > 200)&&(blue < 240)){
lcd_gotoxy(0,3);
lcd_putsf("EMAS");
delay_ms(200);
printf("lemas.wav\r");
}
//marun
if((red > 90)&&(red < 120)&&(green > 80)&&(green < 100)&&(blue > 70)&&(blue < 100)){
lcd_gotoxy(0,3);
lcd_putsf("MARUN");
delay_ms(200);
printf("lmerah m.wav\r");
}
if(PIND.4==0){
lcd_clear();
return;
}
}
}
void menuindo(){
while(1){
if(PIND.2 ==0){
ww++;
}
if(ww > 2){
ww=1;
}
if(ww == 1){
lcd_gotoxy(0,0);
lcd_putsf("MENU INDONESIA ");
lcd_gotoxy(0,1);
lcd_putsf("1. LATIHAN <--");
lcd_gotoxy(0,2);
lcd_putsf("2. KUIS ");
delay_ms(1000);
lcd_clear();
}
if(ww == 2){
lcd_gotoxy(0,0);
lcd_putsf("MENU INDONESIA ");
lcd_gotoxy(0,1);
lcd_putsf("1. LATIHAN ");
lcd_gotoxy(0,2);
lcd_putsf("2. KUIS <-- ");
delay_ms(1000);
lcd_clear();
}
if(PIND.4 == 0){
return;
}
if((PIND.3 == 0)&&(ww==1)){
lcd_clear();
latihan();
}
if((PIND.3 == 0)&&(ww==2)){
lcd_clear();
delay_ms(1000);
zero = 1;
kuis();
}
}
}
void menueng(){
while(1){
if(PIND.2 == 0){
ww++;
}
if(ww > 2){
ww = 1;
}
if(ww == 1 ){
lcd_gotoxy(0,0);
lcd_putsf("ENGLISH MENU ");
lcd_gotoxy(0,1);
lcd_putsf("1. PRACTICE <--");
lcd_gotoxy(0,2);
lcd_putsf("2. QUIZ ");
delay_ms(1000);
lcd_clear();
}
if(ww == 2 ){
lcd_gotoxy(0,0);
lcd_putsf("ENGLISH MENU ");
lcd_gotoxy(0,1);
lcd_putsf("1. PRACTICE ");
lcd_gotoxy(0,2);
lcd_putsf("2. QUIZ <--");
delay_ms(1000);
lcd_clear();
}
if(PIND.4 == 0){
return;
}
if((PIND.3 == 0)&&(ww == 2)){
lcd_clear();
delay_ms(1000);
zero = 1;
quizx();
}
if((PIND.3 == 0)&&(ww == 1)){
lcd_clear();
practice();
}
}
}
void main(void)
{
// Declare your local variables here
// Input/Output Ports initialization
// Port A initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTA=0x00;
DDRA=0x00;
// Port B initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTB=0x00;
DDRB=0x00;
// Port C initialization
// Func7=Out Func6=Out Func5=Out Func4=Out Func3=Out Func2=Out Func1=Out Func0=Out
// State7=0 State6=0 State5=0 State4=0 State3=0 State2=0 State1=0 State0=0
PORTC=0x00;
DDRC=0xFF;
// Port D initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=P State3=P State2=P State1=T State0=T
PORTD=0x1C;
DDRD=0x00;
// Timer/Counter 0 initialization
// Clock source: System Clock
// Clock value: Timer 0 Stopped
// Mode: Normal top=0xFF
// OC0 output: Disconnected
TCCR0=0x00;
TCNT0=0x00;
OCR0=0x00;
// Timer/Counter 1 initialization
// Clock source: System Clock
// Clock value: Timer1 Stopped
// Mode: Normal top=0xFFFF
// OC1A output: Discon.
// OC1B output: Discon.
// Noise Canceler: Off
// Input Capture on Falling Edge
// Timer1 Overflow Interrupt: Off
// Input Capture Interrupt: Off
// Compare A Match Interrupt: Off
// Compare B Match Interrupt: Off
TCCR1A=0x00;
TCCR1B=0x00;
TCNT1H=0x00;
TCNT1L=0x00;
ICR1H=0x00;
ICR1L=0x00;
OCR1AH=0x00;
OCR1AL=0x00;
OCR1BH=0x00;
OCR1BL=0x00;
// Timer/Counter 2 initialization
// Clock source: System Clock
// Clock value: Timer2 Stopped
// Mode: Normal top=0xFF
// OC2 output: Disconnected
ASSR=0x00;
TCCR2=0x00;
TCNT2=0x00;
OCR2=0x00;
// External Interrupt(s) initialization
// INT0: Off
// INT1: Off
// INT2: Off
MCUCR=0x00;
MCUCSR=0x00;
// Timer(s)/Counter(s) Interrupt(s) initialization
TIMSK=0x00;
// USART initialization
// Communication Parameters: 8 Data, 1 Stop, No Parity
// USART Receiver: Off
// USART Transmitter: On
// USART Mode: Asynchronous
// USART Baud Rate: 19200
UCSRA=0x00;
UCSRB=0x08;
UCSRC=0x86;
UBRRH=0x00;
UBRRL=0x23;
// Analog Comparator initialization
// Analog Comparator: Off
// Analog Comparator Input Capture by Timer/Counter 1: Off
ACSR=0x80;
SFIOR=0x00;
// ADC initialization
// ADC disabled
ADCSRA=0x00;
// SPI initialization
// SPI disabled
SPCR=0x00;
// TWI initialization
// TWI disabled
TWCR=0x00;
// Alphanumeric LCD initialization
// Connections specified in the
// Project|Configure|C Compiler|Libraries|Alphanumeric LCD menu:
// RS - PORTC Bit 0
// RD - PORTC Bit 1
// EN - PORTC Bit 2
// D4 - PORTC Bit 4
// D5 - PORTC Bit 5
// D6 - PORTC Bit 6
// D7 - PORTC Bit 7
// Characters/line: 16
lcd_init(16);
count=0;
PORTA=0b10011000;
//PORTD.2 = 1;
//PORTD.3 = 1;
//PORTD.4 = 1;
delay_ms(500);
printf("g\r");
delay_ms(500);
printf("t\r");
while (1)
{
// Place your code here
//delay_ms(200);
//printf("labu.wav\r");
if(PIND.2 == 0){
delay_ms(200);
ww++;
}
if(ww > 2){
ww = 1;
}
if(ww == 1){
lcd_clear();
lcd_gotoxy(0,0);
lcd_putsf("1. INDONESIA <-- ");
lcd_gotoxy(0,1);
lcd_putsf("2. ENGLISH");
delay_ms(500);
}
if(ww == 2){
lcd_clear();
lcd_gotoxy(0,0);
lcd_putsf("1. INDONESIA ");
lcd_gotoxy(0,1);
lcd_putsf("2. ENGLISH <--");
delay_ms(500);
}
if((PIND.3 == 0)&&(ww == 1)){
delay_ms(500);
lcd_clear();
ww=1;
menuindo();
}
if((PIND.3 == 0)&&(ww == 2)){
delay_ms(500);
lcd_clear();
ww=1;
menueng();
}
}
}
e. Cara Menggunakan Alat
Cara menggunakan alat ini yaitu hubungkan power supply atau adaptor 12v ke minimum system, kemudian lcd akan menampilkan menu "INDONESIA" dan "ENGLISH", setelah itu pilih salah satu menu tersebut, lakukan kalibrasi sensor pada menu "LATIHAN" setelah itu alat siap digunakan. jangan lupa hubungkan speaker aktif juga ke output WP3A untuk suaranya. dan juga tampilan isi SD card adalah seperti berikut.
No comments:
Post a Comment