bool GW_GameEngine_VTech::do_setmode(int mode) { switch (mode) { case MODE_OFF: data_stopalltimers(); data_stopallsounds(); data_hideall(true); break; case MODE_IDLE: data_stopalltimers(); data_showall(); // reset numbers display_number(1, 8, false); display_number(2, 8, false); display_number(3, 8, false); display_number(4, 8, false); gameover_=true; break; case MODE_GAMEA: case MODE_GAMEB: if ((GetMode()!=MODE_GAMEA&&GetMode()!=MODE_GAMEB)||gameover_) do_game_start(mode); break; case MODE_TIME1: data_stopalltimers(); data_hideall(true); data().position_get(PS_TIME1)->show(); clock_update(mode); break; case MODE_TIME2: data_stopalltimers(); data_hideall(true); data().position_get(PS_TIME2)->show(); clock_update(mode); break; case MODE_ALARM: data_stopalltimers(); data_hideall(true); data().position_get(PS_ALARM)->show(); clock_update(mode); break; case MODE_CHRONO: data_stopalltimers(); data_hideall(true); data().position_get(PS_CHRONO)->show(); clock_update(mode); break; case MODE_DATE: data_stopalltimers(); data_hideall(true); data().position_get(PS_DATE)->show(); clock_update(mode); break; default: return false; break; } return true; }
void GW_GameEngine_VTech::score_update() { int p=score_; while (p>=10000) p-=10000; for (int i=1; i<=4; i++) data().position_get(PS_NUMBER, i)->hide(); if (p>999) display_number(1, p / 1000); if (p>99) display_number(2, p / 100 % 10); if (p>9) display_number(3, p / 10 % 10); if (p>=0) display_number(4, p % 10 % 10); }
bool GW_Game_DKong::do_setmode(int mode) { switch (mode) { case MODE_OFF: data_stopalltimers(); data_stopallsounds(); data_hideall(true); break; case MODE_IDLE: data_stopalltimers(); data_showall(); // reset numbers display_number(1, 1, false); display_number(2, 2, false); display_number(3, 0, false); display_number(4, 0, false); break; case MODE_GAMEA: case MODE_GAMEB: /* if ((GetMode()!=MODE_GAMEA&&GetMode()!=MODE_GAMEB)) do_game_start(mode); */ break; case MODE_TIME: data_stopalltimers(); data_hideall(true); //data().position_get(PS_TIME1)->show(); clock_update(mode); break; case MODE_ALARM: data_stopalltimers(); data_hideall(true); data().position_get(PS_ALARM)->show(); clock_update(mode); break; default: return false; break; } return true; }
int main() { /* struct sched_param sp; */ /* memset( &sp, 0, sizeof(sp) ); */ /* sp.sched_priority = 99; */ /* sched_setscheduler( 0, SCHED_FIFO, &sp ); */ uint16_t pwm_counter = 0; time_t rawtime; struct tm * timeinfo; initialise_io(); initialise_digit(digit1); /* initialise_digit(digit2); */ /* initialise_digit(digit3); */ /* initialise_digit(digit4); */ #ifdef gperf uint32_t loop_counter = 0; #endif char cursecond = 0; char oldsecond = 11; //out of usual bounds bool displayed = false; while (1) { // get current time time ( &rawtime ); timeinfo = localtime ( &rawtime ); cursecond = (timeinfo->tm_sec) % 10; if (pwm_counter < PWMTable[10]) { // display last digit of seconds of current time if (!displayed) { display_number (digit1,(cursecond)); displayed = true; } oldsecond = cursecond; } else { if (displayed) { initialise_digit (digit1); displayed = false; } }; // reset counter to 0 if (pwm_counter++ > PWMTable[max_brightness]) { pwm_counter = 0; //printf("reset pwm_counter from %u to 0\n",pwm_counter-1); }; #ifdef gperf if (loop_counter++ > 6000000) { exit(0); }; #endif } }
void GW_Game_DKong::setnumber(int n, int ps1, int ps2, bool leadzero) { // set a number on the display if (n>=0 && n<=99) { if (n>10) { display_number(ps1, n / 10); display_number(ps2, n % 10); } else { if (leadzero) display_number(ps1, 0); else display_number(ps1, -1); display_number(ps2, n); } } }
static void display_value(short int value) { if(value < 0) { output_high(PORTB, BLUE_LED); value = -value; } else output_low(PORTB, BLUE_LED); display_number(value); }
//Displays current alarm time //Brightness level is an amount of time the LEDs will be in - 200us is pretty dim but visible. //Amount of time during display is around : [ BRIGHT_LEVEL(us) * 5 + 10ms ] * 10 //Roughly 11ms * 10 = 110ms //Time on is in (ms) void display_alarm_time(uint16_t time_on) { uint16_t bright_level = 50; //time_on /= 11; //Take the time_on and adjust it for the time it takes to run the display loop below for(uint16_t j = 0 ; j < time_on ; j++) { //Display normal hh:mm time if(hours_alarm > 9) { display_number(hours_alarm / 10, 1); //Post to digit 1 delay_us(bright_level); } display_number(hours_alarm % 10, 2); //Post to digit 2 delay_us(bright_level); display_number(minutes_alarm / 10, 3); //Post to digit 3 delay_us(bright_level); display_number(minutes_alarm % 10, 4); //Post to digit 4 delay_us(bright_level); //During debug, display mm:ss /*display_number(minutes_alarm / 10, 1); delay_us(bright_level); display_number(minutes_alarm % 10, 2); delay_us(bright_level); display_number(seconds_alarm / 10, 3); delay_us(bright_level); display_number(seconds_alarm % 10, 4); delay_us(bright_level); display_number(10, 5); //Display colon delay_us(bright_level);*/ //Flash colon for each second if(flip == 1) { display_number(10, 5); //Post to digit COL delay_us(bright_level); } //Check whether it is AM or PM and turn on dot if(ampm_alarm == AM) { display_number(12, 6); //Turn on dot on apostrophe delay_us(bright_level); } clear_display(); delay_ms(1); } }
/* start the main program */ void main() { unsigned int cnt=0; /* Configure the ports as output */ TRISB = C_PortOutput_U8; TRISC = C_PortOutput_U8; while(1) { for(cnt=0;cnt<=9999;cnt++) // loop to display 0000-9999 { display_number(cnt); } } }
void display_speed() { // Velocity in mm/s // v(mm/s) = d(mm) / (t(us) / 1e6) uint32_t v = SENSOR_DISTANCE * 100000 / time_us; if (v > 99999) { lcd_puts_r(PSTR("FAST")); } else { display_number(v, 5); if (forward) { lcd_putc(0, '>'); } else { lcd_putc(0, '<'); } lcd_update(); } }
/* start the main program */ void main() { unsigned int cnt=0; while(1) { for(cnt=0;cnt<9999;cnt++) // loop to display 0000-9999 { display_number(cnt); DELAY_sec(1); } } }
int main(void) { WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer //Set pins used for segments to output P1DIR |= SEGA; P1DIR |= SEGB; P1DIR |= SEGC; P1DIR |= SEGD; P1DIR |= SEGE; P1DIR |= SEGF; P1DIR |= SEGG; __enable_interrupt(); // Enable interrupts. //config button // BUTTON_DIR &= ~BUTTON; // BUTTON_OUT |= BUTTON; // BUTTON_REN |= BUTTON; // BUTTON_IES |= BUTTON; // BUTTON_IFG &= ~BUTTON; // BUTTON_IE |= BUTTON; P1OUT = BUTTON; // P1.4 set, else reset //P1OUT |= BUTTON; P1REN |= BUTTON; // P1.4 pullup P1IE |= BUTTON; // P1.4 interrupt enabled P1IES |= BUTTON; // P1.4 Hi/lo edge P1IFG &= ~BUTTON; // P1.4 IFG cleared // _BIS_SR(LPM4_bits + GIE); display_number(0); // __bis_SR_register(CPUOFF + GIE); // LPM0 with interrupts enabled int i; volatile unsigned int delay_counter; //infinite loop for (;;) { // if (button_pressed) { display_number(current_number); //current_number = current_number++ % 10; current_number++; button_pressed = 0; } //loop for (i = 0; i < 10 && loop_mode; i++) { display_number(i); //fake some delay delay_counter = 50000; do (delay_counter--); while (delay_counter != 0); } } return 0; }
int main() { uint8_t show_speed = 0; Initialization(); // Beeper PORTB |= 0x20; DDRB |= 0x20; // LED enable DDRE |= 0x40; // Pullups on phototransistors PORTE |= 0x30; // Timer 2 is used for beep and power-off timing ASSR = 0; TCCR2A = 3; // ~122Hz TIMSK2 = 1; power_off(); while (1) { set_sleep_mode(SLEEP_MODE_IDLE); sleep_mode(); // Auto power off if (power_off_time == 0) { power_off(); } switch (getkey()) { case KEY_DOWN: // Power off power_off(); break; case KEY_UP: // Clear last measurement reset(); clear_display(); break; case KEY_RIGHT: if (time_us) { if (show_speed) { // Display raw time in microseconds display_number(time_us, 6); show_speed = 0; } else { display_speed(); show_speed = 1; } } break; } if (speed_state == SPEED_FWD_DONE || speed_state == SPEED_REV_DONE) { // Display last speed // Time in microseconds time_us = beam_timer_value(); if (speed_state == SPEED_FWD_DONE) { forward = 1; beep(1400); } else { forward = 0; beep(600); } speed_state = SPEED_IDLE; reset_auto_power_off(); display_speed(); } } }
void end_display(struct Game *game) { display_quad(game->graphics.score_texture, 0, 0, screen_vertices()); display_number(game, game->level * 20); }
GW_Game_DKong::GW_Game_DKong() : GW_Game() { gamepath_set("dkong"); size_set(464, 571); // game screen position GW_PLATFORM_RECT(gr, 125, 78, 212, 412); // full screen //GW_PLATFORM_RECT(gr, 125, 349, 214, 139); // first screen gamerect_set(gr); /* // second screen GW_PLATFORM_RECT(gr, 125, 177, 213, 139); gamerect_set(gr); */ char sname[50]; // transparent colors GW_PLATFORM_RGB(tcolor_bg, 255, 0, 255); GW_PLATFORM_RGB(tcolor_img, 255, 255, 255); // life data(). position_add(PS_LIFE, 1, 216, 470, IM_LIFE, 1, "vite.bmp", &tcolor_img)-> position_add(PS_LIFE, 2, 229, 470, IM_LIFE, 1)-> position_add(PS_LIFE, 3, 242, 470, IM_LIFE, 1); // bg data(). image_add(IM_BG, GW_INDEX_DEFAULT, "bg.bmp", &tcolor_bg); // barrel data(). position_add(PS_BARREL, 1, 137, 200, IM_BARREL, 1, "bar_14.bmp", &tcolor_img)-> //position_add(PS_BARREL, 2, 136, 372, IM_LIFE, 1)-> // 15 position_add(PS_BARREL, 3, 136, 397, IM_BARREL, 2, "bar_16.bmp", &tcolor_img)-> position_add(PS_BARREL, 4, 136, 461, IM_BARREL, 3, "bar_17.bmp", &tcolor_img)-> position_add(PS_BARREL, 5, 169, 197, IM_BARREL, 4, "bar_24.bmp", &tcolor_img)-> position_add(PS_BARREL, 6, 169, 400, IM_BARREL, 1)-> // 26 position_add(PS_BARREL, 7, 169, 457, IM_BARREL, 6, "bar_36.bmp", &tcolor_img)-> // 27 position_add(PS_BARREL, 8, 189, 196, IM_BARREL, 5, "bar_34.bmp", &tcolor_img)-> position_add(PS_BARREL, 9, 202, 403, IM_BARREL, 6, "bar_36.bmp", &tcolor_img)-> position_add(PS_BARREL, 10, 202, 454, IM_BARREL, 8, "bar_46.bmp", &tcolor_img)-> // 37 position_add(PS_BARREL, 11, 208, 195, IM_BARREL, 7, "bar_44.bmp", &tcolor_img)-> position_add(PS_BARREL, 12, 233, 406, IM_BARREL, 8, "bar_46.bmp", &tcolor_img)-> position_add(PS_BARREL, 13, 233, 452, IM_BARREL, 2)-> // 47 position_add(PS_BARREL, 14, 228, 194, IM_BARREL, 9, "bar_54.bmp", &tcolor_img)-> position_add(PS_BARREL, 15, 263, 409, IM_BARREL, 2)-> // 56 position_add(PS_BARREL, 16, 264, 450, IM_BARREL, 1)-> // 57 position_add(PS_BARREL, 17, 245, 193, IM_BARREL, 4)-> // 64 position_add(PS_BARREL, 18, 294, 413, IM_BARREL, 9)-> // 66 position_add(PS_BARREL, 19, 294, 447, IM_BARREL, 6); // 67 // barrel fall data(). position_add(PS_BARRELFALL, 1, 167, 127, IM_BARRELFALL, 1, "bar_f21.bmp", &tcolor_img)-> position_add(PS_BARRELFALL, 2, 168, 149, IM_BARRELFALL, 2, "bar_f22.bmp", &tcolor_img)-> position_add(PS_BARRELFALL, 3, 169, 177, IM_BARRELFALL, 3, "bar_f23.bmp", &tcolor_img)-> position_add(PS_BARRELFALL, 4, 206, 127, IM_BARRELFALL, 1)-> // 41 position_add(PS_BARRELFALL, 5, 207, 148, IM_BARRELFALL, 4, "bar_f42.bmp", &tcolor_img)-> position_add(PS_BARRELFALL, 6, 209, 178, IM_BARRELFALL, 5, "bar_f43.bmp", &tcolor_img)-> //position_add(PS_BARRELFALL, 7, 302, 384, IM_BARRELFALL, 6, "bar_f44.bmp", &tcolor_img)-> position_add(PS_BARRELFALL, 8, 243, 127, IM_BARRELFALL, 1)-> // 61 position_add(PS_BARRELFALL, 9, 244, 147, IM_BARRELFALL, 6, "bar_f44.bmp", &tcolor_img)-> // 62 position_add(PS_BARRELFALL, 10, 245, 178, IM_BARRELFALL, 7, "bar_f63.bmp", &tcolor_img); // hook data(). position_add(PS_HOOK, 1, 275, 128, IM_HOOK, 1, "gancio1.bmp", &tcolor_img)-> position_add(PS_HOOK, 2, 283, 131, IM_HOOK, 2, "gancio2.bmp", &tcolor_img)-> position_add(PS_HOOK, 3, 293, 132, IM_HOOK, 3, "gancio3.bmp", &tcolor_img)-> position_add(PS_HOOK, 4, 298, 134, IM_HOOK, 4, "gancio4.bmp", &tcolor_img)-> position_add(PS_HOOK, 5, 304, 135, IM_HOOK, 5, "gancio5.bmp", &tcolor_img); // crane data(). position_add(PS_CRANE, 1, 306, 151, IM_CRANE, 1, "gru1.bmp", &tcolor_img)-> position_add(PS_CRANE, 2, 294, 125, IM_CRANE, 2, "gru2.bmp", &tcolor_img)-> position_add(PS_CRANE, 3, 288, 88, IM_CRANE, 3, "gru3.bmp", &tcolor_img); // heart data(). position_add(PS_HEART, 1, 144, 91, IM_HEART, 1, "heart1.bmp", &tcolor_img)-> position_add(PS_HEART, 2, 149, 85, IM_HEART, 2, "heart2.bmp", &tcolor_img); // key data(). position_add(PS_KEY, 1, 266, 102, IM_KEY, 1, "key1.bmp", &tcolor_img)-> position_add(PS_KEY, 2, 271, 102, IM_KEY, 2, "key2.bmp", &tcolor_img)-> position_add(PS_KEY, 3, 276, 102, IM_KEY, 3, "key3.bmp", &tcolor_img)-> position_add(PS_KEY, 4, 280, 192, IM_KEY, 4, "key4.bmp", &tcolor_img); // kong up data(). position_add(PS_KONGUP, 1, 160, 84, IM_KONGUP, 1, "kong2up.bmp", &tcolor_img)-> position_add(PS_KONGUP, 2, 200, 84, IM_KONGUP, 2, "kong4up.bmp", &tcolor_img)-> position_add(PS_KONGUP, 3, 232, 84, IM_KONGUP, 3, "kong6up.bmp", &tcolor_img); // kong down data(). position_add(PS_KONGDOWN, 1, 154, 96, IM_KONGDOWN, 1, "kong2dwn.bmp", &tcolor_img)-> position_add(PS_KONGDOWN, 2, 193, 95, IM_KONGDOWN, 2, "kong4dwn.bmp", &tcolor_img)-> position_add(PS_KONGDOWN, 3, 228, 95, IM_KONGDOWN, 3, "kong6dwn.bmp", &tcolor_img); // kong fall data(). position_add(PS_KONGFALL, GW_INDEX_DEFAULT, 258, 180, IM_KONGFALL, GW_INDEX_DEFAULT, "kongfall.bmp", &tcolor_img); // lever data(). position_add(PS_LEVER, 1, 149, 172, IM_LEVER, 1, "leva_giu.bmp", &tcolor_img)-> position_add(PS_LEVER, 2, 145, 162, IM_LEVER, 2, "leva_su.bmp", &tcolor_img); // mario data(). position_add(PS_MARIO, 1, 153, 155, IM_MARIO, 1, "mario22a.bmp", &tcolor_img)-> position_add(PS_MARIO, 2, 157, 155, IM_MARIO, 2, "mario22b.bmp", &tcolor_img)-> position_add(PS_MARIO, 3, 150, 187, IM_MARIO, 3, "mario24.bmp", &tcolor_img)-> position_add(PS_MARIO, 4, 149, 371, IM_MARIO, 4, "mario25.bmp", &tcolor_img)-> position_add(PS_MARIO, 5, 149, 389, IM_MARIO, 5, "mario26.bmp", &tcolor_img)-> position_add(PS_MARIO, 6, 148, 450, IM_MARIO, 6, "mario27.bmp", &tcolor_img)-> position_add(PS_MARIO, 7, 151, 431, IM_MARIO, 7, "mario27j.bmp", &tcolor_img)-> position_add(PS_MARIO, 8, 181, 391, IM_MARIO, 8, "mario36.bmp", &tcolor_img)-> position_add(PS_MARIO, 9, 183, 446, IM_MARIO, 9, "mario37.bmp", &tcolor_img)-> position_add(PS_MARIO, 10, 203, 156, IM_MARIO, 10, "mario42.bmp", &tcolor_img)-> position_add(PS_MARIO, 11, 213, 395, IM_MARIO, 11, "mario46.bmp", &tcolor_img)-> position_add(PS_MARIO, 12, 214, 376, IM_MARIO, 12, "mario46j.bmp", &tcolor_img)-> position_add(PS_MARIO, 13, 214, 444, IM_MARIO, 13, "mario47.bmp", &tcolor_img)-> position_add(PS_MARIO, 14, 245, 397, IM_MARIO, 14, "mario56.bmp", &tcolor_img)-> position_add(PS_MARIO, 15, 245, 380, IM_MARIO, 15, "mario56j.bmp", &tcolor_img)-> position_add(PS_MARIO, 16, 245, 441, IM_MARIO, 16, "mario57.bmp", &tcolor_img)-> position_add(PS_MARIO, 17, 245, 423, IM_MARIO, 17, "mario57j.bmp", &tcolor_img)-> position_add(PS_MARIO, 18, 234, 154, IM_MARIO, 18, "mario62.bmp", &tcolor_img)-> position_add(PS_MARIO, 19, 257, 136, IM_MARIO, 19, "mario62a.bmp", &tcolor_img)-> position_add(PS_MARIO, 20, 284, 151, IM_MARIO, 20, "mario62b.bmp", &tcolor_img)-> position_add(PS_MARIO, 21, 273, 164, IM_MARIO, 21, "mario62c.bmp", &tcolor_img)-> position_add(PS_MARIO, 22, 286, 188, IM_MARIO, 22, "mario62d.bmp", &tcolor_img)-> position_add(PS_MARIO, 23, 309, 187, IM_MARIO, 23, "mario62e.bmp", &tcolor_img)-> position_add(PS_MARIO, 24, 272, 400, IM_MARIO, 24, "mario66.bmp", &tcolor_img)-> position_add(PS_MARIO, 25, 274, 439, IM_MARIO, 25, "mario67.bmp", &tcolor_img); // platform data(). position_add(PS_PLAT, 1, 137, 130, IM_PLAT, 1, "sbarregi.bmp", &tcolor_img)-> position_add(PS_PLAT, 2, 152, 122, IM_PLAT, 2, "sbarresu.bmp", &tcolor_img); // binder data(). position_add(PS_BINDER, 1, 148, 359, IM_BINDER, 1, "trave2.bmp", &tcolor_img)-> position_add(PS_BINDER, 2, 177, 362, IM_BINDER, 2, "trave3.bmp", &tcolor_img)-> position_add(PS_BINDER, 3, 209, 365, IM_BINDER, 3, "trave4.bmp", &tcolor_img)-> position_add(PS_BINDER, 4, 239, 368, IM_BINDER, 4, "trave5.bmp", &tcolor_img)-> position_add(PS_BINDER, 5, 271, 370, IM_BINDER, 5, "trave6.bmp", &tcolor_img); // numbers data(). position_add(PS_NUMBER, 1, 274, 468)-> position_add(PS_NUMBER, 2, 286, 468)-> position_add(PS_NUMBER, 3, 304, 468)-> position_add(PS_NUMBER, 4, 316, 468)-> position_add(PS_SEMICOLON, 0, 298, 472, IM_SEMICOLON, 0, "time_pp.bmp", &tcolor_img); for (int i=0; i<10; i++) { sprintf(sname, "num%d.bmp", i); data().image_add(IM_NUMBER, i, sname, &tcolor_img); } display_number(1, 1, false); display_number(2, 2, false); display_number(3, 9, false); display_number(4, 9, false); // options data(). position_add(PS_GAMEA, GW_INDEX_DEFAULT, 302, 384, IM_GAMEA, GW_INDEX_DEFAULT, "game_a.bmp", &tcolor_img)-> position_add(PS_GAMEB, GW_INDEX_DEFAULT, 302, 394, IM_GAMEB, GW_INDEX_DEFAULT, "game_b.bmp", &tcolor_img)-> position_add(PS_ALARM, GW_INDEX_DEFAULT, 302, 402, IM_ALARM, GW_INDEX_DEFAULT, "alarm.bmp", &tcolor_img)-> position_add(PS_AM, GW_INDEX_DEFAULT, 263, 468, IM_AM, GW_INDEX_DEFAULT, "time_am.bmp", &tcolor_img)-> position_add(PS_PM, GW_INDEX_DEFAULT, 263, 478, IM_PM, GW_INDEX_DEFAULT, "time_pm.bmp", &tcolor_img); // sounds data(). sound_add(SND_BARREL, "barrel.wav")-> sound_add(SND_BONUS, "bonus.wav")-> sound_add(SND_FALL, "fall.wav")-> sound_add(SND_JUMP, "jump.wav")-> sound_add(SND_KONGFALL, "kongfall.wav")-> sound_add(SND_MISS, "miss.wav")-> sound_add(SND_OVER, "over.wav")-> sound_add(SND_STEP, "step.wav"); // timers /* data(). timer_add(TMR_GAME, 250, true)-> timer_add(TMR_GAMESTART, 1800, false)-> timer_add(TMR_REPRISE, 1100, false)-> timer_add(TMR_GAMEOVER, 100, false)-> timer_add(TMR_GAMEOVERSOUND, 3500, false)-> timer_add(TMR_GAMEOVERWAIT, 30000, false); */ }
GW_GameEngine_VTech::GW_GameEngine_VTech(int engineoptions) : GW_Game(), engineoptions_(engineoptions), mode_(MODE_OFF), gameover_(true) { char sname[50]; // transparent colors GW_PLATFORM_RGB(tcolor_bg, 255, 0, 255); GW_PLATFORM_RGB(tcolor_img, 255, 255, 255); // bg data(). image_add(IM_BG, GW_INDEX_DEFAULT, "bg.bmp", &tcolor_bg); // numbers data(). position_add(PS_NUMBER, 1, 250, 61)-> position_add(PS_NUMBER, 2, 265, 61)-> position_add(PS_NUMBER, 3, 284, 61)-> position_add(PS_NUMBER, 4, 299, 61)-> position_add(PS_SEMICOLON, 0, 280, 67, IM_SEMICOLON, 0, "im_time_semicolon.bmp", &tcolor_img); int nmax=10; if ((engineoptions_&EO_NUMBERSEPARATED)==EO_NUMBERSEPARATED) nmax=40; for (int i=0; i<nmax; i++) { if ((engineoptions_&EO_NUMBERSEPARATED)==EO_NUMBERSEPARATED) sprintf(sname, "im_number_%d_%d.bmp", (i/10)+1, i%10); else sprintf(sname, "im_number_%d.bmp", i); data().image_add(IM_NUMBER, i, sname, &tcolor_img); } display_number(1, 8, false); display_number(2, 8, false); display_number(3, 8, false); display_number(4, 8, false); // miss data(). position_add(PS_MISS, 1, 330, 62)-> position_add(PS_MISS, 2, 343, 62)-> position_add(PS_MISS, 3, 356, 62)-> position_add(PS_MISS, 4, 371, 62)-> position_add(PS_MISS, 5, 385, 62)-> position_add(PS_MISS, 6, 329, 80)-> position_add(PS_MISS, 7, 344, 80)-> position_add(PS_MISS, 8, 356, 80)-> position_add(PS_MISS, 9, 371, 80)-> position_add(PS_MISS, 10, 383, 80); if ((engineoptions_&EO_MISSSEPARATED)!=EO_MISSSEPARATED) data().image_add(IM_MISS, GW_INDEX_DEFAULT, "im_miss.bmp", &tcolor_img); for (int i=1; i<=10; i++) { if ((engineoptions_&EO_MISSSEPARATED)==EO_MISSSEPARATED) { sprintf(sname, "im_miss_%02d.bmp", i); data().image_add(IM_MISS, i, sname, &tcolor_img); } data().position_get(PS_MISS, i)->image_set(IM_MISS, ((engineoptions_&EO_MISSSEPARATED)==EO_MISSSEPARATED?i:GW_INDEX_DEFAULT)); } // options data(). position_add(PS_GAMEA, 0, 153, 61, IM_GAMEA, GW_INDEX_DEFAULT, "im_game_a.bmp", &tcolor_img)-> position_add(PS_GAMEB, 0, 153, 76, IM_GAMEB, GW_INDEX_DEFAULT, "im_game_b.bmp", &tcolor_img)-> position_add(PS_ALARM, 0, 200, 77, IM_ALARM, GW_INDEX_DEFAULT, "im_alarm.bmp", &tcolor_img)-> position_add(PS_BELL, 0, 179, 63, IM_BELL, GW_INDEX_DEFAULT, "im_bell.bmp", &tcolor_img)-> position_add(PS_CHRONO, 0, 217, 77, IM_CHRONO, GW_INDEX_DEFAULT, "im_chrono.bmp", &tcolor_img)-> position_add(PS_DATE, 0, 232, 77, IM_DATE, GW_INDEX_DEFAULT, "im_date.bmp", &tcolor_img)-> position_add(PS_TIME1, 0, 223, 61, IM_TIME1, GW_INDEX_DEFAULT, "im_time_1.bmp", &tcolor_img)-> position_add(PS_TIME2, 0, 200, 61, IM_TIME2, GW_INDEX_DEFAULT, "im_time_2.bmp", &tcolor_img)-> position_add(PS_AM, 0, 315, 61, IM_AM, GW_INDEX_DEFAULT, "im_time_am.bmp", &tcolor_img)-> position_add(PS_PM, 0, 314, 76, IM_PM, GW_INDEX_DEFAULT, "im_time_pm.bmp", &tcolor_img); // timers data(). timer_add(TMR_GAME, 250, true)-> timer_add(TMR_GAMESTART, 1800, false)-> timer_add(TMR_REPRISE, 1100, false)-> timer_add(TMR_GAMEOVER, 100, false)-> timer_add(TMR_GAMEOVERSOUND, 3500, false)-> timer_add(TMR_GAMEOVERWAIT, 30000, false); }
void next_level_display(struct Game *game) { display_quad(game->graphics.level_texture, 0, 0, screen_vertices()); display_number(game, game->level); }
//Displays current time //Brightness level is an amount of time the LEDs will be in - 200us is pretty dim but visible. //Amount of time during display is around : [ BRIGHT_LEVEL(us) * 5 + 10ms ] * 10 //Roughly 11ms * 10 = 110ms //Time on is in (ms) void display_time(uint16_t time_on) { //uint16_t bright_level = 1000; uint16_t bright_level = 50; //uint16_t bright_level = 100; //time_on /= 11; //Take the time_on and adjust it for the time it takes to run the display loop below for(uint16_t j = 0 ; j < time_on ; j++) { amMark++; #ifdef NORMAL_TIME //Display normal hh:mm time if(hours > 9) { display_number(hours / 10, 1); //Post to digit 1 delay_us(bright_level); } display_number(hours % 10, 2); //Post to digit 2 delay_us(bright_level); display_number(minutes / 10, 3); //Post to digit 3 delay_us(bright_level); display_number(minutes % 10, 4); //Post to digit 4 delay_us(bright_level); #else //During debug, display mm:ss display_number(minutes / 10, 1); delay_us(bright_level); display_number(minutes % 10, 2); delay_us(bright_level); display_number(seconds / 10, 3); delay_us(bright_level); display_number(seconds % 10, 4); delay_us(bright_level); #endif //Flash colon for each second if(flip == 1) { display_number(10, 5); //Post to digit COL delay_us(bright_level); } //Indicate wether the alarm is on or off if( (PINB & (1<<BUT_ALARM)) != 0) { display_number(11, 4); //Turn on dot on digit 4 delay_us(bright_level); //If the alarm slide is on, and alarm_going is true, make noise! if(alarm_going == TRUE && flip_alarm == 1) { clear_display(); siren(500); flip_alarm = 0; } } else { snooze = FALSE; //If the alarm switch is turned off, this resets the ~9 minute addtional snooze timer hours_alarm_snooze = 88; //Set these values high, so that normal time cannot hit the snooze time accidentally minutes_alarm_snooze = 88; seconds_alarm_snooze = 88; } //Check whether it is AM or PM and turn on dot if((ampm == AM)&&(amMark>=5)) { amMark = 0; // This variable is used to help dim the am/pm dot display_number(12, 6); //Turn on dot on apostrophe delay_us(bright_level); } clear_display(); delay_us(bright_level); } }
void main(void) { /* Configure the oscillator for the device */ ConfigureOscillator(); /* Initialize I/O and Peripherals for application */ InitApp(); select_chip(1); // Select the ADT7320 SSPBUF = 0b00001000; // Command byte indicating a write buf_wait(); SSPBUF = 0b00000000; // Write to the ADT7320 config register buf_wait(); select_chip(2); // Select the AD7793 ADC SSPBUF = 0b00001000; // Command byte indicating a write to the buf_wait(); // mode register SSPBUF = 0b00000000; // First 8 bits of the 16 bit mode register buf_wait(); SSPBUF = 0b11000001; // Second 8 bits of the mode register buf_wait(); select_chip(1); SSPBUF = 0b01010000; // Command byte to read temperature buf_wait(); int junc_bin = SSPBUF/1000; float junc_temp = 25; int loop_counter = 0; while(1) { PORTCbits.RC6 = 0b1; PORTCbits.RC7 = 0b1; PORTBbits.RB5 = 0b1; PORTBbits.RB4 = 0b1; PORTBbits.RB3 = 0b1; PORTBbits.RB2 = 0b1; PORTBbits.RB1 = 0b1; PORTBbits.RB0 = 0b1; PORTA = 0b11110111; for (int thermo_sel = 1; thermo_sel < 3; thermo_sel++) { select_chip(2); SSPBUF = 0b00010000; // Command byte indicating a write to the buf_wait(); // config register for the thermocouple SSPBUF = 0b01000110; // First 8 bits of the 16 bit config register buf_wait(); // for the thermocouple switch (thermo_sel) { case 1: SSPBUF = 0b10010000; // Second 8 bits for the first thermo buf_wait(); break; case 2: SSPBUF = 0b10010001; // Second 8 bits for the second thermo buf_wait(); break; } int not_ready = 1; while (not_ready == 1) { SSPBUF = 0b01000000; // Command byte to read status buf_wait(); not_ready = SSPBUF/10000000; } SSPBUF = 0b01011000; // Command byte to read from first thermo buf_wait(); float thermo_v = 0; for (int i=0; i<3; i++) { //thermo_v += (binary_decimal(SSPBUF) * (16 - i * 8)); } junc_temp = (binary_decimal(junc_bin))/16.0; // if (junc_temp/1000000000000) {junc_temp = (binary_decimal(junc_bin) - 8192)/16.0;} float tc = temp_voltage(junc_temp) + thermo_v; seven_segment(voltage_temp(tc), thermo_sel); } loop_counter++; if (loop_counter > 100) { loop_counter = 0; select_chip(1); SSPBUF = 0b01010000; // Command byte to read temperature buf_wait(); junc_bin = SSPBUF; } char* str = display_number(216.98); char strval[5]; for (int i=0; i<6; i++) {strval[i] = *(str+i);} char digit = strval[0]; int val = 5; switch (digit) { case 0x30: val = 0; break; case 0x31: val = 1; break; case 0x32: val = 2; break; } int result = val; /* TODO <INSERT USER APPLICATION CODE HERE> */ } }