Beispiel #1
0
void error(void){
    set_all_leds(POWER,0,0);
    sound_start(4);
    delay(100);
    sound_stop();
    set_all_leds(0,0,0);
    delay(50);
    set_all_leds(POWER,0,0);
    sound_start(4);
    delay(100);
    sound_stop();
    set_all_leds(0,0,0); 
    delay(10);
}
Beispiel #2
0
/**
 * State machine for menu and display
 */
void run_states(uint8_t state, s_time* time) {
	// State machine zum Ändern der Uhrzeit
	switch (0xf0 & state) {
	case STATE_MENU_SECOND:
		set_all_leds(1);
		if (b_pressed()) {
			add_second(time, 0);
		}
		display_seconds(*time);
		break;
	case STATE_MENU_MINUTE:
		set_all_leds(1);
		if (b_pressed()) {
			add_minute(time, 0);
		}
		display_minutes(*time);
		break;
	case STATE_MENU_HOUR:
		set_all_leds(1);
		if (b_pressed()) {
			add_hour(time);
		}
		display_hours(*time);
		break;
	case STATE_NONE:

		set_all_leds(0);

#ifdef WITH_ENLIGHT
		if (enlight > 0) {
#endif
			display_seconds(*time);
			display_minutes(*time);
			display_hours(*time);
#ifdef WITH_ENLIGHT
			enlight--;
		}
#endif

		add_second(time, 1);
		break;
	}
}
Beispiel #3
0
static void apply_led_effect(_ControlledLeds leds) {
    BOOL counter_finished = leds->effect_counter >= leds->max_effect_counter - 1;

    switch (leds->state) {
        case LedsDisabled:
            // Nothing, don't override other effects.
            break;
        case LedsEnabled:
            set_all_leds(leds, TRUE);
            break;
        case LedsBlinking:
            set_all_leds(leds, leds->effect_state % 2 == 0);
            break;
        case LedsBlinkingFast:
            set_all_leds(leds, leds->effect_state % 2 == 0);
            break;
        case LedsFlash:
            set_all_leds(leds, TRUE);
            if (counter_finished) {
                leds->state = LedsDisabled;
            }
            break;
        case LedsLongFlash:
            set_all_leds(leds, TRUE);
            if (counter_finished) {
                leds->state = LedsDisabled;
            }
            break;
        case LedsGroupRunning:
        case LedsGroupRun:
            set_all_leds(leds, FALSE);
            uint8_t active = leds->effect_state;
            uint8_t max_effect_state = 2*leds->count - 2;
            if (active >= leds->count) {
                // Running downwards
                active = max_effect_state - active;
            }
            leds->leds[active]->enabled = TRUE;

            if (counter_finished) {
                if (leds->effect_state >= max_effect_state) {
                    if (leds->state == LedsGroupRun) {
                        leds->state = LedsDisabled;
                    } else {
                        leds->effect_state = 0;
                    }
                }
            }
            break;
        case LedsInvalid:
            // Nothing
            break;
    }
    if (counter_finished) {
        leds->effect_counter = 0;
        leds->effect_state++;
    } else {
        leds->effect_counter++;
    }
}
Beispiel #4
0
void main (void)
{
    // Connect to our drivers for the TFT, touch sensor.
    tft_touch = touchscreen_open(TOUCHSCREEN_1);
    ptr = pointer_open(POINTER_1);
    display = graphics_open(GRAPHICS_1);
    canvas = graphics_get_visible_canvas(display);
    leds = led_open(DRV_LED_1);
    led_turn_all_off(leds);

    // Clear screen
    graphics_fill_canvas(canvas, BLACK);
    graphics_set_visible_canvas(display, canvas);

    // Update display and turn off LEDs
    while(!graphics_visible_canvas_is_set(display));

    // Set up and calibrate touch screen.
    touchscreen_set_callback(tft_touch, draw_mark, canvas);
    while(!touchscreen_calibrate(tft_touch, 320, 240))
    {
        set_all_leds(0xFF0000); // If Touchscreen can't calibrate RED ALERT!
    }
    led_turn_all_off(leds);

    // Put colormap on TFT
    graphics_draw_bitmap(canvas, bmp, 0, 0, 320, 240, 0);
    graphics_set_visible_canvas(display, canvas);

    // Start picking colors!
    while(1)
    {
        if (pointer_update(ptr, pointer_state))
        {
            set_all_leds(graphics_get_pixel(canvas, pointer_state->x, pointer_state->y));
        }
    }
}
Beispiel #5
0
void main(){
  
    unsigned char digit,button;
    unsigned int len,i;
    unsigned int g_seed;
    unsigned int Xn_1;
    
    setup();
    
    set_all_leds(0,0,0);
    delay(5);
    set_all_leds(0,0,0);
    delay(5);   
    
    wait_button();      // Ожидание нажатия для начала раунда
    start_flash();      // Стартовое приветствие
    g_seed = get_seed(); // Захват стартового значения для ПСП
    delay(150);
    len = 1;            // Установка длинны последовательности
    

    while(1){
        ///////////////////////////////////////////////
        //   Демонстрация последовательности
        ///////////////////////////////////////////////
        Xn_1 = g_seed;
        for(i=0;i<len;i++){

            digit = get_next_psevdo_digit(&Xn_1);
            show_color(digit);

            delay(100); 
            sound_stop();
            set_all_leds(0,0,0);
            delay(50);
        }  // Показали Последовательность  

        /////////////////////////////////////////////////////// 
        //   ВВод и проверка последовательности
        ///////////////////////////////////////////////////////
        Xn_1 = g_seed;
        for(i=0;i<len;i++){
            
            digit = get_next_psevdo_digit(&Xn_1);
             button = wait_button();
            if(digit != button){
                error();            //  Ошибка
                break;      
            }else{                  // Ответ верен
                show_color(digit);  // Индикация правильного ответа
                delay(100); 
                sound_stop();
                set_all_leds(0,0,0);
                delay(10);
            }
        }//for   
        
        if(digit == button){        // Если Всё верно
            delay(30);          
            set_all_leds(10,10,10); // Индикация, что ответ был правильный
            delay(5);
            set_all_leds(0,0,0);
            delay(100);
            len++;                  // Увеличение длинны последовательности
            continue;
        }else{
            wait_button();          // Ожидание нажатия для начала следующего раунда
            start_flash();          // Стартовое приветствие
            g_seed = get_seed();    // Захват стартового значения для ПСП
            delay(10);
            len = 1;                // Установка длинны последовательности
        }
        
    
    }



}
void loop() {
	mil = millis();
/*
  if( mil > when_next ){    // debug, mrygaj co 1 sek
		if( bitRead(sending, 0 ) ){  sendVal(0);}
		if( bitRead(sending, 1 ) ){  sendVal(1);}
		if( bitRead(sending, 2 ) ){  sendVal(2);}
		if( bitRead(sending, 3 ) ){  sendVal(3);}
		if( bitRead(sending, 4 ) ){  sendVal(4);}
		if( bitRead(sending, 5 ) ){  sendVal(5);}
		if( bitRead(sending, 6 ) ){  sendVal(6);}
		if( bitRead(sending, 7 ) ){  sendVal(7);}
		if( bitRead(sending, 8 ) ){  sendVal(8);}
		if(sending > 0){
			Serial.println();
		}
		when_next = mil + time;
	}*/
	if( pcb_type == 3 && divider-- == 0 ){
		boolean power = digitalRead( PIN_B3_POWER_SENSOR );
		if( power == LOW ){
			low_for_sure++;
			divider = PWR_SENSOR_DIV/2;		// high speed checking
			if( low_for_sure > 90 ){
				Serial.println("F0");
				Serial.flush();
			}
		}else{
			low_for_sure = 0;
			divider = PWR_SENSOR_DIV;
		}
	}
	
	readHall();
	step_servoY();
	step_servoZ();
	
	if(stepperIsReady){
		sendStepperReady();
		stepperIsReady = false;
	}
	/*
	if(pre--){
		int16_t val1 = analogRead( PIN_B2_WEIGHT );
		agv = (val1 + agv * 3)>>2;
		if( val1 - agv > 2 ){
			byte r = abs(val1 - agv);
			bottom_panels.setPixelColor(0, r,0,0 );
			bottom_panels.show();

		}else if( val1 - agv < 2 ){
			byte g = abs(val1 - agv);
			bottom_panels.setPixelColor(1, 0,g,0 );
			bottom_panels.show();
		}
	}*/

	if( mil - last_android > MAX_TIME_WITHOUT_ANDROID ){			// no android
		last_android	= mil;
		disableServosNow();
		stepperX.disableOutputs();
	//	unsigned long int color = bottom_panels.Color(20,  0,  0 );	
	//	set_all_leds(color);
		Serial.println("RRNOMASTER");
		Serial.flush();
	}
	if( servo_start_time != 0 ){
		unsigned long period = millis() - servo_start_time;
		if( period > SERVO_MAX_TIME ){		// emergency stop
			disableServosNow();
			servo_start_time = 0;
			unsigned long int color = bottom_panels.Color(255,  0,  0 );
			set_all_leds(color);
			Serial.println("RRSERVOOFF");
			Serial.flush();
		}
	}
	if( mil - last_poke > POKE_ANDROID_TIME ){			// no android
		Serial.print("POKE ");
		Serial.println(String(mil));
		Serial.flush();
		last_poke = mil;
	}
}
inline void init_leds(){
	top_panels.begin();
	bottom_panels.begin();
	unsigned long int color = bottom_panels.Color(50,  0,  0 );
	set_all_leds(color);
}
void setup(){
	Serial.begin(B2_SERIAL0_BOUND);
	serial0Buffer = "";
	Serial.println("");	// remove dust
	Serial.flush();

	// read pcb type	
	pinMode( PIN_B3_POWER_SENSOR, INPUT );
	boolean power = digitalRead( PIN_B3_POWER_SENSOR );
	if( power == LOW ){
		Serial.println("-chyba 2");
	}else{
		Serial.println("-chyba 3");
	}

	//pcb_type
	disableYZ();
	if(pcb_type == 2 ){		// servos + magicled
		//pinMode(PIN_B2_SERVO_Y, INPUT+INPUT_PULLUP );      // nie pozwalaj na przypadkowe machanie na starcie
		//pinMode(PIN_B2_SERVO_Z, INPUT+INPUT_PULLUP );      // nie pozwalaj na przypadkowe machanie na starcie
		pinMode(PIN_B2_SELF_RESET, INPUT );	
		pinMode(PIN_B2_HALL_X, INPUT + INPUT_PULLUP );
		pinMode(PIN_B2_HALL_Y, INPUT + INPUT_PULLUP );
		pinMode(PIN_B2_WEIGHT, INPUT);

	}else if(pcb_type == 3 ){		// actuators + magicled
		if(YZ_INPUT_ON_DISABLE){
			pinMode(PIN_B3_OUT_Y1, INPUT );		// stop Y
			pinMode(PIN_B3_OUT_Y2, INPUT );		// stop Y		
			pinMode(PIN_B3_OUT_Z1, INPUT );		// stop Z	
			pinMode(PIN_B3_OUT_Z2, INPUT );		// stop Z
		}else{
			pinMode(PIN_B3_OUT_Y1, OUTPUT);
			pinMode(PIN_B3_OUT_Y2, OUTPUT);
			pinMode(PIN_B3_OUT_Z1, OUTPUT);
			pinMode(PIN_B3_OUT_Z2, OUTPUT);
			pinMode(PIN_B3_LIGHT, INPUT );

			digitalWrite(PIN_B3_OUT_Y1, YZ_VALUE_ON_DISABLE);		// stop Y
			digitalWrite(PIN_B3_OUT_Y2, YZ_VALUE_ON_DISABLE);
			digitalWrite(PIN_B3_OUT_Z1, YZ_VALUE_ON_DISABLE);		// stop Z
			digitalWrite(PIN_B3_OUT_Z2, YZ_VALUE_ON_DISABLE);	

		}
		//pinMode(PIN_B3_POWER_SENSOR, INPUT + INPUT_PULLUP );
		pinMode(PIN_B3_POWER_SENSOR, INPUT );	
	}

	// blink led	
	pinMode(PIN_B2_STEPPER_DIR, OUTPUT );
	for(byte i =0; i<pcb_type;i++){
		digitalWrite( PIN_B2_STEPPER_DIR, HIGH );
		delay(100);
		digitalWrite( PIN_B2_STEPPER_DIR, LOW );
		delay(200);
	}
	init_leds();
	setupStepper();

	unsigned long int color = bottom_panels.Color(0,  0,  20 );	
	set_all_leds(color);
	Serial.println("");	// remove dust
	Serial.flush();
	Serial.println("BSTART");

	if(pcb_type == 2 ){		// servos + magicled
		init_hallx(PIN_B2_HALL_X);
	}else if(pcb_type == 3 ){
		init_hallx(PIN_B3_IN_X);
	}

	sendStats( true );
	Serial.flush();
}