/*controle manual via joystick e botoes*/ void manualControl(){ int x, y, digital, b1, b2, end1, end2; while(1){ x = posicaoJoystick('x'); y = posicaoJoystick('y'); digital = readJSButton(); b1 = readButtons('1'); b2 = readButtons('2'); end1 = readEnd('x'); end2 = readEnd('y'); if(end1||end2){ TM_HD44780_Clear(); TM_HD44780_Puts(0, 0, "FIM DE CURSO"); TM_HD44780_Puts(0, 1, "RESETE A MESA"); return; } if(x == 1||x == -1||y == 1||y == -1){ if(x==1){ runClockwise2(1, 'x'); }else if(x==-1){ runCounterclockwise2(1, 'x'); } if(y==1){ runClockwise2(1, 'y'); }else if(y==-1){ runCounterclockwise2(1, 'y'); } } if(digital==1){ TM_HD44780_Clear(); TM_HD44780_Puts(0, 0, "MARCAR"); setFura(); } if(b1==1){ TM_HD44780_Clear(); TM_HD44780_Puts(0, 0, "DESCER DRILL"); runCaneta(1, '+'); } if(b2==1){ TM_HD44780_Clear(); TM_HD44780_Puts(0, 0, "SUBIR DRILL"); runCaneta(1, '-'); } } }
word ButtonWaitForAnyEvent(unsigned int timeout) { if (!ButtonLedInitialized()) return 0; unsigned long long endms, curTime; word oldDown, newDown; if (timeout == 0) endms = 0x7fffffffffffffffULL; else endms = TimerGetMS() + timeout; oldDown = ButtonLedInstance.curButtonsE; while (TRUE) { curTime = TimerGetMS(); if (curTime >= endms) { return 0; } usleep(BUTTON_POLL_TIME*1000); ButtonLedInstance.curButtonsE = readButtons(); newDown = ButtonLedInstance.curButtonsE; if (newDown != oldDown) { return ((oldDown & ~newDown) << WAITFOR_RELEASE_SHIFT) | (newDown & ~oldDown); } } }
void hardwareInit(void) { PLLConfig(); SET_ADPCFG; buttonsInit(); LED_SET_OUT; LED_OFF; sensorsInit(); sensorsOn(); readBatteryVoltage(); servoInit(); motorsInit(); //motorsOff(); profilerInit(); readButtons(); if( key_UP&&key_DN ) //if ICSP is connected { displayEnabled = TRUE; serialInit(); //_TRISB10 = 0; //_TRISB11 = 0; } CC2500_init(); systemTimerInit(); }
//================================================================================ // Main routine //================================================================================ // int main() { unsigned char btns; unsigned char btns_old = 0x00; init(); fprintf(LCD, "42 is the answer"); PORTB |= (1<<PB4); // LCD Backlight switch // sei(); while(1){ btns = readButtons(); if(((btns ^ btns_old) == 0x01) && (btns == 0x01)) { // we have toggle of btn0 PORTA^=0x02; } if(((btns ^ btns_old) == 0x02) && (btns == 0x02)) { // we have toggle of btn1 PORTC++; } btns_old=btns; // printf("Hello World\r\n"); _delay_ms(50); } }
void ButtonGroup::_start(){ bool exit = false; while(!exit) { fd_set rfds; struct timeval tv; int retval; FD_ZERO(&rfds); FD_SET(_quitPipe.getReadFd(), &rfds); tv.tv_sec = 0; tv.tv_usec = 1000; retval = select(_quitPipe.getReadFd()+1, &rfds, NULL, NULL, &tv); if(retval == -1) { log(LOG_ERR, "select() failed"); exit = true; } else if (!retval) { // timeout readButtons(); } else{ unsigned char quitRead = _quitPipe.read(); if(QUIT == quitRead) { exit = true; } else { throw Error::system("this shuld not happened"); } } } }
WorldMap::WorldMap() : mWorld(0), mSub(0), mLevelCount(0), mSection(0), mCount(0), mNewWorld(false), //fult mWorldMax(3) { readButtons(); mMusic = "Resources/Sound/Music/Title_Screen_"; mSprite.setTexture(*ResourceManager::getInst().getTexture("Resources/Menu/WorldMenu/WorldmapBG.png")); mSprite.setPosition(0,0); readSave(); readWorld(); updateWorld(); readAnimals(); LevelManager::getInst().setDeadAnimalCollection(mDeadAnimalVector); mCurrentWorld = mWorld; mCurrentSection = mSection; mFactButton = new FactButton(sf::Vector2f(20,20), "addAnimalipedia", "Resources/Menu/AchievementMenu/faktaknapp.png", "Resources/Sound/Menu/Menu_forward.wav"); mCutscenes.push_back("Resources/Data/Cutscenes/Cutscene_2.xml"); mCutscenes.push_back("Resources/Data/Cutscenes/Cutscene_3.xml"); mCutscenes.push_back("Resources/Data/Cutscenes/Cutscene_ending.xml"); }
word ButtonWaitForAnyPress(unsigned int timeout) { if (!ButtonLedInitialized()) return 0; unsigned long long endms, curTime; word oldDown, newDown, pressed; if (timeout == 0) endms = 0x7fffffffffffffffULL; else endms = TimerGetMS() + timeout; oldDown = ButtonLedInstance.curButtonsE; while (TRUE) { curTime = TimerGetMS(); if (curTime >= endms) { return 0; } usleep(BUTTON_POLL_TIME*1000); ButtonLedInstance.curButtonsE = readButtons(); newDown = ButtonLedInstance.curButtonsE; pressed = newDown & ~oldDown; if (pressed != 0) { return pressed; } oldDown = newDown; } }
Transition StateCfgOnOff_cfgOnOff(void * instance, void * data) { Transition transition; ButtonsStatus buttonStatus; StateCfgOnOff* this = instance; if (this->shouldPrint) { this->lastSelectedValue = *this->variable; //Force print the last selected value. this->lastPrintValue = !this->lastSelectedValue; } StateCfgOnOff_updateScreen(this); transition.nextState = &(this->super); transition.dataFornextState = NULL; this->shouldPrint = false; readButtons(&buttonStatus); if (buttonStatus.button.enter) { *this->variable = this->lastSelectedValue; this->shouldPrint = true; transition = *this->returnTransition; } else if (buttonStatus.button.back) { this->shouldPrint = true; transition = *this->returnTransition; } else if (buttonStatus.button.down || buttonStatus.button.up) { StateCfgOnOff_swapValue(this); } return transition; }
int main(){ initLedButtons(); char buttonState; while(1){ char t = readButtons(); if (t != buttonState){ buttonState =t; setLeds(buttonState); } } closeLedButtons(); }
/*ajusta altura da caneta/drill manualmente*/ void calibraCaneta(void){ int b1, b2, digital=0; TM_HD44780_Clear(); TM_HD44780_Puts(0, 0, "CALIBRE EIXO Z"); TM_HD44780_Puts(0, 1, "Digital = OK"); while(!digital){ digital = readJSButton(); b1 = readButtons('1'); b2 = readButtons('2'); if(b1){ runCaneta(1, '+'); }else if(b2){ runCaneta(1, '-'); } } TM_HD44780_Clear(); runCaneta(300, '-'); }
/*APRIMORAR E TESTAR*/ void menu(void){ int b1, b2, digital = 0; int menu = 0; while(!digital){ digital = readJSButton(); b1 = readButtons('1'); b2 = readButtons('2'); if(b1||b2){ menu++; menu %= 2; } if(menu == 0){ TM_HD44780_Clear(); TM_HD44780_Puts(0, 0, "MODO AUTONOMO"); TM_HD44780_PutCustom(15, 0, 0); TM_HD44780_Puts(0, 1, "MODO MANUAL"); Delayms(50); }else if(menu == 1){ TM_HD44780_Clear(); TM_HD44780_Puts(0, 0, "MODO AUTONOMO"); TM_HD44780_Puts(0, 1, "MODO MANUAL"); TM_HD44780_PutCustom(15, 1, 0); Delayms(50); } TM_HD44780_Clear(); } if(menu == 0){ modoPerfuracao(); //setDesenhaQuadrado(); }else if(menu == 1){ manualControl(); } }
void main(void) { byte patterns[]= {0x00,0x01,0x03,0x07,0x0F,0x1F,0x3F,0x7F,0xFF,0x7F,0x1F,0x0F,0x07,0x03,0x01,0x00}; int i; byte scan_code; DDRA = 0xFF; PERT = 0x0F; //pull up resistor? PORTA = 0xff; DDRP = 0x0f; //pull up resistor? //use the folowing to calibrate the delay functions //PORTA=0xFF; //delay2(10000); //PORTA=0x00; while(1) { for(i=0; i<SL; i++) { PORTA=patterns[i]; delay(delayTime); readButtons(); scan_code = getkey (); if (scan_code != 0xff) //if keyboard press block_LEDS(scan_code); }//end for }//end while EnableInterrupts; for(;;) { _FEED_COP(); /* feeds the dog */ } /* loop forever */ /* please make sure that you never leave main */ }
void loop() { /* Serial.print( analogRead( pinJoystickX ) ); //Read the position of the joysticks X axis and print it on the serial port. Serial.print( "," ); Serial.print( analogRead( pinJoystickY ) ); //Read the position of the joysticks Y axis and print it on the serial port. Serial.print( "," ); Serial.print( digitalRead( pinButtonJoystick ) ); //Read the value of the select button and print it on the serial port. Serial.print( digitalRead( pinButtonNorth ) ); //Read the value of the button 1 and print it on the serial port. Serial.print( digitalRead( pinButtonSouth ) ) ; //Read the value of the button 2 and print it on the serial port. Serial.print( digitalRead( pinButtonEast ) ); //Read the value of the button 0 and print it on the serial port. Serial.println( digitalRead( pinButtonWest ) ); //Read the value of the button 3 and print it on the serial port. //Wait for 100 ms, then go back to the beginning of 'loop' and repeat. delay( 100 ); */ readJoystickComboPWM( PF_n::transmitter_c::CHANNEL_1, pinJoystickX, pinJoystickY, xLeft, xMid, xRight, yUp, yMid, yDown ); readButtons( PF_n::transmitter_c::CHANNEL_2, pinButtonNorth, pinButtonSouth, pinButtonEast, pinButtonWest ); readJoystickButton( PF_n::transmitter_c::CHANNEL_3, pinButtonJoystick ); transmitter.sendMessages(); }
int main(){ initScreen(); initSound(); initLedButtons(); lcdTest(); while(1){ fillBoard(); printBoard(); for (int i = 0; i < 100; i++){ setLeds((char)i); setFrequency(120*(i%20)); playerStep(); printBoard(); playSounds(); if (readButtons() & 0x01 > 0) break; } } closeLedButtons(); closeScreen(); closeSound(); }
/**************************************************************************//** * @brief Main function *****************************************************************************/ int main(void) { uint32_t buttons; POINT P[ 3 ]; TOUCH_Config_TypeDef touch_config = TOUCH_INIT_DEFAULT; const char readmeText[] = \ "USB Bitmap transfer using USB drive functionality.\r\n\r\n"\ "This example demonstrate use several functionalities:\r\n"\ "1. Creation of virtual drive in system with FAT FS,\r\n"\ "2. Mounting the drive on PC and file transfer,\r\n"\ "3. Bitmap file creation based on TFT frame buffer content,\r\n"\ "4. Resistive touch panel interaction.\r\n\r\n"\ "On system startup initial drive is created and\r\n"\ "formatted using FAT FS then simple readme.txt file\r\n"\ "is put on file system. Every time user press PB4 key\r\n"\ "new file, containing TFT frame buffer in bitmap format\r\n"\ "is added. All files could be retrieved after connecting\r\n"\ "board to PC by means of USB. For this connection use\r\n"\ "small USB socket located on Leopard Gecko CPU board, not\r\n"\ "the big one on development kit.\r\n\r\n"\ "If new files doesn't appear on drive after pressing PB4,\r\n"\ "try to reconnect the board to PC.\r\n\r\n"\ "Board: Energy Micro EFM32LG-DK3650 Development Kit\r\n"\ "Device: EFM32LG990F256\r\n"; /* Configure for 48MHz HFXO operation of core clock */ CMU_ClockSelectSet(cmuClock_HF, cmuSelect_HFXO); /* Initialize DK board register access */ BSP_Init(BSP_INIT_DEFAULT); /* If first word of user data page is non-zero, enable eA Profiler trace */ BSP_TraceProfilerSetup(); CMU_ClockEnable(cmuClock_GPIO, true); CMU_ClockEnable( cmuClock_ADC0, true); /* Set frame buffer start address */ frameBuffer = (uint16_t *) EBI_BankAddress(EBI_BANK2); /* Make sure CYCCNT is running, needed by delay functions. */ DWT_CTRL |= 1; /* Initialize USB subsystem and prepare for taking pictures */ BITMAP_Init(); /* Create our first file on disk - simple readme */ BITMAP_CreateFileAndSaveData("README.TXT", readmeText, sizeof(readmeText)); /* Indicate we are waiting for AEM button state enabling EFM */ while (BSP_RegisterRead(&BC_REGISTER->UIF_AEM) != BC_UIF_AEM_EFM) { /* Show a short "strobe light" on DK LEDs, indicating wait */ BSP_LedsSet(0x8001); delayMs(100); BSP_LedsSet(0x4002); delayMs(100); } touch_config.frequency = 13000000; /* use max ADC frequency */ touch_config.ignore = 0; /* notice every move, even 1 pixel */ TOUCH_Init(&touch_config); /* Initialize touch screen calibration factor matrix with approx. values */ setCalibrationMatrix( (POINT*)&lcdCalibPoints, /* Display coordinates */ (POINT*)&touchCalibPoints, /* Touch coordinates */ &calibFactors ); /* Calibration factor matrix */ while (1) { delayMs(100); if ( TFT_DirectInit(&tftInit) ) { delayMs(100); displayHelpScreen(); BSP_LedsSet(0x0000); BSP_PeripheralAccess(BSP_TOUCH, true); GPIO_PinModeSet(LCD_TOUCH_X1, gpioModeInput, 0); GPIO_PinModeSet(LCD_TOUCH_X2, gpioModeInput, 0); GPIO_PinModeSet(LCD_TOUCH_Y1, gpioModeInput, 0); GPIO_PinModeSet(LCD_TOUCH_Y2, gpioModeInput, 0); do { delayMs(25); buttons = readButtons(); /* Draw on screen */ if ( buttons & BC_UIF_PB1 ) { memset( frameBuffer, BLACK, 2 * WIDTH * HEIGHT ); /* Clear screen */ do { TOUCH_Pos_TypeDef *pos = TOUCH_GetPos(); if ( pos->pen ) drawPixel( pos->x, pos->y, COLOR ); delayMs(1); buttons = readButtons() & ~BC_UIF_PB1; if(buttons == BC_UIF_PB4) { getNicePicture(); buttons &= ~BC_UIF_PB4; } } while ( buttons == 0 ); } /* Calibrate touch screen */ else if ( buttons & BC_UIF_PB2 ) { memset( frameBuffer, BLACK, 2 * WIDTH * HEIGHT ); /* Clear screen */ drawCross( lcdCalibPoints[ 0 ].x, lcdCalibPoints[ 0 ].y, COLOR ); TFT_DrawString(30, 35, "Tap green marker" ); P[ 0 ] = getTouchTapSample10bit(); memset( frameBuffer, BLACK, 2 * WIDTH * HEIGHT ); /* Clear screen */ drawCross( lcdCalibPoints[ 1 ].x, lcdCalibPoints[ 1 ].y, COLOR ); TFT_DrawString(40, 130, "Tap green marker" ); P[ 1 ] = getTouchTapSample10bit(); memset( frameBuffer, BLACK, 2 * WIDTH * HEIGHT ); /* Clear screen */ drawCross( lcdCalibPoints[ 2 ].x, lcdCalibPoints[ 2 ].y, COLOR ); TFT_DrawString(20, 180, "Tap green marker" ); P[ 2 ] = getTouchTapSample10bit(); TOUCH_CalibrationTable((POINT*)&lcdCalibPoints,/* Display coordinates*/ &P[0]); /* Touch coordinates */ memset( frameBuffer, BLACK, 2 * WIDTH * HEIGHT ); /* Clear screen */ TFT_DrawString(10, 100, "The touch screen is" ); TFT_DrawString(30, 130, "now calibrated !" ); } /* Display help screen */ else if ( buttons & BC_UIF_PB3 ) { displayHelpScreen(); while ( readButtons() & BC_UIF_PB3 ) delayMs(50); } else if( buttons & BC_UIF_PB4 ) { getNicePicture(); } } while ( ( buttons & EXIT_LOOP ) == 0 ); } else { BSP_LedsSet(0x8001); delayMs(100); BSP_LedsSet(0x4002); } } }
void waitForOk() { while(readButtons() != BTN_OK); }
/**************************************************************************//** * @brief Main function *****************************************************************************/ int main(void) { uint32_t buttons; POINT touchSample, P[ 3 ]; ADC_Init_TypeDef init = ADC_INIT_DEFAULT; /* Configure for 48MHz HFXO operation of core clock */ CMU_ClockSelectSet(cmuClock_HF, cmuSelect_HFXO); /* Initialize DK board register access */ BSP_Init(BSP_INIT_DEFAULT); /* If first word of user data page is non-zero, enable eA Profiler trace */ BSP_TraceProfilerSetup(); CMU_ClockEnable(cmuClock_GPIO, true); CMU_ClockEnable( cmuClock_ADC0, true); /* Max ADC clock is 13MHz, use 14MHz/(1+1) or 48MHz/(5+1) */ init.prescale = 5; ADC_Init(ADC0, &init); sInit.reference = adcRefVDD; /* Set frame buffer start address */ frameBuffer = (uint16_t *) EBI_BankAddress(EBI_BANK2); /* Make sure CYCCNT is running, needed by delay functions. */ DWT_CTRL |= 1; /* Indicate we are waiting for AEM button state enabling EFM */ BSP_LedsSet(0x8001); while (BSP_RegisterRead(&BC_REGISTER->UIF_AEM) != BC_UIF_AEM_EFM) { /* Show a short "strobe light" on DK LEDs, indicating wait */ BSP_LedsSet(0x8001); delayMs(200); BSP_LedsSet(0x4002); delayMs(50); } /* Initialize touch screen calibration factor matrix with approx. values */ setCalibrationMatrix( (POINT*)&lcdCalibPoints, /* Display coordinates */ (POINT*)&touchCalibPoints, /* Touch coordinates */ &calibFactors ); /* Calibration factor matrix */ while (1) { if ( TFT_DirectInit(&tftInit) ) { displayHelpScreen(); BSP_LedsSet(0x0000); BSP_PeripheralAccess(BSP_TOUCH, true); GPIO_PinModeSet(LCD_TOUCH_X1, gpioModeInput, 0); GPIO_PinModeSet(LCD_TOUCH_X2, gpioModeInput, 0); GPIO_PinModeSet(LCD_TOUCH_Y1, gpioModeInput, 0); GPIO_PinModeSet(LCD_TOUCH_Y2, gpioModeInput, 0); do { buttons = readButtons(); /* Draw on screen */ if ( buttons & BC_UIF_PB1 ) { memset( frameBuffer, BLACK, 2 * WIDTH * HEIGHT ); /* Clear screen */ do { if ( touched() ) { touchSample = getTouchSample(); drawPixel( touchSample.x, touchSample.y, COLOR ); } delayMs( 2 ); buttons = readButtons() & ~BC_UIF_PB1; } while ( buttons == 0 ); } /* Calibrate touch screen */ else if ( buttons & BC_UIF_PB2 ) { memset( frameBuffer, BLACK, 2 * WIDTH * HEIGHT ); /* Clear screen */ drawCross( lcdCalibPoints[ 0 ].x, lcdCalibPoints[ 0 ].y, COLOR ); TFT_DrawString(30, 35, "Tap green marker" ); P[ 0 ] = getTouchTapSample10bit(); memset( frameBuffer, BLACK, 2 * WIDTH * HEIGHT ); /* Clear screen */ drawCross( lcdCalibPoints[ 1 ].x, lcdCalibPoints[ 1 ].y, COLOR ); TFT_DrawString(40, 130, "Tap green marker" ); P[ 1 ] = getTouchTapSample10bit(); memset( frameBuffer, BLACK, 2 * WIDTH * HEIGHT ); /* Clear screen */ drawCross( lcdCalibPoints[ 2 ].x, lcdCalibPoints[ 2 ].y, COLOR ); TFT_DrawString(20, 180, "Tap green marker" ); P[ 2 ] = getTouchTapSample10bit(); setCalibrationMatrix( (POINT*)&lcdCalibPoints,/* Display coordinates*/ &P[0], /* Touch coordinates */ &calibFactors ); /* Calibration factor matrix*/ memset( frameBuffer, BLACK, 2 * WIDTH * HEIGHT ); /* Clear screen */ TFT_DrawString(10, 100, "The touch screen is" ); TFT_DrawString(30, 130, "now calibrated !" ); } /* Display help screen */ else if ( buttons & BC_UIF_PB3 ) { displayHelpScreen(); while ( readButtons() & BC_UIF_PB3 ) {} } } while ( ( buttons & EXIT_LOOP ) == 0 ); } else { BSP_LedsSet(0x8001); delayMs(200); } } }
// ------------------------------------------ void HIDbase::doButtons() { if( readButtons() ) { // do nothing if no buttons have been pressed switch ( HIDstate ) { // --------------- do nothing if in slave mode case slave_state : break; // --------------- case confirm_reset_state : if( keyPressed( BTN_UP ) && keyChanged( BTN_UP ) ) { // Y)es key dTime = true; ledFlash( LED_3 ); HIDstate = running_state; statusLCD = ALL_FIELDS; } else if( keyPressed( BTN_DOWN ) && keyChanged( BTN_DOWN ) ) { // N)o key ledFlash( LED_3 ); HIDstate = running_state; statusLCD = ALL_FIELDS; } break; // -------------- case running_state : if( keyPressed( BTN_HOME ) && keyChanged( BTN_HOME ) ) {// left button = start the roast ledFlash( LED_1 ); // bump the leftmost LED to indicate beans loaded HIDstate = confirm_reset_state; // ask for confirmation before resetting timer statusLCD = (1 << CONFIRM_BIT); } else if( keyPressed( BTN_SEL_MODE ) && keyChanged( BTN_SEL_MODE ) ) { // 2nd button selects mode ledFlash( LED_2 ); // bump LED to acknowledge HIDstate = level_1_state; statusLCD |= (1 << LEVEL_1_BIT); // repaint the level_1 field statusLCD &= ~(1 << ROW_BIT); // make first row active } break; // -------------- case level_1_state : if( keyPressed( BTN_HOME ) && keyChanged( BTN_HOME ) ) {// left button = return to home screen ledFlash( LED_1 ); // bump the leftmost LED to acknowledge HIDstate = running_state; // return to "home" screen //statusLCD = ALL_FIELDS; statusLCD |= (1 << LEVEL_1_BIT); // update the level_1 field statusLCD &= ~(1 << ROW_BIT); // make first row active } else if( keyPressed( BTN_UP ) && keyChanged( BTN_UP ) ) { // increase the value of level_1 ledFlash( LED_3 ); int8_t trial = level_1; trial += 5; if( trial > 100 ) trial = 100; if( trial != level_1 ) { level_1 = trial; dLevel_1 = true; statusLCD |= (1 << LEVEL_1_BIT); // repaint the level_1 field statusLCD &= ~(1 << ROW_BIT); // make first row active } } else if( keyPressed( BTN_DOWN ) && keyChanged( BTN_DOWN ) ) { // increase the value of level_1 ledFlash( LED_3 ); int8_t trial = level_1; trial -= 5; if( trial < 0 ) trial = 0; if( trial != level_1 ) { level_1 = trial; dLevel_1 = true; statusLCD |= (1 << LEVEL_1_BIT); // repaint the level_1 field statusLCD &= ~(1 << ROW_BIT); // make first row active } } else if( keyPressed( BTN_SEL_MODE ) && keyChanged( BTN_SEL_MODE ) ) { // 2nd button selects mode ledFlash( LED_2 ); // bump LED to acknowledge HIDstate = level_2_state; statusLCD |= (1 << LEVEL_2_BIT) | (1 << LEVEL_1_BIT); // update both fields statusLCD &= ~(1 << ROW_BIT); // make first row active } break; // -------------- case level_2_state : if( keyPressed( BTN_HOME ) && keyChanged( BTN_HOME ) ) {// left button = return to home screen ledFlash( LED_1 ); // bump the leftmost LED to indicate beans loaded HIDstate = running_state; // return to "home" screen //statusLCD = ALL_FIELDS; statusLCD |= (1 << LEVEL_2_BIT); // update the level_2 field statusLCD |= (1 << ROW_BIT); // make second row active } else if( keyPressed( BTN_UP ) && keyChanged( BTN_UP ) ) { // increase the value of level_1 ledFlash( LED_3 ); int8_t trial = level_2; trial += 5; if( trial > 100 ) trial = 100; if( trial != level_2 ) { level_2 = trial; dLevel_2 = true; statusLCD |= (1 << LEVEL_2_BIT); statusLCD |= (1 << ROW_BIT); // make second row active } } else if( keyPressed( BTN_DOWN ) && keyChanged( BTN_DOWN ) ) { // increase the value of level_1 ledFlash( LED_3 ); int8_t trial = level_2; trial -= 5; if( trial < 0 ) trial = 0; if( trial != level_2 ) { level_2 = trial; dLevel_2 = true; statusLCD |= (1 << LEVEL_2_BIT); statusLCD |= (1 << ROW_BIT); // make second row active } } else if( keyPressed( BTN_SEL_MODE ) && keyChanged( BTN_SEL_MODE ) ) { // 2nd button selects mode ledFlash( LED_2 ); // bump LED to acknowledge HIDstate = running_state; //statusLCD = ALL_FIELDS; statusLCD |= (1 << LEVEL_2_BIT); // update the level_2 field statusLCD |= (1 << ROW_BIT); // make second row active } break; } // end switch } // end if readButtons() }
// main loop int main(void){ uint8_t stateDS18=DS18B20_STATUS_READY; #ifdef USE_WDT WDT_init(WDTO_8S); #endif initGPIO(); LCD_init(); showLcdSplash(); setLcdInitialFields(); paramLoadFromEeprom(); USART1_config(USART1_MY_UBBRN,USART_DATA_FORMAT_8BITS|USART_STOP_BITS_1,USART_TRANSMIT_ENABLE|USART_RECEIVE_ENABLE| USART_INTERRUPT_ENABLE); USART1_sendStr("Hello"); schedulerInit(); // check for the default values #ifdef USE_WDT WDT_init(WDTO_8S); #endif sei(); //enable interrups // loop while while(1){ // cintrol zone if(flagTaskControl){ #ifdef USE_WDT WDT_reset(); #endif LED_RUN_OFF; // fire the DS if(stateDS18==DS18B20_STATUS_READY){ DS18B20_startConv(); stateDS18=DS18B20_STATUS_CONV; // check if convertion ended }else if(stateDS18==DS18B20_STATUS_CONV){ if(DS18B20_convComplete()){ stateDS18=DS18B20_STATUS_END_CONV; } // convertion ready }else if (stateDS18==DS18B20_STATUS_END_CONV){ LED_RUN_ON; currentTemp=DS18B20_getTemp(); stateDS18=DS18B20_STATUS_READY; currentStatus = checkTempError(currentTemp,currentTempSetPoint,currentHistSetPoint); // chec the out setOutputRelay(currentStatus); _delay_ms(50); LED_RUN_OFF; } flagTaskControl=0; } // user bottons area if(flagTaskReadButtons){ #ifdef USE_WDT WDT_reset(); #endif uint8_t portVal = readButtons(); uint8_t code = decodeButton(portVal); code = debounceKey(code); #ifdef MAIN_DEBUG sprintf(debugBuffer,"Key %d",code); USART1_sendStr(debugBuffer); #endif stateMachine(code); // go to machine flagTaskReadButtons=0; } // lcd update area if(flagTaskUpdateLcd){ #ifdef USE_WDT WDT_reset(); #endif //showLcdSavedMessage(); updateLcd(); // update the lcd flagTaskUpdateLcd=0; } // save to eeprom if(flagSaveParametersEeprom){ #ifdef USE_WDT WDT_reset(); #endif paramSavetoEeprom(); // save value sto eeprom showLcdSavedMessage(); setLcdInitialFields(); updateLcd(); flagSaveParametersEeprom=0; } } }
bool ButtonIsUp(byte Button) { return (readButtons() & Button) == 0; }