示例#1
0
int main( void )
{
    /* perform battery check */
    bat_check();
    
    /* display welcome message and  */
    /* seed random number generator */
    clear();
    lcd_goto_xy(0,0);
    print("Welcome!");
    lcd_goto_xy(0,1);
    print("Press B");
    wait_for_button_press(BUTTON_B);   /* button down */
    long seed = 0;
    while(button_is_pressed(BUTTON_B)) /* while button not released */
        seed++;
    srandom(seed);
    
    while(1) 
    {
        clear();
        
        /* obtain random number between 0-9 */
        int val = random() % 10;
        
        /* display number */
        lcd_goto_xy(0,0);
        print_long(val);
        lcd_goto_xy(0,1);
        print("Press B");
        
        /* wait for user to press/release B */
        wait_for_button(BUTTON_B);
    }
}
示例#2
0
int main()
{
  lcd_load_custom_character(happy, 0);
  lcd_load_custom_character(sad, 1);
  lcd_load_custom_character(indifferent, 2);
  lcd_load_custom_character(surprised, 3);
  lcd_load_custom_character(mocking, 4);
  clear();                  // this must be called before we can use the custom characters
  print("mood: ?");

  // initialize the random number generator based on how long we hold the button the first time
  wait_for_button_press(ANY_BUTTON);
  long seed = 0;
  while(button_is_pressed(ANY_BUTTON))
    seed++;
  srandom(seed);

  while(1)
  {
  
    lcd_goto_xy(6, 0);             // move cursor to the correct position
  
    char mood;
    do
    {
      mood = random()%5;
    } while (mood == prevMood);   // ensure we get a new mood that differs from the previous
    prevMood = mood;
  
    print_character(mood);   // print a random mood character
    wait_for_button(ANY_BUTTON);   // wait for any button to be pressed
  }
}
示例#3
0
void loop()                     // run over and over again
{
  // wait here for one of the three buttons to be pushed
  unsigned char button = wait_for_button(ANY_BUTTON);
  clear();
  
  if (button == TOP_BUTTON)
  {
    play_from_program_space(fugue);

    print("Fugue!");
    lcd_goto_xy(0, 1);
    print("flash ->");
  }
  if (button == MIDDLE_BUTTON)
  {
    play("! V8 cdefgab>cbagfedc");
    print("C Major");
    lcd_goto_xy(0, 1);
    print("RAM ->");
  }
  if (button == BOTTOM_BUTTON)
  {
    if (is_playing())
    {
      stop_playing();
      print("stopped");
    }
    else
    {
      play_note(A(5), 200, 15);
      print("note A5"); 
    }
  }
}
示例#4
0
文件: reset.c 项目: Dave2084/freewpc
void system_accept_freewpc (void)
{
	if ((freewpc_accepted[0] == ACCEPT_1) &&
		 (freewpc_accepted[1] == ACCEPT_2) &&
		 (freewpc_accepted[2] == ACCEPT_3))
		return;

	dmd_alloc_low_clean ();
	font_render_string_center (&font_mono5, 64, 3, "FREEWPC");
	font_render_string_center (&font_mono5, 64, 9, "WARNING... BALLY WMS");
	font_render_string_center (&font_mono5, 64, 15, "DOES NOT SUPPORT");
	font_render_string_center (&font_mono5, 64, 21, "THIS SOFTWARE");
	font_render_string_center (&font_mono5, 64, 27, "PRESS ENTER");
	dmd_show_low ();
	wait_for_button (SW_ENTER);

	dmd_alloc_low_clean ();
	font_render_string_center (&font_mono5, 64, 3, "FREEWPC");
	font_render_string_center (&font_mono5, 64, 9, "NO WARRANTY EXISTS");
	font_render_string_center (&font_mono5, 64, 15, "ROM MAY CAUSE DAMAGE");
	font_render_string_center (&font_mono5, 64, 21, "TO REAL MACHINE");
	font_render_string_center (&font_mono5, 64, 27, "PRESS ENTER");
	dmd_show_low ();
	wait_for_button (SW_ENTER);

	dmd_alloc_low_clean ();
	font_render_string_center (&font_mono5, 64, 3, "FREEWPC");
	font_render_string_center (&font_mono5, 64, 9, "IF YOU ARE SURE YOU");
	font_render_string_center (&font_mono5, 64, 15, "WANT TO CONTINUE");
	font_render_string_center (&font_mono5, 64, 21, "PRESS ENTER TWICE");
	dmd_show_low ();
	wait_for_button (SW_ENTER);
	wait_for_button (SW_ENTER);

	dmd_alloc_low_clean ();
	dmd_show_low ();
	task_sleep_sec (1);

	pinio_nvram_unlock ();
	freewpc_accepted[0] = ACCEPT_1;
	freewpc_accepted[1] = ACCEPT_2;
	freewpc_accepted[2] = ACCEPT_3;
	pinio_nvram_lock ();

	factory_reset ();
	warm_reboot ();
}
bool confirm(const char *msg)
{
    bool ret;
    
    rb->splashf(0, "%s ([PLAY] to CONFIRM)", msg);
    
    ret = (wait_for_button() == BUTTON_ON);
    show_info();
    
    return ret;
}
示例#6
0
game_win::game_win(Point xy, int w, int h, const string& title)
	:Simple_window(xy,w,h,title),
	
	a0_but {Point(240,140),100,100,"",
		[](Address, Address pw){reference_to<game_win>(pw).a0();}},
	a1_but {Point(350,140),100,100,"",
		[](Address, Address pw){reference_to<game_win>(pw).a1();}},
	a2_but {Point(460,140),100,100,"",
		[](Address, Address pw){reference_to<game_win>(pw).a2();}},
	b0_but {Point(240,250),100,100,"",
		[](Address, Address pw){reference_to<game_win>(pw).b0();}},
	b1_but {Point(350,250),100,100,"",
		[](Address, Address pw){reference_to<game_win>(pw).b1();}},
	b2_but {Point(460,250),100,100,"",
		[](Address, Address pw){reference_to<game_win>(pw).b2();}},
	c0_but {Point(240,360),100,100,"",
		[](Address, Address pw){reference_to<game_win>(pw).c0();}},
	c1_but {Point(350,360),100,100,"",
		[](Address, Address pw){reference_to<game_win>(pw).c1();}},
	c2_but {Point(460,360),100,100,"",
		[](Address, Address pw){reference_to<game_win>(pw).c2();}}
{
	a0_x.add(Point(240,140),Point(340,240));
	a0_x.add(Point(340,140),Point(240,240));
	a1_x.add(Point(350,140),Point(450,240));
	a1_x.add(Point(450,140),Point(350,240));
	a2_x.add(Point(460,140),Point(560,240));
	a2_x.add(Point(560,140),Point(460,240));
	b0_x.add(Point(240,250),Point(340,350));
	b0_x.add(Point(340,250),Point(240,350));
	b1_x.add(Point(350,250),Point(450,350));
	b1_x.add(Point(450,250),Point(350,350));
	b2_x.add(Point(460,250),Point(560,350));
	b2_x.add(Point(560,250),Point(460,350));
	c0_x.add(Point(240,360),Point(340,460));
	c0_x.add(Point(340,360),Point(240,460));
	c1_x.add(Point(350,360),Point(450,460));
	c1_x.add(Point(450,360),Point(350,460));
	c2_x.add(Point(460,360),Point(560,460));
	c2_x.add(Point(560,360),Point(460,460));
	
	
	attach(a0_but);
	attach(a1_but);
	attach(a2_but);
	attach(b0_but);
	attach(b1_but);
	attach(b2_but);
	attach(c0_but);
	attach(c1_but);
	attach(c2_but);
	wait_for_button();
}
示例#7
0
void __read_input(uint8_t max_value){

    MenuState->key_pressed = wait_for_button(BUTTON_ANY);

    switch (MenuState->key_pressed){
      case BUTTON_DOWN:
        MenuState->selected_item += 1;
        break;
      case BUTTON_UP:
        MenuState->selected_item -= 1;
        break;  
    }
    MenuState->selected_item = constrain(MenuState->selected_item, 0, max_value - 1);
}
示例#8
0
void _brd_print_warning(){

  lcd_clear12x16();
  print_string(&_saved, 34, 0);

  FontSelector = f6x8;
  Y1 = 17;
  print_string(&brr1, 0, Y1);
  print_string(&brr2, 0, Y1+9);
  print_string(&brr3, 0, Y1+9);
  print_string(&brr4, 0, Y1+9);


  print_string(&_ok, 114, 57);
  lcd_update(); 
  
  wait_for_button(BUTTON_OK);
}
示例#9
0
void calendar_window::refresh(int m, int y)
{
	req_month.label = "Month: ";	// Clear the inbox text
	req_year.label = "Year: ";
	current_month = m;
	current_year = y;
	ostringstream ss;
	ss << m;	// Put the month - currently an int - into the buffer
	string month = ss.str();	// Pull the characters - the month - out of the buffer as a string
	
	ostringstream sss;
	sss << y;	// Put the month - currently an int - into the buffer
	string year = sss.str();	// Pull the characters - the month - out of the buffer as a string
	detach(*month_display);
	month_display = new Text(Point(x_max()/2, 30),  month + " " + year);
	month_display->set_font_size(30);
	attach(*month_display);
	
	wait_for_button();
}
示例#10
0
int main(void)
{
	struct adc_config         adc_conf;
	struct adc_channel_config adcch_conf;

	board_init();
	sysclk_init();
	sleepmgr_init();
	irq_initialize_vectors();
	cpu_irq_enable();

	// Initialize configuration structures.
	adc_read_configuration(&ADCA, &adc_conf);
	adcch_read_configuration(&ADCA, ADC_CH0, &adcch_conf);

	/* Configure the ADC module:
	 * - unsigned, 12-bit results
	 * - bandgap (1 V) voltage reference
	 * - 200 kHz maximum clock rate
	 * - manual conversion triggering
	 */
	adc_set_conversion_parameters(&adc_conf, ADC_SIGN_OFF, ADC_RES_12,
			ADC_REF_BANDGAP);
	adc_set_clock_rate(&adc_conf, 200000UL);
	adc_set_conversion_trigger(&adc_conf, ADC_TRIG_MANUAL, 1, 0);

	adc_write_configuration(&ADCA, &adc_conf);

	/* Configure ADC channel 0:
	 * - single-ended measurement from configured input pin
	 * - interrupt flag set on completed conversion
	 */
	adcch_set_input(&adcch_conf, INPUT_PIN, ADCCH_NEG_NONE,
			1);
	adcch_set_interrupt_mode(&adcch_conf, ADCCH_MODE_COMPLETE);
	adcch_disable_interrupt(&adcch_conf);

	adcch_write_configuration(&ADCA, ADC_CH0, &adcch_conf);

	// Enable the ADC and do one dummy conversion.
	adc_enable(&ADCA);
	adc_start_conversion(&ADCA, ADC_CH0);
	adc_wait_for_interrupt_flag(&ADCA, ADC_CH0);

	// Light up LED 1, wait for button press.
	ioport_set_pin_low(LED1_PIN);
	wait_for_button();

	// Perform oversampling of offset.
	cal_data.offset = get_mean_sample_value();

	// Light up LED 2, wait for button press.
	ioport_set_pin_low(LED2_PIN);
	wait_for_button();

	// Perform oversampling of 0.9 V for gain calibration.
	cal_data.gain = get_mean_sample_value() - cal_data.offset;

	// Turn off LEDs.
	ioport_set_pin_high(LED1_PIN);
	ioport_set_pin_high(LED2_PIN);

	// Enable interrupts on ADC channel, then trigger first conversion.
	adcch_enable_interrupt(&adcch_conf);
	adcch_write_configuration(&ADCA, ADC_CH0, &adcch_conf);
	adc_start_conversion(&ADCA, ADC_CH0);

	do {
		// Sleep until ADC interrupt triggers.
		sleepmgr_enter_sleep();
	} while (1);
}
示例#11
0
int main()
{
	char buffer[20];

	// load the bar graph
	load_custom_characters();

	// configure serial clock for 115.2 kbaud
	serial_set_baud_rate(115200);

	// wait for the device to show up
	while(1)
	{
		clear();
		print("Master");
		delay_ms(100);
		serial_send("\x81",1);

		if(serial_receive_blocking(buffer, 6, 50))
			continue;
		
		clear();
		print("Connect");
		lcd_goto_xy(0,1);
		buffer[6] = 0;
		print(buffer);

		// clear the slave's LCD and display "Connect" and "OK" on two lines
		// Put OK in the center to test x-y positioning
		slave_clear();
		slave_print("Connect");
		slave_lcd_goto_xy(3,1);
		slave_print("OK");

		// play a tune
		char tune[] = "\xB3 l16o6gab>c";
		tune[1] = sizeof(tune)-3;
		serial_send_blocking(tune,sizeof(tune)-1);

		// wait
		wait_for_button(ANY_BUTTON);

		// reset calibration
		slave_reset_calibration();
		
		time_reset();

		slave_auto_calibrate();

		unsigned char speed1 = 0, speed2 = 0;

		// read sensors in a loop
		while(1)
		{
			serial_send("\x87",1); // returns calibrated sensor values
      
			// read 10 characters
			if(serial_receive_blocking(buffer, 10, 100))
				break;

			// get the line position
			serial_send("\xB6", 1);

			int line_position[1];
			if(serial_receive_blocking((char *)line_position, 2, 100))
				break;

			// get the battery voltage
						serial_send("\xB1",1);
      
			// read 2 bytes
			int battery_millivolts[1];
			if(serial_receive_blocking((char *)battery_millivolts, 2, 100))
				break;

			// display readings
			display_levels((unsigned int*)buffer);

			lcd_goto_xy(5,0);
			line_position[0] /= 4; // to get it into the range of 0-1000
			if(line_position[0] == 1000)
				line_position[0] = 999; // to keep it to a maximum of 3 characters 
			print_long(line_position[0]);
			print("   ");

			lcd_goto_xy(0,1);
			print_long(battery_millivolts[0]);
			print(" mV  ");
      
			delay_ms(10);

			// if button A is pressed, increase motor1 speed
			if(button_is_pressed(BUTTON_A) && speed1 < 127)
				speed1 ++;
			else if(speed1 > 1)
				speed1 -= 2;
			else if(speed1 > 0)
				speed1 = 0;

			// if button C is pressed, control motor2
			if(button_is_pressed(BUTTON_C) && speed2 < 127)
				speed2 ++;
			else if(speed2 > 1)
				speed2 -= 2;
			else if(speed2 > 0)
				speed2 = 0;

			// if button B is pressed, do PID control
			if(button_is_pressed(BUTTON_B))
				slave_set_pid(40, 1, 20, 3, 2);
			else
			{
				slave_stop_pid();
				slave_set_motors(speed1, speed2);
			}
		}
	}

	while(1);
}