void showGames(uint8_t selected) { int i; lcdClear(); lcdPrintln("Games:"); if( gamecount ){ for(i=0;i<gamecount;i++){ if( i==selected ) lcdPrint("*"); else lcdPrint(" "); char buf[9]; memcpy(buf, games[i].gameTitle, 8); buf[8] = 0; lcdPrintln(buf); } }else{ lcdPrint("*No Games"); } lcdRefresh(); }
void ram(void){ int menu = 0; while(true) { lcdClear(); printHeader(); switch(menu) { case MENU_DISK: printDisk(); break; default: break; } lcdDisplay(); getInputWait(); return; /* switch(getInputWaitRelease()){ case BTN_UP: case BTN_DOWN: return; case BTN_LEFT: menu = --menu < 0 ? MENU_MAX : menu; break; case BTN_RIGHT: menu = ++menu > MENU_MAX ? 0 : menu; break; case BTN_ENTER: return; } */ } }
void lcdMainMenu(){// code for main menu in the lcd if (lcdReadButtons(uart1) == LCD_BTN_LEFT && previousLCD != LCD_BTN_LEFT && arbitraryVariable == 0){// if clicked now, and not clicked 20 ms before menuCount--; } else if (lcdReadButtons(uart1) == LCD_BTN_RIGHT && previousLCD != LCD_BTN_RIGHT && arbitraryVariable == 0){ menuCount++; } if (menuCount < 0){ menuCount = maxNumberMenus; } else if (menuCount > maxNumberMenus){ menuCount = 0; } // Main Menu switch(menuCount){ case 0: lcdClear(uart1); lcdSetText(uart1, 1, "750R's LCD"); lcdSetText(uart1, 2 , "Welcome"); subMenuCount = 0; break; case 1: lcdClear(uart1); lcdSetText(uart1, 1 , "Autonomous"); subMenuCount = 1; break; case 2: lcdClear(uart1); lcdSetText(uart1, 1 , "Battery"); subMenuCount = 2; break; case 3: lcdClear(uart1); lcdSetText(uart1, 1 , "Sensors"); subMenuCount = 3; break; case 4: lcdClear(uart1); lcdSetText(uart1, 1 , "Motors"); subMenuCount = 4; break; case 5: lcdClear(uart1); lcdSetText(uart1, 1, "Auton Recorder"); subMenuCount = 5; } }
static void reset() { int i; // setup the screen lcdClear(); for (i=MIN_X; i<MAX_X; i++) { lcdSetPixel(i,MIN_Y,0b000101011); lcdSetPixel(i,MAX_Y,0b000101011); } for (i=MIN_Y; i<MAX_Y; i++) { lcdSetPixel(MIN_X,i,0b000101011); lcdSetPixel(MAX_X,i,0b000101011); } snake.speed = MIN_SPEED; snake.len = 3; snake.dir = 0; snake.t_start = 2; points = 0; // create snake in the middle of the field snake.tail[0].x = SIZE_X/2; snake.tail[0].y = SIZE_Y/2; snake.tail[1].x = SIZE_X/2 +1; snake.tail[1].y = SIZE_Y/2; snake.tail[2].x = SIZE_X/2 +2; snake.tail[2].y = SIZE_Y/2; // print initail tail draw_block(snake.tail[0].x, snake.tail[0].y, 0b00011000); draw_block(snake.tail[1].x, snake.tail[1].y, 0b00011000); draw_block(snake.tail[2].x, snake.tail[2].y, 0b00011000); // switch to level one next_level(); }
void drawCommonThings(int charging) { lcdClear(); lcdNl(); lcdPrintln(" Battery status"); // Draw battery frame. drawHLine(63, 14, 112, 0b00000011); drawHLine(93, 14, 112, 0b00000011); drawVLine(14, 63, 93, 0b00000011); drawVLine(112, 63, 73, 0b00000011); drawVLine(112, 83, 93, 0b00000011); drawHLine(73, 112, 116, 0b00000011); drawHLine(83, 112, 116, 0b00000011); drawVLine(116, 73, 83, 0b00000011); // Print if not charging. lcdSetCrsr(0, 40); if(!charging){ lcdPrintln(" (not charging)"); }; lcdSetCrsr(0, 30); }
void lcdInit( void ) { spiConfig( &pygmyLCD, LCD_CS, LCD_SCK, NONE, LCD_MOSI ); pinConfig( LCD_RESET, OUT ); // We will use USART1_RTS as CS pinConfig( LCD_A0, OUT ); pinSet( LCD_RESET, LOW ); delay( 2000 ); // microseconds pinSet( LCD_RESET, HIGH ); delay( 2000 ); // microseconds lcdWriteCommand( LCD_FUNCSET | LCD_FUNCSET_H ); lcdWriteCommand( LCD_SETVOP | 55 ); lcdWriteCommand( LCD_TEMPCONTROL ); lcdWriteCommand( LCD_BIAS | LCD_BIAS_BS1|LCD_BIAS_BS0 ); lcdWriteCommand( LCD_FUNCSET ); lcdWriteCommand( LCD_DISPCONTROL | LCD_DISPCONTROL_D ); lcdSetBPP( PYGMY_PBM_1BPP ); lcdSetColor( 0xFF, 0xFF, 0xFF ); lcdBackColor( 0x00, 0x00, 0x00 ); lcdClear(); drawAll(); }
static bool screen_overview() { char key = 0; while (key != BTN_ENTER) { lcdClear(); lcdPrintln("Privacy:"); lcdPrintln(levels[(int)GLOBAL(privacy)]); lcdPrintln(""); lcdPrintln("Nickname:"); lcdPrintln(GLOBAL(nickname)); lcdPrintln(""); lcdPrintln("LEFT: cancel"); lcdPrintln("ENTER: OK"); lcdRefresh(); key = getInputWait(); if (key == BTN_LEFT) { //getInputWaitRelease(); return true; } } return false; }
void ram(void) { int dx=0; int dy=0; static uint32_t ctr=0; ctr++; setExtFont(GLOBAL(nickfont)); dx=DoString(0,0,GLOBAL(nickname)); dx=(RESX-dx)/2; if(dx<0) dx=0; dy=(RESY-getFontHeight())/2; lcdClear(); DoString(dx,dy,GLOBAL(nickname)); lcdRefresh(); while(getInputRaw()==BTN_NONE){ delayms_queue_plus(10,0); }; return; }
int saveConfig(void){ FIL file; /* File object */ UINT writebytes; UINT allwrite=0; int res; lcdClear(); res=f_open(&file, CONFFILE, FA_OPEN_ALWAYS|FA_WRITE); lcdPrint("create:"); lcdPrintln(f_get_rc_string(res)); if(res){ return 1; }; CONF_ITER{ res = f_write(&file, &the_config[i].value, sizeof(uint8_t), &writebytes); allwrite+=writebytes; if(res){ lcdPrint("write:"); lcdPrintln(f_get_rc_string(res)); return 1; }; }; lcdPrint("write:"); lcdPrintln(f_get_rc_string(res)); lcdPrint(" ("); lcdPrintInt(allwrite); lcdPrintln("b)"); res=f_close(&file); lcdPrint("close:"); lcdPrintln(f_get_rc_string(res)); if(res){ return 1; }; return 0; };
static int showHighscore() { int key = getInputRaw(); //throw away pending keypress char nick[20]; uint32_t score = 0; highscore_set(points,GLOBAL(nickname)); score = highscore_get(nick); lcdClear(); setTextColor(0xff,0x00); DoString(0,RESY/2-33, " Your Score"); // Display own score in green color, if it's higher than high score, else red if (points > score) { setTextColor(0xff,0b00011100); } else { setTextColor(0xff,0b11100000); } DoString(RESX/2-4, RESY/2-25, IntToStr(points,6,0)); setTextColor(0xff,0x00); DoString(0,RESY/2-10, " Highscore"); setTextColor(0xff,0b11100000); DoString(RESX/2-4, RESY/2-2, IntToStr(score,6,0)); setTextColor(0xff,0x00); DoString(0, RESY/2+18, " UP to play "); DoString(0, RESY/2+26, "DOWN to quit "); lcdDisplay(); while(1) { key = getInputRaw(); if (key&BTN_DOWN) { return 1; } else if (key&BTN_UP) { return 0; } } }
static void _hLoadModelLayout() { if (KEYINIT) mnuMLayout.marked = Config.MixerIndex; if (elementIndex == 0) { if (doMenu(&mnuMLayout)) { lcdClear(); lcdSetPos(3, 18); lcdWriteString_P(strAreYouSure); writeSoftkeys(_skCANCELYES); elementIndex = 1; } } else if (KEY4) // YES { mixerLoadModel(mnuMLayout.marked); //configSave(); loadPage(PAGE_SHOW_LAYOUT); } }
void f_recv(void){ __attribute__ ((aligned (4))) uint8_t buf[32]; int len; do{ lcdClear(); len=nrf_rcv_pkt_time_encr(1000,sizeof(buf),buf,enctoggle?testkey:NULL); if(len==0){ lcdPrintln("No pkt (Timeout)"); }; lcdPrint("Size:");lcdPrintInt(len);lcdNl(); lcdPrint("1:");lcdPrintIntHex( *(int*)(buf+ 0) ); lcdNl(); lcdPrint("2:");lcdPrintIntHex( *(int*)(buf+ 4) ); lcdNl(); lcdPrint("3:");lcdPrintIntHex( *(int*)(buf+ 8) ); lcdNl(); lcdPrint("4:");lcdPrintIntHex( *(int*)(buf+12) ); lcdNl(); len=crc16(buf,14); lcdPrint("crc:");lcdPrintShortHex(len); lcdNl(); lcdDisplay(); }while ((getInputRaw())==BTN_NONE); };
void spectrum_callback(uint8_t* buf, int bufLen) { TOGGLE(LED2); if (displayMode == MODE_SPECTRUM) lcdClear(); else if (displayMode == MODE_WATERFALL) lcdShift(0,1,0); for(int i = 0; i < 128; i++) // display 128 FFT magnitude points { // FFT unwrap: uint8_t v; if(i < 64) // negative frequencies v = buf[(bufLen/2)+64+i]; else // positive frequencies v = buf[i-64]; // fill display if (displayMode == MODE_SPECTRUM) { for(int j = 0; j < (v/2); j++) lcdBuffer[i+RESX*(RESY-j)] = 0x00; } else if (displayMode == MODE_WATERFALL) { lcdSetPixel(i,RESY-1,v); } } // text info lcdSetCrsr(0,0); lcdPrint("f="); lcdPrint(IntToStr(freq/1000000,4,F_LONG)); lcdPrintln("MHz "); lcdPrintln("-5MHz 0 +5MHz"); lcdDisplay(); }
void ram(void) { struct NRF_CFG config; uint8_t buf[16]; config.nrmacs=1; config.maclen[0] = 16; config.channel = 81; memcpy(config.mac0, "\x01\x02\x03\x02\x01", 5); nrf_config_set(&config); lcdClear(); lcdPrintln("People nearby:"); //lcdPrint("nearby:"); lcdRefresh(); do{ if( nrf_rcv_pkt_time(64,sizeof(buf),buf) == 16 ){ buf[14] = 0; if( buf[1] == 0x23 || buf[1] == 0x24){ lcdPrintln((char*)(buf+6)); //lcdPrintln("foo"); } lcdRefresh(); } }while ((getInputRaw())==BTN_NONE); }
static void mainloop(void) { int dx=0; int dy=0; setExtFont(GLOBAL(nickfont)); dx=DoString(0,0,GLOBAL(nickname)); dx=(RESX-dx)/2; if(dx<0) dx=0; dy=(RESY-getFontHeight())/2; lcdClear(); lcdSetPixel(1,1,1); DoString(dx,dy,GLOBAL(nickname)); lcdRefresh(); lk_ticks = 0; lk_button_mode = 0x00; lk_ls0 = 0x00; lk_ls1 = 0x00; lk_ls2 = 0x00; lk_ls3 = 0x00; lk_in0 = 0x00; lk_in1 = 0x00; lk_ticks = 0x0000; lk_piezo_toggle = 0x00; while(getInputRaw()==BTN_NONE){ tick_lilakit(); melody_play(); //delayms_queue(10); //XXX: this hangs the badge. delayms(10); } return; }
//# MENU antenna void antenna_main() { frequency=(int64_t)input_int("Frequency:",(int)(frequency/1000000),50,4000,4)*1000000; lcdClear(); lcdSetCrsr(0,0); lcdPrintln("Antenna Frequency"); lcdNl(); lcdPrint(" "); lcdPrint(IntToStr(frequency/1000000,4,F_LONG)); lcdPrintln(" MHz "); lcdNl(); lcdPrintln("Antenna Length"); float meter = SPEEDOFLIGHT/frequency; lcdNl(); lcdPrint(" "); lcdPrint(IntToStr(meter * 1000, 4, F_LONG )); lcdPrint(" mm"); lcdNl(); lcdPrint(" "); lcdPrint(IntToStr(meter * 1000 / 2, 4, F_LONG )); lcdPrint(" mm"); lcdNl(); lcdPrint(" "); lcdPrint(IntToStr(meter * 1000 / 4, 4, F_LONG )); lcdPrint(" mm"); lcdDisplay(); getInputWaitRepeat(); }
static bool gameover_scene() { int dy = getFontHeight(); int s1x = DoString(0, 0, "GAME OVER!"); s1x = (RESX-s1x)/2; int s2x = DoString(0, 0, "HIGHTSCORE!"); s2x = (RESX-s2x)/2; gpioSetValue(RB_SPI_SS0, 0); gpioSetValue(RB_SPI_SS1, 0); gpioSetValue(RB_SPI_SS2, 0); gpioSetValue(RB_SPI_SS3, 0); gpioSetValue(RB_SPI_SS4, 0); gpioSetValue(RB_SPI_SS5, 0); char key = 0; while(key != BTN_UP && key != BTN_DOWN) { lcdClear(); if(highscore_set(game.scroll_pos / 15, GLOBAL(nickname))) DoString (s2x, dy, "HIGHSCORE!"); else DoString(s1x, dy, "GAME OVER!"); int x = DoInt(0, 3*dy, game.scroll_pos / 15); DoChar(x, 3*dy, 'm'); DoString(0, 5*dy, "UP to play"); DoString(0, 6*dy, "DOWN to quit"); lcdDisplay(); key = getInputWaitTimeout(5000); } return !(key==BTN_DOWN); }
void ram(void) { char pw[PW_LEN+1]; uint16_t k[8]; int button; memset(k, 0, 16); while(1){ lcdClear(); lcdNl(); lcdPrintln(" password"); lcdPrintln(" generator"); lcdNl(); lcdNl(); pw_set(pw,k); pw_cleanup(pw); lcdPrint(" "); lcdPrintln(pw); lcdRefresh(); delayms(23); while((button=getInputRaw())==BTN_NONE) delayms(23); if(button==BTN_LEFT) return; } }
int main() { AdcChannel channel[] = { ADC_BATTERY_VOLTAGE, ADC_WHITE_LINE1, ADC_WHITE_LINE2, ADC_WHITE_LINE3, ADC_IR_PROXIMITY1, ADC_IR_PROXIMITY2, ADC_IR_PROXIMITY3, ADC_IR_PROXIMITY4, ADC_IR_PROXIMITY5, ADC_IR_RANGE1, ADC_IR_RANGE2, ADC_IR_RANGE3, ADC_IR_RANGE4, ADC_IR_RANGE5, ADC_SERVO_POD1, ADC_SERVO_POD1, ADC_LAST }; char strChannel[17][20] = { "ADC_BATTERY_VOLTAGE", "ADC_WHITE_LINE1", "ADC_WHITE_LINE2", "ADC_WHITE_LINE3", "ADC_IR_PROXIMITY1", "ADC_IR_PROXIMITY2", "ADC_IR_PROXIMITY3", "ADC_IR_PROXIMITY4", "ADC_IR_PROXIMITY5", "ADC_IR_RANGE1", "ADC_IR_RANGE2", "ADC_IR_RANGE3", "ADC_IR_RANGE4", "ADC_IR_RANGE5", "ADC_SERVO_POD1", "ADC_SERVO_POD2", "ADC_LAST" }; char buf[17]; UINT value, idx; initAdc(); initLcd(); for(idx = 0; idx < (sizeof(channel)/sizeof(channel[0])); idx ++) { lcdClear(); lcdCursor(1,1); lcdString(strChannel[idx]); lcdCursor(2,1); if(getAdcValue(channel[idx], &value) == STATUS_OK) { snprintf(buf, sizeof(buf), "%d", value); lcdString(buf); } else { lcdString("Error"); } _delay_ms(DELAY_COUNT); } return 0; }
void pre_auton() { // Set bStopTasksBetweenModes to false if you want to keep user created tasks running between // Autonomous and Tele-Op modes. You will need to manage all user created tasks if set to false. bStopTasksBetweenModes = true; // All activities that occur before the competition starts // Example: clearing encoders, setting servo positions, ... short leftButton = 1; short centerButton = 2; short rightButton = 4; int choice1; int choice2; bLCDBacklight = true; /* Press and hold any LCD button BEFORE turning on robot * to enter autonomus selection mode. * If LCD buttons are not pressed (or LCD is not plugged in) * the default autonomous will run. */ bool inMenu = nLCDButtons; while(inMenu) { lcdClear(); char* c = "\tChoice 1\nBLU\tDiag\tRED"; lcd_printf(c); int code = lcdWaitForBtnClick(); if (code==leftButton) { choice1=0b00; } if (code==rightButton) { choice1=0b01; } if (code==centerButton) { diag(); lcdClear(); c="\tChoice 1\nBLU\tDiag\tRED"; continue; } lcdClear(); lcd_printf("\tChoice 2\nAuto\tBack\tPole"); code = lcdWaitForBtnClick(); // Display menu 2 if (code==leftButton) { choice2=0b00; } if (code==rightButton) { choice2=0b10; } if (code==centerButton) { continue; } Program = choice1 + choice2; while(1) { lcdClear(); switch (Program) { case BLU_AUTO: lcd_printf("\tBLU Auto\nDiag\tOK\tBack"); break; case RED_AUTO: lcd_printf("\tRED Auto\nDiag\tOK\tBack"); break; case BLU_POLE: lcd_printf("\tBLU Pole\nDiag\tOK\tBack"); break; case RED_POLE: lcd_printf("\tRED Pole\nDiag\tOK\tBack"); break; } code = lcdWaitForBtnClick(); if(code==centerButton) { inMenu=false; break; } else if (code==leftButton) diag(); else break; } // while(1) } // while(inMenu) //claw(false); lcdClear(); }
int main() { int G = 0, keyInterval = 1; float rms, power = 0, setPower = 3.0; unsigned char keyBuf; bool adRefresh = true, pwrValueRefresh = true, gainValueRefresh = true; bool enAGC = true, atLimit = false; // isAdj = false; lcdInit(); ec11Init(); adInit(); lcdBacklit(true); lcdPrintStr("Design: CX Wang"); lcdLocate(2, 1); lcdPrintStr("Initializing.."); idelay_s(5); lcdClear(); for(;;) { if(pwrValueRefresh || gainValueRefresh) { /* * Display */ lcdWrite(0x0c,0,1); // Turn cursor off if(pwrValueRefresh) { pwrValueRefresh = false; lcdLocate(1, 0); lcdPrintStr("PWR: "); if(power < 9.94) lcdPrintFloat(power + 0.05, 3, 1); //For rounding else lcdPrintStr(">10"); lcdPrintStr("W"); if(enAGC) { lcdPrintStr("/"); lcdPrintFloat(setPower, 3, 1); lcdPrintStr("W"); } } if(gainValueRefresh) { gainValueRefresh = false; lcdLocate(0, 1); lcdPrintStr("Gain: "); lcdPrintInt(G, 4); if(G == 0 || G == 1023 * ADNUM) { lcdLocate(15, 1); lcdPrintStr("*"); atLimit = true; } else if(atLimit) { atLimit = false; lcdLocate(15, 1); lcdPrintStr(" "); } } if(enAGC) lcdLocate(15, 0); else lcdLocate(10, 1); lcdWrite(0x0e,0,1); // Turn cursor on } /* * Adjustment */ rms = (float)adcRead(0) * 10.0 / 1024.0; power = rms * rms / 8.0; if(enAGC) { if(power < setPower) { G += fabs(power - setPower) * 10;//imax(1, fabs(power - setPower) * 10); if(G > 1023 * ADNUM) G = 1023 * ADNUM; adRefresh = true; gainValueRefresh = pwrValueRefresh = true; // isAdj = true; } else if(power > setPower + 0.02) { /* Ensure precision for power higher than 0.4watt and reduce oscillation * got x1.03 retired */ G -= fabs(power - setPower) * 10;//imax(1, fabs(power - setPower) * 10); if(G < 0) G = 0; adRefresh = true; gainValueRefresh = pwrValueRefresh = true; // isAdj = true; } else if(setPower < 0.05) { G = 0; adRefresh = true; gainValueRefresh = pwrValueRefresh = true; } // else if(isAdj) { // isAdj = false; // pwrValueRefresh = pwrValueRefresh = true; // } } else if(fabs(power - setPower) > 0.05){ setPower = power; if(setPower > 7.50) setPower = 7.50; pwrValueRefresh = true; } if(adRefresh) { adRefresh = false; adSetGain(G); } if((keyBuf = ec11Check()) == 2) { if(enAGC) { setPower += 0.10; if(setPower > 7.50) setPower = 7.50; pwrValueRefresh = true; } else { G += keyLevel(keyInterval); if(G > 1023 * ADNUM) G = 1023 * ADNUM; gainValueRefresh = adRefresh = true; if(keyInterval < 1000) keyInterval += 50; } } else if(keyBuf == 1) { if(enAGC) { setPower -= 0.10; if(setPower < 0) setPower = 0; pwrValueRefresh = true; } else { G -= keyLevel(keyInterval); if(G < 0) G = 0; gainValueRefresh = adRefresh = true; if(keyInterval < 1000) keyInterval += 50; } } else if(keyBuf & 0b100) { enAGC = !enAGC; lcdClear(); pwrValueRefresh = gainValueRefresh = true; } if(keyInterval > 1) keyInterval--; } }
int main() { int n; int c=0; int lcd; char ch[128]; int fd_port; int p; int spo2; char read_buf[20]; fd_port = open_serial(); // 장치 초기화 및 열기 if(wiringPiSetup()==-1) return 1; pinMode(LED1, OUTPUT); pinMode(LED2, OUTPUT); pinMode(LED3, OUTPUT); lcd= lcdInit(2,16,4,6,5,4,0,2,3,0,0,0,0); sleep(1); lcdPosition(lcd,0,0); lcdPrintf(lcd,"WElCOME!!"); delay(1000); lcdPosition(lcd,0,1); lcdPrintf(lcd,"Your Finger Test"); delay(1500); lcdClear(lcd); lcdPosition(lcd,0,0); lcdPrintf(lcd,"Loading "); delay(900); lcdPosition(lcd,0,0); lcdPrintf(lcd,"Loading. "); delay(900); lcdPosition(lcd,0,0); lcdPrintf(lcd,"Loading.. "); delay(900); lcdPosition(lcd,0,0); lcdPrintf(lcd,"Loading... "); delay(900); lcdPosition(lcd,0,0); lcdPrintf(lcd,"Loading. "); delay(900); lcdPosition(lcd,0,0); lcdPrintf(lcd,"Loading.. "); delay(900); lcdPosition(lcd,0,0); lcdPrintf(lcd,"Loading... "); delay(900); lcdPosition(lcd,0,0); lcdPrintf(lcd,"Loading. "); delay(900); lcdPosition(lcd,0,0); lcdPrintf(lcd,"Loading.. "); delay(900); lcdPosition(lcd,0,1); lcdPrintf(lcd,"S"); delay(700); lcdPosition(lcd,0,1); lcdPrintf(lcd,"ST"); delay(700); lcdPosition(lcd,0,1); lcdPrintf(lcd,"STA"); delay(700); lcdPosition(lcd,0,1); lcdPrintf(lcd,"STAR"); delay(700); lcdPosition(lcd,0,1); lcdPrintf(lcd,"START"); delay(1200); while (1) { n=read(fd_port,ch, sizeof(ch)); p=atoi(ch); printf("문자->%s 변환->%d", ch,p); lcdClear(lcd); lcdPosition(lcd,0,0); lcdPrintf(lcd,"Handle Test!"); lcdPosition(lcd,0,1); lcdPrintf(lcd,"Pitch>%d",p); if(p<70) { digitalWrite(LED3,1); digitalWrite(LED2,0); digitalWrite(LED1,0); } else if(p<88){ digitalWrite(LED3,0); digitalWrite(LED2,1); digitalWrite(LED1,0); } else { c++; digitalWrite(LED3,0); digitalWrite(LED2,0); digitalWrite(LED1,1); if(c>5){ lcdClear(lcd); lcdPosition(lcd,0,0); lcdPrintf(lcd,"Congratulation"); lcdPosition(lcd,0,1); lcdPrintf(lcd,"Pitch>%d Cure!!",p); break; } } // delay(1); } close(fd_port); // 장치 닫기 return 0; }
__interrupt void watchdog_timer(void) { int x = debounceSwitch(); switch(alarm_state) { case(0): lcdSetText("ALARM NOT SET",0,0); if((x == BIT7) && prevState == 0x0000){//if the left button is pressed in state 0, begin setting the alarm alarm_state = 1; lcdClear(); lcdSetText("Set Hour:",0,0); lcdSetText(text,0,1); } break; case(1): if(x == BIT5 && prevState ==0x0000){//press the right button to increment the hours text[1] ++; if(text[1] == '0' + 10 ||(text[0] =='2' && text[1] == '5')) text[1] = '0'; if(text[1]=='0') text[0]++; if(text[0] == '3') text[0] = '0'; }else if(x == BIT7 && prevState ==0x000){ //press the left button to switch to setting the minutes alarm_state = 2; lcdClear(); lcdSetText("Set Minute:",0,0); } lcdSetText(text,0,1); break; case(2): if(x == BIT5 && prevState ==0x0000){//press the right button to increment the minutes text[4] ++; if(text[4] == '0' + 10) text[4] = '0'; if(text[4]=='0') text[3]++; if(text[3] == '7') text[3] = '0'; }else if(x == BIT7 && prevState ==0x000){ //press the left button to set the alarm serialWrite('r'); lcdClear(); lcdSetText("ALARM SET:",0,0); alarm_state = 3; } lcdSetText(text,0,1); break; case(3): if(x == BIT7 && prevState ==0x0000){ // if waiting for alarm and want reset, transmit S character serialWrite('S'); alarm_state = 0; lcdClear(); lcdSetText("ALARM NOT SET",0,0); } break; case(4): if(x == BIT7 && prevState ==0x0000){// if alarm going off and want reset, transmit o character and turn off alarm serialWrite('o'); TA0CCR1 = 0; alarm_state = 0; lcdClear(); lcdSetText("ALARM NOT SET",0,0); } break; } }
//# MENU lcd void lcd_menu() { getInputWaitRelease(); lcdClear(); lcdPrintln("LCD:"); lcdDisplay(); ON(LED1); uint16_t x,y; uint8_t rgb=0; uint8_t ct=0x3a; uint16_t rgba[]= { RGB(0xff,0,0), RGB(0,0xff,0), RGB(0,0,0xff), RGB(0,0xff,0xff),RGB(0xff,0,0xff),RGB(0xff,0xff,0), RGB(0xff,0xff,0xff),0 }; while(1) { switch(getInputWaitRepeat()) { case BTN_DOWN: lcd_select(); lcdWrite(TYPE_CMD,0x3a); lcdWrite(TYPE_DATA,5); lcdWrite(TYPE_CMD,0x2C); for (y=0; y<128; y++) { for (x=0; x<RESX; x++) { if (x<20) { if(y<64) { PIX(0xff,(0xff-(0xff&(y<<2))),(0xff-(0xff&(y<<2)))); } else { PIX((0xff-(0xff&(y<<2))),0,0); }; } else if (x <40) { if(y<64) { PIX((0xff-(0xff&(y<<2))),0xff,(0xff-(0xff&(y<<2)))); } else { PIX(0,(0xff-(0xff&(y<<2))),0); }; } else if (x <60) { if(y<64) { PIX((0xff-(0xff&(y<<2))),(0xff-(0xff&(y<<2))),0xff); } else { PIX(0,0,(0xff-(0xff&(y<<2)))); }; } else if (x <80) { if(y<64) { PIX(((0xff&(y<<2))),0,0); } else { PIX(0xff,((0xff&(y<<2))),((0xff&(y<<2)))); }; } else if (x <100) { if(y<64) { PIX(0,((0xff&(y<<2))),0); } else { PIX(((0xff&(y<<2))),0xff,((0xff&(y<<2)))); }; } else if (x <120) { if(y<64) { PIX(0,0,((0xff&(y<<2)))); } else { PIX(((0xff&(y<<2))),((0xff&(y<<2))),0xff); }; } else { PIX(0,0,0); } }; }; for (y=128; y<RESY; y++) { for (x=0; x<RESX; x++) { PIX(0,0,0); }; }; lcd_deselect(); break; case BTN_LEFT: ct--; lcd_select(); lcdWrite(TYPE_CMD,0x25); lcdWrite(TYPE_DATA, ct); lcd_deselect(); break; case BTN_RIGHT: ct++; lcd_select(); lcdWrite(TYPE_CMD,0x25); lcdWrite(TYPE_DATA, ct); lcd_deselect(); break; case BTN_UP: lcd_select(); lcdWrite(TYPE_CMD,0x3a); lcdWrite(TYPE_DATA,5); lcdWrite(TYPE_CMD,0x2C); if(rgb==0) { for (y=0; y<RESY; y++) { for (x=0; x<RESX; x++) { if(x==0 || x==RESX-1 || y==0 || y==RESY-1) { PIX(0xff,0,0); } else if(x==1 || x==RESX-2 || y==1 || y==RESY-2) { PIX(0xff,0xff,0); } else if(x==2 || x==RESX-3 || y==2 || y==RESY-3) { PIX(0,0,0xff); } else { PIX(0xff,0xff,0xff); }; }; }; } else { for (y=0; y<RESY; y++) { for (x=0; x<RESX; x++) { lcdWrite(TYPE_DATA,rgba[rgb-1]>>8); lcdWrite(TYPE_DATA,rgba[rgb-1]&0xff); }; }; }; lcd_deselect(); rgb=(rgb+1)%(1+(sizeof(rgba)/sizeof(*rgba))); break; case BTN_ENTER: lcd_select(); lcdWrite(TYPE_CMD,0x3a); lcdWrite(TYPE_DATA,2); lcd_deselect(); return; }; getInputWaitRelease(); }; };
//# MENU img void img_menu() { char filename[FLEN]; FATFS FatFs; FRESULT res; int ct=0x3a; lcdClear(); lcdPrintln("Image"); lcdPrintln("up: 16bit"); lcdPrintln("down: 12bit"); lcdPrintln("l/r: contrast"); lcdDisplay(); getInputWaitRelease(); while(1){ switch(getInput()){ case BTN_UP: lcd_select(); lcdWrite(TYPE_CMD,0x3a); lcdWrite(TYPE_DATA,2); lcd_deselect(); getInputWaitRelease(); if(selectFile(filename,"L16")){ lcdPrintln("Select ERROR"); lcdDisplay(); getInputWait(); return; }; lcd_select(); lcdWrite(TYPE_CMD,0x3a); lcdWrite(TYPE_DATA,5); lcd_deselect(); do_image(filename); break; case BTN_DOWN: lcd_select(); lcdWrite(TYPE_CMD,0x3a); lcdWrite(TYPE_DATA,2); lcd_deselect(); getInputWaitRelease(); if(selectFile(filename,"LCD")){ lcdPrintln("Select ERROR"); lcdDisplay(); getInputWait(); return; }; lcd_select(); lcdWrite(TYPE_CMD,0x3a); lcdWrite(TYPE_DATA,3); lcd_deselect(); do_image(filename); break; case BTN_LEFT: ct-=1; lcd_select(); lcdWrite(TYPE_CMD,0x25); lcdWrite(TYPE_DATA, ct); lcd_deselect(); break; case BTN_RIGHT: ct+=1; lcd_select(); lcdWrite(TYPE_CMD,0x25); lcdWrite(TYPE_DATA, ct); lcd_deselect(); break; case BTN_ENTER: lcd_select(); lcdWrite(TYPE_CMD,0x3a); lcdWrite(TYPE_DATA,2); lcd_deselect(); return; }; }; };
void main(void) { char msgA[] = {0x49, 0x20, 0x4C, 0x6F, 0x76, 0x65, 0x20, 0x38, 0x30, 0x35, 0x31, 0}; char msgB[] = {'I', ' ', 'L', 'o', 'v', 'e', ' ', '8', '0', '5', '1', 0}; char msgC[] = "I Love 8051"; char msgD[] = "Hello World!"; lcdClear(); lcdWriteCmd(0x0F); // Display: ON, Cursor: ON, Blink: ON lcdWriteCmd(0x38); // 8-bit, 2 lines, 5x7 font lcdWriteCmd(0x06); // Input mode: Increment, Non-shift lcdWriteString(msgC); lcdSelectRow(1); // lcdWriteCmd(0x80 | 0x40); lcdWriteString(msgD); // for (n=0; *(msgD+n)!=0; n++) // { // lcdWriteData( *(msgD+n) ); // } // for (n=0; msgD[n]!=0; n++) // { // lcdWriteData( msgD[n] ); // } // for (n=0; n<11; n++) // { // lcdWriteData( msgB[n] ); // } // lcdWriteData('I'); // lcdWriteData(' '); // lcdWriteData('L'); // lcdWriteData('o'); // lcdWriteData('v'); // lcdWriteData('e'); // lcdWriteData(' '); // lcdWriteData('8'); // lcdWriteData('0'); // lcdWriteData('5'); // lcdWriteData('1'); // // lcdWriteData(0x7E); // lcdWriteData(0xF6); // lcdWriteData('3'); // lcdWriteData(0xFA); // lcdWriteData(0xFB); // lcdWriteData(0x49); // " I " // lcdWriteData(0x20); // " " // lcdWriteData(0x4C); // " L " // lcdWriteData(0x6F); // " o " // lcdWriteData(0x76); // " v " // lcdWriteData(0x65); // " e " // lcdWriteData(0x20); // " " // lcdWriteData(0x38); // " 8 " // lcdWriteData(0x30); // " 0 " // lcdWriteData(0x35); // " 5 " // lcdWriteData(0x31); // " 1 " for (;;); }/* main */
int main() { MotorDirection dirs[] = {FORWARD, BACKWARD, RIGHT, LEFT, SOFT_RIGHT, SOFT_LEFT, SOFT_RIGHT2, SOFT_LEFT2, STOP}; char strDirs[9][16] = {"FORWARD", "BACKWARD", "RIGHT", "LEFT", "SOFT_RIGHT", "SOFT_LEFT", "SOFT_RIGHT2", "SOFT_LEFT2", "STOP"}; int idx; initMotor(); initLcd(); #if 0 /* Test #1: Check direction */ motorVelocitySet(255, 255); for(idx = 0; idx < (sizeof(dirs)/sizeof(dirs[0])); idx ++) { lcdClear(); lcdCursor(1,1); lcdString(strDirs[idx]); _delay_ms(DELAY_COUNT*2); motorDirectionSet(dirs[idx]); /* Delay for some time */ _delay_ms(DELAY_COUNT); motorDirectionSet(STOP); } /* Test #2: Check speed */ lcdClear(); lcdCursor(1,1); lcdString("Speed : "); lcdCursor(2,1); lcdString("L 100, R 100"); _delay_ms(DELAY_COUNT*2); motorVelocitySet(100, 100); motorDirectionSet(FORWARD); /* Delay for some time */ _delay_ms(DELAY_COUNT); motorDirectionSet(STOP); /* Test #3: Check individual wheel speed (L < R) */ lcdClear(); lcdCursor(1,1); lcdString("Speed : "); lcdCursor(2,1); lcdString("L 100, R 255"); _delay_ms(DELAY_COUNT*2); motorVelocitySet(100, 255); /* Left turn expected */ motorDirectionSet(FORWARD); /* Delay for some time */ _delay_ms(DELAY_COUNT); motorDirectionSet(STOP); /* Test #4: Check individual wheel speed (L > R) */ lcdClear(); lcdCursor(1,1); lcdString("Speed : "); lcdCursor(2,1); lcdString("L 255, R 100"); _delay_ms(DELAY_COUNT*2); motorVelocitySet(255, 100); /* Right turn expected */ motorDirectionSet(FORWARD); /* Delay for some time */ _delay_ms(DELAY_COUNT); motorDirectionSet(STOP); /* Test #5: Check left position encoder */ motorLeftPositionEncoderInit(leftPosEncoderIsr); lPosCount = 100; motorVelocitySet(255, 255); motorDirectionSet(FORWARD); #endif /* Test #6: Check orientation */ motorLeftPositionEncoderInit(leftPosEncoderIsr); lPosCount = 23; motorVelocitySet(150, 150); motorDirectionSet(LEFT); while(1); return 0; }
int main (int argc, char *argv[]) { int i ; int lcd ; int bits, rows, cols ; struct tm *t ; time_t tim ; char buf [32] ; if (argc != 4) return usage (argv [0]) ; printf ("Raspberry Pi LCD test\n") ; printf ("=====================\n") ; bits = atoi (argv [1]) ; cols = atoi (argv [2]) ; rows = atoi (argv [3]) ; if (!((rows == 1) || (rows == 2) || (rows == 4))) { fprintf (stderr, "%s: rows must be 1, 2 or 4\n", argv [0]) ; return EXIT_FAILURE ; } if (!((cols == 16) || (cols == 20))) { fprintf (stderr, "%s: cols must be 16 or 20\n", argv [0]) ; return EXIT_FAILURE ; } wiringPiSetup () ; if (bits == 4) lcdHandle = lcdInit (rows, cols, 4, 11,10, 4,5,6,7,0,0,0,0) ; else lcdHandle = lcdInit (rows, cols, 8, 11, 10, 0,1,2,3,4,5,6,7) ; if (lcdHandle < 0) { fprintf (stderr, "%s: lcdInit failed\n", argv [0]) ; return -1 ; } lcdPosition (lcdHandle, 0, 0) ; lcdPuts (lcdHandle, "Gordon Henderson") ; lcdPosition (lcdHandle, 0, 1) ; lcdPuts (lcdHandle, " wiringpi.com ") ; waitForEnter () ; if (rows > 1) { lcdPosition (lcdHandle, 0, 1) ; lcdPuts (lcdHandle, " wiringpi.com ") ; if (rows == 4) { lcdPosition (lcdHandle, 0, 2) ; for (i = 0 ; i < ((cols - 1) / 2) ; ++i) lcdPuts (lcdHandle, "=-") ; lcdPuts (lcdHandle, "=3") ; lcdPosition (lcdHandle, 0, 3) ; for (i = 0 ; i < ((cols - 1) / 2) ; ++i) lcdPuts (lcdHandle, "-=") ; lcdPuts (lcdHandle, "-4") ; } } waitForEnter () ; lcdCharDef (lcdHandle, 2, newChar) ; lcdClear (lcdHandle) ; lcdPosition (lcdHandle, 0, 0) ; lcdPuts (lcdHandle, "User Char: ") ; lcdPutchar (lcdHandle, 2) ; lcdCursor (lcdHandle, TRUE) ; lcdCursorBlink (lcdHandle, TRUE) ; waitForEnter () ; lcdCursor (lcdHandle, FALSE) ; lcdCursorBlink (lcdHandle, FALSE) ; lcdClear (lcdHandle) ; for (;;) { scrollMessage (0, cols) ; if (rows == 1) continue ; tim = time (NULL) ; t = localtime (&tim) ; sprintf (buf, "%02d:%02d:%02d", t->tm_hour, t->tm_min, t->tm_sec) ; lcdPosition (lcdHandle, (cols - 8) / 2, 1) ; lcdPuts (lcdHandle, buf) ; if (rows == 2) continue ; sprintf (buf, "%02d/%02d/%04d", t->tm_mday, t->tm_mon + 1, t->tm_year+1900) ; lcdPosition (lcdHandle, (cols - 10) / 2, 2) ; lcdPuts (lcdHandle, buf) ; pingPong (lcd, cols) ; } return 0 ; }
void autonSelectMenu() { lcdSetBacklight(uart1, true); while (button != LCD_BTN_CENTER) { lcdClear(uart1); lcdSetText(uart1, 1, "Alliance Color?"); lcdSetText(uart1, 2, "< Red Blue >"); button = getLcdButtons(); if (button == LCD_BTN_LEFT) { lcdClear(uart1); lcdSetText(uart1, 1, "Starting Side?"); lcdSetText(uart1, 2, "< Middle Hang >"); while (button != LCD_BTN_LEFT || button != LCD_BTN_RIGHT) { button = getLcdButtons(); // Red Middle if (button == LCD_BTN_LEFT) { int screen = 0; int minScreen = 0; int maxScreen = 4; lcdClear(uart1); while (button != LCD_BTN_CENTER) { switch (screen) { case 0: lcdSetText(uart1, 1, "auton one"); break; case 1: lcdSetText(uart1, 1, "auton two"); break; case 2: lcdSetText(uart1, 1, "auton three"); break; case 3: lcdSetText(uart1, 1, "auton four"); break; } button = getLcdButtons(); if (button == LCD_BTN_RIGHT) { if (++screen > maxScreen) screen = minScreen; } else if (button == LCD_BTN_LEFT) { if (--screen < minScreen) screen = maxScreen; } } autonSelection = screen; lcdSetText(uart1, 1, " AUTONOMOUS"); lcdSetText(uart1, 2, " SET"); taskDelay(400); return; } // Red Hang if (button == LCD_BTN_RIGHT) { int screen = 0; int minScreen = 0; int maxScreen = 4; lcdClear(uart1); while (button != LCD_BTN_CENTER) { switch (screen) { case 0: lcdSetText(uart1, 1, "auton one"); break; case 1: lcdSetText(uart1, 1, "auton two"); break; case 2: lcdSetText(uart1, 1, "auton three"); break; case 3: lcdSetText(uart1, 1, "auton four"); break; } button = getLcdButtons(); if (button == LCD_BTN_RIGHT) { if (++screen > maxScreen) screen = minScreen; } else if (button == LCD_BTN_LEFT) { if (--screen < minScreen) screen = maxScreen; } } autonSelection = screen; lcdSetText(uart1, 1, " AUTONOMOUS"); lcdSetText(uart1, 2, " SET"); taskDelay(400); return; } } } if (button == LCD_BTN_RIGHT) { lcdClear(uart1); lcdSetText(uart1, 1, "Starting Side?"); lcdSetText(uart1, 2, "< Middle Hang >"); while (button != LCD_BTN_LEFT || button != LCD_BTN_RIGHT) { button = getLcdButtons(); // Blue Middle if (button == LCD_BTN_LEFT) { int screen = 0; int minScreen = 0; int maxScreen = 4; lcdClear(uart1); while (button != LCD_BTN_CENTER) { switch (screen) { case 0: lcdSetText(uart1, 1, "auton one"); break; case 1: lcdSetText(uart1, 1, "auton two"); break; case 2: lcdSetText(uart1, 1, "auton three"); break; case 3: lcdSetText(uart1, 1, "auton four"); break; } button = getLcdButtons(); if (button == LCD_BTN_RIGHT) { if (++screen > maxScreen) screen = minScreen; } else if (button == LCD_BTN_LEFT) { if (--screen < minScreen) screen = maxScreen; } } autonSelection = screen; lcdSetText(uart1, 1, " AUTONOMOUS"); lcdSetText(uart1, 2, " SET"); taskDelay(400); return; } // Blue Hang if (button == LCD_BTN_RIGHT) { int screen = 0; int minScreen = 0; int maxScreen = 4; lcdClear(uart1); while (button != LCD_BTN_CENTER) { switch (screen) { case 0: lcdSetText(uart1, 1, "auton one"); break; case 1: lcdSetText(uart1, 1, "auton two"); break; case 2: lcdSetText(uart1, 1, "auton three"); break; case 3: lcdSetText(uart1, 1, "auton four"); break; } button = getLcdButtons(); if (button == LCD_BTN_RIGHT) { if (++screen > maxScreen) screen = minScreen; } else if (button == LCD_BTN_LEFT) { if (--screen < minScreen) screen = maxScreen; } } autonSelection = screen; lcdSetText(uart1, 1, " AUTONOMOUS"); lcdSetText(uart1, 2, " SET"); taskDelay(400); return; } } } } }
int selectFile(char *filename, const char *extension) { int skip = 0; char key; int selected = 0; font=&Font_7x8; while(1){ char files[PERPAGE][FLEN]; int count = getFiles(files, PERPAGE, skip, extension); if(!count){ lcdPrintln("No Files?"); lcdRefresh(); getInputWait(); getInputWaitRelease(); return -1; }; if(count<PERPAGE && selected==count){ skip--; continue; }; redraw: lcdClear(); lcdPrintln("Select file:"); for(int i=0; i<count; i++){ if( selected == i ) lcdPrint("*"); else lcdPrint(" "); lcdSetCrsrX(14); int dot=-1; for(int j=0;files[j];j++) if(files[i][j]=='.'){ files[i][j]=0; dot=j; break; }; lcdPrintln(files[i]); if(dot>0) files[i][dot]='.'; } lcdRefresh(); key=getInputWaitRepeat(); switch(key){ case BTN_DOWN: if( selected < count-1 ){ selected++; goto redraw; }else{ skip++; } break; case BTN_UP: if( selected > 0 ){ selected--; goto redraw; }else{ if( skip > 0 ){ skip--; } } break; case BTN_LEFT: return -1; case BTN_ENTER: case BTN_RIGHT: strcpy(filename, files[selected]); getInputWaitRelease(); // catch this event so the app does not get it return 0; } } }