#include "LCD4884.h" #include "LCD4884_bmp.h" #include "LCD4884_chinese.h" #include #include "tone.h" //keypad debounce parameter #define DEBOUNCE_MAX 15 #define DEBOUNCE_ON 10 #define DEBOUNCE_OFF 3 #define NUM_KEYS 5 #define RELAYPIN 12 #define BUZZ 10 // joystick number #define LEFT_KEY 0 #define CENTER_KEY 1 #define DOWN_KEY 2 #define RIGHT_KEY 3 #define UP_KEY 4 // menu starting points #define MENU_X 10 #define MENU_Y 0 int adc_key_val[5] ={50, 200, 400, 600, 800 }; boolean btn_inter = false; // debounce counters byte button_count[NUM_KEYS]; // button status - pressed/released byte button_status[NUM_KEYS]; // button on flags for user program byte button_flag[NUM_KEYS]; // menu definition #define NUM_MENU_ITEM 6 char menu_items[NUM_MENU_ITEM][12]={ "1 minute", "2 minute", "3 minute", "5 minute", "7 minute", "10 minute" }; int timer_list[NUM_MENU_ITEM] = { 1,2,3,5,7,10 }; char current_menu_item; void relay(bool sw){ pinMode(RELAYPIN,OUTPUT); digitalWrite(RELAYPIN,sw?LOW:HIGH); //reversed for UV control } /* menu functions */ void init_MENU(void){ byte i; lcd.LCD_clear(); for (i=0; i= NUM_KEYS) k = -1; // No valid key pressed return k; } void update_adc_key(){ int adc_key_in; char key_in; byte i; adc_key_in = analogRead(0); key_in = get_key(adc_key_in); for(i=0; iDEBOUNCE_ON){ if(button_status[i] == 0){ button_flag[i] = 1; button_status[i] = 1; //button debounced to 'pressed' status btn_inter = true; } } } }else{ // no button pressed if (button_count[i] >0){ button_flag[i] = 0; button_count[i]--; if(button_count[i]= 500) //update every 500ms { char buff[12]; if (millis() % 1000 > 500) sprintf(buff,"%02d:%02d",tremain/60,tremain%60); else sprintf(buff,"%02d %02d",tremain/60,tremain%60); lcd.LCD_write_string_big(5, 1, buff, MENU_NORMAL); } } void f_timer_countdown(int mincount){ relay(true); unsigned long millend; millend = millis() + mincount * 60000; byte i; byte key = 0xFF; while (key!= CENTER_KEY){ for(i=0; i= millend) key = CENTER_KEY; f_timer_update((millend-millis())/1000); } relay(false); } void f_timer(int mincount){ char buff[12]; sprintf(buff,"%02d:%02d",mincount,0); lcd.LCD_write_string_big(5, 1, buff, MENU_NORMAL); lcd.LCD_write_string(25, 5, "Timer", MENU_HIGHLIGHT ); f_timer_countdown(mincount); lcd.LCD_draw_bmp_pixel(0,0, DFrobot_bmp, 84,38); lcd.LCD_write_string(20, 5, "Complete", MENU_HIGHLIGHT ); Sakura(); waitfor_OKkey(); } void f_temperature() { lcd.LCD_write_string_big(10, 1, "+12.30", MENU_NORMAL); lcd.LCD_write_string(78, 2, "C", MENU_NORMAL); lcd.LCD_write_string(38, 5, "OK", MENU_HIGHLIGHT ); waitfor_OKkey(); } void f_charmap(){ char i,j; for(i=0; i<5; i++){ for(j=0; j<14; j++){ lcd.LCD_set_XY(j*6,i); lcd.LCD_write_char(i*14+j+32, MENU_NORMAL); } } lcd.LCD_write_string(38, 5, "OK", MENU_HIGHLIGHT ); waitfor_OKkey(); } void f_bitmap(){ lcd.LCD_draw_bmp_pixel(0,0, DFrobot_bmp, 84,24); lcd.LCD_write_chinese(6,3, DFrobot_chinese,12,6,0,0); lcd.LCD_write_string(38, 5, "OK", MENU_HIGHLIGHT ); waitfor_OKkey(); } void f_about(){ lcd.LCD_write_string( 0, 1, "LCD4884 Shield", MENU_NORMAL); lcd.LCD_write_string( 0, 3, "www.DFrobot.cn", MENU_NORMAL); lcd.LCD_write_string(38, 5, "OK", MENU_HIGHLIGHT ); waitfor_OKkey(); } void (*menu_funcs[NUM_MENU_ITEM])(void) = { f_temperature, f_charmap, f_bitmap, f_about }; void setup() { pinMode(BUZZ, OUTPUT); pinMode(RELAYPIN,OUTPUT); digitalWrite(RELAYPIN,HIGH); // setup interrupt-driven keypad arrays // reset button arrays for(byte i=0; i(NUM_MENU_ITEM-1)) current_menu_item = 0; // next item to highlight display lcd.LCD_write_string(MENU_X, MENU_Y + current_menu_item, menu_items[current_menu_item], MENU_HIGHLIGHT ); break; case LEFT_KEY: init_MENU(); current_menu_item = 0; break; case RIGHT_KEY: break; case CENTER_KEY: lcd.LCD_clear(); //(*menu_funcs[current_menu_item])(); f_timer(timer_list[current_menu_item]); lcd.LCD_clear(); init_MENU(); //current_menu_item = 0; break; } btn_inter = false; } } }