void state_find_track_control_logic() {			
	if (state_find_track_data.not_first_run == false){
		status.system.start_line=false;
		state_find_track_data.not_first_run = true;
		task_t system_state = {.data.command = STATE_COMMAND, .data.timestamp=0, .data.value=STATE_IDLE};
		add_task(&system_state);
		set_m_forward();
		l_motor.rpm = 100;
		r_motor.rpm = 100;
		state_find_track_data.exp = false;
		tmr_start(&state_timer,STATE_FIND_TRACK_SENSOR_BLACKOUT_INTERVAL); 
	}
	
	if (state_find_track_data.exp == true || tmr_exp(&state_timer)){
		state_find_track_data.exp = true;
		read_switches();
		uint8_t sensor_value = led.array;
		if ((sensor_value & 0x3f)!= 0x3f)
		{
			state_find_track_data.exp=false;
			state_find_track_go_a_bit_more_control_data.not_first_run=false;
			set_state(state_find_track_go_a_bit_more_control_logic);
		}
		return;	
	}
}
Пример #2
0
static uint8_t read_switches_debounced()
{
    uint8_t state;

    state = read_switches();
    _delay_ms(DEBOUNCE_DELAY_1);
    state |= read_switches();

    if (state)
    {
        _delay_ms(DEBOUNCE_DELAY_2);
        // If during debounce delay switches (one or more) 
        // where pressed, then consider this as really pressed (debounced) switch(es)
        return state & read_switches();
    }
    return 0;
}
Пример #3
0
/***********************************************
Isolate the button's row:
Assuming Button is still pushed.  
(This has to be done quickly after a detect)
Return : stored in keys[] file scope variable
array[0] 	Front Row
array[1]   Front Row (5)
array[2] 	 	 Row (4)
array[3] 	  	 Row (3)
array[4]   		 Row (2)
************************************************/
void scan_keys( byte* mkeys )
{
  all_rows_high();
  for (int i=0; i<NUM_ROWS; i++)
  {
     set_row( i, 0 );
	 delay(CHARGE_TIME);
	 mkeys[i] = read_switches();		// upper nibble
     set_row( i, 1 );				// restore so not to affect the next row
  }
}
Пример #4
0
void do_computer_control(void) {

  while (1) {
    read_switches();
    if (function_changed) {
      // oops i guess they want something else, return!
      clear_all_leds();
      clock_leds();
      return;
    }
    
    //putstring("computer kontrol\n\r");
    
  }
}
Пример #5
0
void do_keyboard_mode(void) {
  signed int shift = 0;
  uint8_t accent=0, slide=0;
  uint8_t i, last_bank;
  
  // turn tempo off!
  turn_off_tempo();
  
  clear_bank_leds();

  read_switches();
  last_bank = bank;
  has_bank_knob_changed(); // ignore startup change

  while (1) {
    read_switches();

    if (function_changed) {
      midi_notesoff();           // turn all notes off
      return;
    }
  
    // show the current MIDI address
    if (!is_bank_led_set(midi_out_addr)) {
      clear_bank_leds();
      set_bank_led(midi_out_addr);
    }

    if (has_bank_knob_changed()) {
      // bank knob was changed, which means they want a different
      // midi addr... OK then!
      midi_out_addr = bank;

      // set the new midi address (burn to EEPROM)
      internal_eeprom_write8(MIDIOUT_ADDR_EEADDR, midi_out_addr);

      last_bank = bank;
    }

    // show the octave
    display_octave_shift(shift);

    for (i=0; i<13; i++) {
      // check if any notes were just pressed
      if (just_pressed(notekey_tab[i])) {
	note_on((C2+i) + shift*OCTAVE, slide, accent);
	midi_send_note_on( ((C2+i) + shift*OCTAVE) | (accent << 6));
	slide = TRUE;

	// turn on that LED
	set_notekey_led(i);	
      }
      
      // check if any notes were released
      if (just_released(notekey_tab[i])) {
	midi_send_note_off( ((C2+i) + shift*OCTAVE) | (accent << 6));

	// turn off that LED
	clear_notekey_led(i);
      }
    }

    if (just_pressed(KEY_UP)) {
      if (shift < 2)
	shift++;
    } else if (just_pressed(KEY_DOWN)) {
      if (shift > -1)
	shift--;
    } 

    // check if they turned accent on
    if (just_pressed(KEY_ACCENT)) {
      accent = !accent;
      if (accent)
	set_led(LED_ACCENT);
      else
	clear_led(LED_ACCENT);
    }
    
    // if no keys are held down and there was a note just playing
    // turn off the note.
    if ((NOTE_PIN & 0x3F) && no_keys_pressed()) {
      note_off(0);
      slide = FALSE;
      clear_notekey_leds();
    }
  }
}
//***********************************
//***********************************
//********** MAIN FUNCTION **********
//***********************************
//***********************************
int main (void)
{
	BYTE display_html_file_name[12];
	DWORD file_size;

	//**********************
	//**********************
	//***** INITIALISE *****
	//**********************
	//**********************
	initialise();





	//*********************
	//*********************
	//***** MAIN LOOP *****
	//*********************
	//*********************
	while(1)						//(Do forever)
	{
		//----- RESET THE WATCHDOG TIMEOUT TIMER -----
		ClearWDT();


		switches_1_new = 0;
		if (do_10ms_functions)
		{
			do_10ms_functions = 0;
		
			//----- READ SWITCHES -----
			read_switches();

		}


		//------------------------------------
		//----- CHECK FOR SWITCH PRESSES -----
		//------------------------------------
		if (SWITCH_UP_NEW_PRESS)
		{
			//----- UP PRESSED -----
			
			//Load the index.htm file
			if (display_html_setup_read_file(index_htm, 0, &file_size))			//Find HTML file ready to display it
				display_html_file(file_size);
		}
		else if (SWITCH_DOWN_NEW_PRESS)
		{
			//----- DOWN PRESSED -----
			
			//Load text1.htm using name as a variable to demonstrate finding file by name at run time
			display_html_file_name[0] = 'T';
			display_html_file_name[1] = 'E';
			display_html_file_name[2] = 'X';
			display_html_file_name[3] = 'T';
			display_html_file_name[4] = '1';
			display_html_file_name[5] = '.';
			display_html_file_name[6] = 'H';
			display_html_file_name[7] = 'T';
			display_html_file_name[8] = 'M';
			display_html_file_name[9] = 0x00;
			
			if (display_html_setup_read_file(0, display_html_file_name, &file_size))
			{
				display_html_file(file_size);
			}

		}
		else if (SWITCH_LEFT_NEW_PRESS)
		{
			//----- LEFT PRESSED -----
			
			//Load dynamic text demo HTML file - the text is added by the html_get_dynamic_text_character function below
			if (display_html_setup_read_file(dyntext_htm, 0, &file_size))
				display_html_file(file_size);
		}
		else if (SWITCH_RIGHT_NEW_PRESS)
		{
			//----- RIGHT PRESSED -----
			
			//Load text2.htm
			if (display_html_setup_read_file(text2_htm, 0, &file_size))
				display_html_file(file_size);
		}
		else if (SWITCH_FIRE_NEW_PRESS)
		{
			//----- FIRE PRESSED -----


			//Generate content using code instead of HTML
			display_clear_screen(DISPLAY_COLOUR_WHITE);
			
			display_bitmap(indeximg_bmp, 0, 0, 0x00ffffff);		//p_bitmap, x_coord, y_coord, transparency_colour(0xffffffff to not use)
		
		

			display_foreground_colour = DISPLAY_COLOUR_RED;
			display_background_colour = DISPLAY_COLOUR_TURQUOISE;
			display_const_string (disp_font_5w_7h, DISPLAY_TEXT_ALIGN_LEFT,				//Font, Options
									2, 2,												//Hoz padding, vertical padding
									20, 50,												//X start coord, Y start coord
									0, 0,												//X end coord, Y end coord (0 if area containment not required)
									string1);											//Text
	
	
			display_const_string(disp_font_5w_11h, DISPLAY_TEXT_ALIGN_LEFT,				//Font, Options
									2, 2,												//Hoz padding, vertical padding
									20, 70,												//X start coord, Y start coord
									0, 0,												//X end coord, Y end coord (0 if area containment not required)
									string1);											//Text


			display_foreground_colour = DISPLAY_COLOUR_VIOLET;
			display_background_colour = DISPLAY_COLOUR_YELLOW;
			display_const_string(disp_font_22h, DISPLAY_TEXT_ALIGN_CENTRE,				//Font, Options
									2, 2,												//Hoz padding, vertical padding
									20, 105,											//X start coord, Y start coord
									200, 160,											//X end coord, Y end coord (0 if area containment not required)
									string1);											//Text



			display_foreground_colour = DISPLAY_COLOUR_BLACK;
			display_background_colour = DISPLAY_COLOUR_NULL;							//(DISPLAY_COLOUR_NULL == no background colour / leave existing colour)
	
			display_const_string(disp_font_15h, DISPLAY_TEXT_ALIGN_LEFT,				//Font, Options
									2, 2,												//Hoz padding, vertical padding
									176, 134,											//X start coord, Y start coord
									0, 0,												//X end coord, Y end coord (0 if area containment not required)
									string1);											//Text


			display_foreground_colour = DISPLAY_COLOUR_WHITE;
			display_background_colour = DISPLAY_COLOUR_BLUE;
			display_const_string(disp_font_42h, DISPLAY_TEXT_ALIGN_CENTRE,				//Font, Options
									2, 2,												//Hoz padding, vertical padding
									0, 170,												//X start coord, Y start coord
									319, 0,												//X end coord, Y end coord (0 if area containment not required)
									string1);											//Text
									

		}

		
	}
}