Beispiel #1
0
void loop(void)
{


//check for pressed key
    keyboardCheck();


//loop among screens
    if(screenActive==_screenMenu) screenActive=screenMenu();
    if(screenActive==_screenPlay) screenActive=screenPlay();
    if(screenActive==_screenEnd) screenActive=screenEnd();



//play sound
    if (millis() > songTime)
    {
        if (play_rtttl() == 1)//end of sound???
        {
            songIndex = 0; //restart tone from the begin
            songTime=millis()+600;//pause before next tone
        }
    }



}
int main(void) {
	DDRD = 0xff;
	DDRB = 0xff;
	DDRC = 0;
	
	PORTC = _BV(2) | _BV(3) | _BV(4) | _BV(5);	// keyboard pull-up
	

	TCCR1A = 0;
	TCCR1B = _BV(CS11) | _BV(CS10);
	
	TIMSK = _BV(OCIE1A);
	
	sei();
	enableLed(false);
	enablePower(false);
	displayOutTime(0);
	
	timer_interval = eeprom_read_word(EEPROM_OFFSET_TIME);
	if (timer_interval > MAX_TIME_INTERVAL_MINUTES || timer_interval == 0) {
		timer_interval = 10;
	}
	
    while(1) {
		keyboardCheck();
		if (timer_mode == TIMER_MODE_WAIT) {
			if (key_pressed[KEY_PLUS] == 0xff && timer_interval < MAX_TIME_INTERVAL_MINUTES) {
				timer_interval++;
				key_pressed[KEY_PLUS] = 220;
			} else if (key_pressed[KEY_MINUS] == 0xff && timer_interval > 0) {
				timer_interval--;
				key_pressed[KEY_MINUS] = 220;
			}
		}
		for (uint8_t i = 0; i < 8; i++) {
			displayUpdate(i);
			if (timer_mode == TIMER_MODE_RUN) {
				displayOutTime(time);
				displayOutSeparator(hsec < 50);
				if (time < 30) {
					enableLed(hsec < 25 || (hsec > 50 && hsec < 75));	
				} else if (time < 60) {
					enableLed(hsec < 75);
				}
			} else {
				displayOutTime(timer_interval);
				displayOutSeparator(true);
				//displayOutSeparator(hsec < 25 || (hsec > 50 && hsec < 75));
				//if (hsec < 25 || (hsec > 50 && hsec < 75)) {
					//displayOutTime(timer_interval);
					//displayOutSeparator(true);
				//} else {
					//displayClear();
				//}
			}
			_delay_us(500);
		}
    }
}
Beispiel #3
0
void loop(void)
{
  unsigned long ulNow = millis();

  if (ulNow > displayRefresh)
  {
    //time to refresh the screen?
    displayRefresh = ulNow + 50;
    displayCopyToLed();
  }

  //play sound
  if (ulNow > songTime)
  {
    //time to play next note?
    if (play_rtttl() == 1)//end of sound???
    {
      songIndex = 0; //restart tone from the begin
      songTime = ulNow + 1000; //pause before next tone
    }
  }

  //check for pressed key
  keyboardCheck();


  //loop among screens
  switch (screenActive)
  {
    case _screenMenu: screenActive = screenMenu();
      break;
    case _screenPlay: screenActive = screenPlay();
      break;
    case _screenEnd:  screenActive = screenEnd();
      break;
  }


}
Beispiel #4
0
int main(void) {
	init();

	uart_init();
	MSG("INIT");
//	cli();

	LCD_init();

	LCD_contrast(0xff);

	LCD_PrintStr(STR_HELLO);

	LCD_GotoXY(1, 1);

	//LCD_PrintStr(STR_WORLD);
	//LCD_PrintInt((uint8_t)'А');
	// en  A - 65 => 65+128 = 193
	// rus A - 144
//	LCD_PrintInt(a);
//
//	LCD_PrintChar(' ');
	for (uint8_t i = 0; i < 16;i++) {
		LCD_PrintChar(40+i);
	}

	uint8_t i = 0;
	while (true) {
		keyboardCheck();
		bool update = false;
		if (key_click_flag[KEY_UP]) {
			if (i < 2) {
				i++;
				update = true;
			}
		}
		if (key_click_flag[KEY_DOWN]) {
			if (i != 0) {
				i--;
				update = true;
			}
		}
		if (update) {
			LCD_Clear();
			switch(i) {
				case 0:
					LCD_PrintStr(STR_START);
					break;
				case 1:
					LCD_PrintStr(STR_PROFILE);
					break;
				case 2:
					LCD_PrintStr(STR_SETTINGS);
					break;
			}
			LCD_GotoXY(0, 1);
			LCD_PrintInt(i);
			_delay_ms(500);
		}

//		LCD_GotoXY(0, 1);
//		LCD_PrintInt(key_counter[KEY_UP]);
//		LCD_PrintChar(' ');
//		LCD_PrintInt(key_counter[KEY_DOWN]);
//		LCD_PrintChar(' ');
//		LCD_PrintInt(key_click_flag[KEY_UP]);
		_delay_us(1000);
	}
}