Example #1
0
void flameflacker()
{
  set_rgb_color(40, 45+random_to(15), 0, 0);
  set_rgb_color(41, 45+random_to(15), 8+random_to(15), 0);
  set_rgb_color(42, 45+random_to(15), 22+random_to(15), 0);
  set_rgb_color(43, 45+random_to(15), 38+random_to(13), 0);
}
static void pin_write_handler(ble_lbs_t * p_lbs, uint8_t * pin_state)
{  
    
    // Sets motor values for every motor.

    twi_set_motor(pin_state);

    // Sets the color for every RGB-LED.

    uint8_t web_color_data = read_byte(pin_state, 5);
    set_rgb_color(web_color_data);

    // Shoots IR-signal.
    if (read_bit(pin_state, 1, 0))
    {
        ir_shooting(pin_state);
        playNote(536);
        nrf_delay_ms(50);
        playNote(536);
    }
    
    // Turns laser on when game session is active
    if(read_bit(pin_state, 1, 1))
    {
       nrf_gpio_pin_set(LASER_TRANSISTOR);
    }
    else
       nrf_gpio_pin_clear(LASER_TRANSISTOR);

    write_car_id(pin_state[19]);
    unique_car_ID = pin_state[19];
}
Example #3
0
void Init_Tisch1()
{
  int t;

  for (t=0; t <= 255;t++) set_rgb_color(t,pal[t].r,pal[t].g,pal[t].b );
  
  Kurven = 0;
  Lichter1(250) = 0;  Lichter1(251) = 0;  Lichter1(252) = 0;
  Lichter2(247) = 0;  Lichter2(248) = 0;  Lichter2(249) = 0;
  Lichter3(244) = 0;  Lichter3(245) = 0;  Lichter3(246) = 0;
  Licht4   = 0;
  PushUp = TRUE;
  Bonus    = 0;
  MAXfarbe = 234; // {235-255}
  temp = 3;
  thermo(temp);
  PCSspe[1] = 0;
  PCSspe[2] = 0;
  PCSspe[3] = 0;
  special = 0;
  BumpCount = 0;

  // Common variables with different values depending on table
  tnr = '1';  // {tablenr}
  ArmXLinks = 79;
  ArmYLinks = 400+135;
  ArmXRechts = 159;
  ArmYRechts = 400+135;
}
Example #4
0
// {z :-> 0-6 }
void thermo(byte tmp)
{
  byte z;

  for (z = 1; z <= 6;z++)
  {
    if (z <= tmp)
	{
		set_rgb_color(55+z, 0,0,47);
	} else
		set_rgb_color(55+z, 50, 0, 0);
  }

  if (temp == 0)
  {
      display("ATTENTION:");
	  do { led_anzeige(TRUE); } while (led_status);
      SDL_Delay(2000);
      display("TEMP. OVERHEAT!");
	  do {led_anzeige(TRUE); } while (led_status);
      SDL_Delay(2000);
      display("TURNED FIRE OFF!");
	  do {led_anzeige(TRUE); } while (led_status);
      SDL_Delay(2000);
      PushUp = FALSE;
      set_rgb_color(40,10,10,60);
      set_rgb_color(41,10,10,50);
      set_rgb_color(42,10,10,40);
      set_rgb_color(43,10,10,30);
  }
}
int main(void)
{ 
    uint32_t err_code;

    //Initialize GPIO
    nrf_gpiote_init();
    pin_output_init(); 
    
    err_code = nrf_drv_ppi_init();
    APP_ERROR_CHECK(err_code);



    // Initialize PWM
    pwm_init(); 

    // Initialize
    timers_init();
    
    ble_stack_init();
    gap_params_init();
    services_init();
    advertising_init();
    conn_params_init();

    //Starts advertising
    advertising_timer_init();
    advertising_start();

    //Initialize shields
    twi_motordriver_init();
    twi_rfid_init();

    // Initialize the IR lib. Must be done after initializing the SoftDevice
    ir_lib_init(IR_OUTPUT_PIN);
    err_code = ir_ppi_init();
    APP_ERROR_CHECK(err_code);

    //Feedback, notifying the user that the DK is ready
    set_rgb_color(0);
    playNote(1607);
    nrf_delay_ms(30);
    playNote(1516);
    nrf_delay_ms(30);
    playNote(1431);

     // Enter main loop.
    for (;;)
    {
        power_manage();
    }
}
static void pin_event_handler(nrf_drv_gpiote_pin_t pin, nrf_gpiote_polarity_t action){
    //if(pin == IR_RECEIVER_PIN_1 || pin == IR_RECEIVER_PIN_2 || pin == IR_RECEIVER_PIN_3){
      
     /*hit_counter = new_hit_value();
      playNote(1516);
      nrf_delay_ms(50);
      playNote(1607);*/

     /* if(pin == IR_RECEIVER_PIN_1) {          
          ir_in_pin_handler(pin, action);
           //ble_lbs_on_button_change(&m_lbs, hit_counter, 0);
      }
      else if(pin == IR_RECEIVER_PIN_2)
            ble_lbs_on_button_change(&m_lbs, hit_counter, 1);
      else if(pin == IR_RECEIVER_PIN_3)
            ble_lbs_on_button_change(&m_lbs, hit_counter, 2);
    }*/

    if(pin == RFID_INTERRUPT_PIN) {
        ble_lbs_on_button_change(&m_lbs, rfid_counter, 4);

        if(rfid_counter % 20 == 0){
            playNote(1072);
            set_rgb_color(2);
            nrf_delay_ms(10);
            playNote(1012);
            set_rgb_color(1);
            nrf_delay_ms(10);
            playNote(955);
            set_rgb_color(2);
            nrf_delay_ms(10);
            playNote(901); 
            set_rgb_color(0);
        }
        rfid_counter = rfid_read_event_handler();
    }
}
Example #7
0
int do_scalebar(void)
{
    double scale_size;
    double length, width;
    double x, x1, x2, y1, y2, y3;
    int seg, i, j, lab;
    int margin;
    char num[50];

    /* get scale size */
    scale_size =
	METERS_TO_INCHES * distance(PS.w.east, PS.w.west) / scale(PS.scaletext);

    /* convert scale size to map inches */
    length = (sb.length / scale_size) *
	G_database_units_to_meters_factor() * METERS_TO_INCHES;

    /* if(sb.units == SB_UNITS_AUTO) { do nothing } */
    if(sb.units == SB_UNITS_METERS)
	    length /= G_database_units_to_meters_factor();
    else if(sb.units == SB_UNITS_KM)
	    length *= KILOMETERS_TO_METERS / G_database_units_to_meters_factor();
    else if(sb.units == SB_UNITS_FEET)
	    length *= FEET_TO_METERS / G_database_units_to_meters_factor();
    else if(sb.units == SB_UNITS_MILES)
	    length *= MILES_TO_METERS / G_database_units_to_meters_factor();
    else if(sb.units == SB_UNITS_NMILES)
	    length *= NAUT_MILES_TO_METERS / G_database_units_to_meters_factor();

    width = sb.height;
    seg = sb.segment;
    j = 0;
    lab = 0;

    margin = (int)(0.2 * (double)sb.fontsize + 0.5);
    if (margin < 2)
	margin = 2;
    fprintf(PS.fp, "/mg %d def\n", margin);
    x = sb.x - (length / 2.);
    set_font_size(sb.fontsize);
    set_line_width(sb.width);

    if (strcmp(sb.type, "f") == 0) {
	/* draw fancy scale bar */

	for (i = 0; i < seg; i++) {
	    /* draw a filled rectangle */
	    x1 = 72.0 * (x + (length / seg) * i) + 0.5;
	    y1 = 72.0 * (PS.page_height - sb.y);
	    x2 = 72.0 * (x + (length / seg) * (i + 1)) + 0.5;
	    y2 = (72.0 * (PS.page_height - sb.y)) + (width * 72.0);

	    /* Alternate black and white */
	    if (j == 0) {
		fprintf(PS.fp, "0.0 0.0 0.0 C\n");
		j = 1;
	    }
	    else {
		fprintf(PS.fp, "1.0 1.0 1.0 C\n");
		j = 0;
	    }
	    fprintf(PS.fp, "%.1f %.1f %.1f %.1f B\n", x1, y1, x2, y2);

	    /* set outline to black */
	    fprintf(PS.fp, "F 0.0 0.0 0.0 C\n");
	    fprintf(PS.fp, "D\n");

	    lab++;

	    /* do text */
	    if (i == 0 || lab == sb.numbers) {
		sprintf(num, "%s", nice_number((sb.length / sb.segment) * i));
		text_box_path(x1, y2 + margin, CENTER, LOWER, num,
			      sb.fontsize, 0);
		if (sb.bgcolor) {	/* TODO: take bg color, not just [white|none] */
		    set_rgb_color(WHITE);
		    fprintf(PS.fp, "F ");
		}
		set_rgb_color(BLACK);
		fprintf(PS.fp, "TIB\n");
		lab = 0;
	    }

	    if ((lab > 0 && i == seg - 1) ||
		(sb.numbers == 1 && i == seg - 1)) {
		/* special case for last label */
		sprintf(num, "%s", nice_number(sb.length));
		text_box_path(x2, y2 + margin, CENTER, LOWER, num,
			      sb.fontsize, 0);
		if (sb.bgcolor) {
		    set_rgb_color(WHITE);
		    fprintf(PS.fp, "F ");
		}
		set_rgb_color(BLACK);
		fprintf(PS.fp, "TIB\n");
	    }

	}

    }
    else {
	/* draw simple scalebar */

	x1 = 72.0 * x + 0.5;
	y1 = (72.0 * (PS.page_height - sb.y)) + (width * 72.0);
	x2 = 72.0 * x + 0.5;
	y2 = 72.0 * (PS.page_height - sb.y);

	fprintf(PS.fp, "%.1f %.1f %.1f %.1f L D\n", x1, y1, x2, y2);

	/* draw label */
	text_box_path(x1, y1 + margin, CENTER, LOWER, "0", sb.fontsize, 0);
	if (sb.bgcolor) {
	    set_rgb_color(WHITE);
	    fprintf(PS.fp, "F ");
	}
	set_rgb_color(BLACK);
	fprintf(PS.fp, "TIB\n");


	x1 = 72.0 * x + 0.5;
	y1 = 72.0 * (PS.page_height - sb.y);
	x2 = 72.0 * (x + length) + 0.5;
	y2 = 72.0 * (PS.page_height - sb.y);
	fprintf(PS.fp, "%.1f %.1f %.1f %.1f L D\n", x1, y1, x2, y2);

	x1 = 72.0 * (x + length) + 0.5;
	y2 = (72.0 * (PS.page_height - sb.y)) + (width * 72.0);
	x2 = 72.0 * (x + length) + 0.5;
	y1 = 72.0 * (PS.page_height - sb.y);
	fprintf(PS.fp, "%.1f %.1f %.1f %.1f L D\n", x1, y1, x2, y2);

	/* draw label */
	sprintf(num, "%s", nice_number(sb.length));
	text_box_path(x1, y2 + margin, CENTER, LOWER, num, sb.fontsize, 0);
	if (sb.bgcolor) {
	    set_rgb_color(WHITE);
	    fprintf(PS.fp, "F ");
	}
	set_rgb_color(BLACK);
	fprintf(PS.fp, "TIB\n");


	for (i = 1; i < seg; i++) {
	    x1 = 72.0 * (x + (length / seg) * i) + 0.5;
	    y1 = 72.0 * (PS.page_height - sb.y);
	    x2 = 72.0 * (x + (length / seg) * i) + 0.5;
	    y2 = (72.0 * (PS.page_height - sb.y)) + (width / 2. * 72.0);
	    y3 = (72.0 * (PS.page_height - sb.y)) + (width * 72.0);

	    fprintf(PS.fp, "%.1f %.1f %.1f %.1f L D\n", x1, y1, x2, y2);

	    lab++;

	    /* do text */
	    if (lab == sb.numbers) {
		sprintf(num, "%s", nice_number((sb.length / sb.segment) * i));

		text_box_path(x1, y3 + margin, CENTER, LOWER, num,
			      sb.fontsize, 0);
		if (sb.bgcolor) {
		    set_rgb_color(WHITE);
		    fprintf(PS.fp, "F ");
		}
		set_rgb_color(BLACK);
		fprintf(PS.fp, "TIB\n");
		lab = 0;
	    }

	}
    }


    /* draw units label */
    if (sb.units == SB_UNITS_AUTO)
	strcpy(num, G_database_unit_name(TRUE));
    else if(sb.units == SB_UNITS_METERS)
	strcpy(num, "meters");
    else if(sb.units == SB_UNITS_KM)
	strcpy(num, "kilometers");
    else if(sb.units == SB_UNITS_FEET)
	strcpy(num, "feet");
    else if(sb.units == SB_UNITS_MILES)
	strcpy(num, "miles");
    else if(sb.units == SB_UNITS_NMILES)
	strcpy(num, "nautical miles");
    
    text_box_path(72.0 * (x + length/2), 72.0 * (PS.page_height - (sb.y + 0.075)),
	CENTER, UPPER, num, sb.fontsize, 0);

    if (sb.bgcolor) {
	set_rgb_color(WHITE);
	fprintf(PS.fp, "F ");
    }
    set_rgb_color(BLACK);
    fprintf(PS.fp, "TIB\n");


    return 0;
}
Example #8
0
int do_grid_numbers(void)
{
    double g;
    char num_text[50];
    int grid, vy, vx, hy = 0, hx = 0;
    int first, len, x, y, last_bottom, last_right;
    int rounded_grid, margin;

    if (PS.grid <= 0 || PS.grid_numbers <= 0)
	return 1;
    grid = PS.grid * PS.grid_numbers;

    /* round grid to multiple of 10 */
    rounded_grid = 1;
    if (PS.w.proj != PROJECTION_LL) {
	sprintf(num_text, "%d", PS.grid);
	len = strlen(num_text);
	while (len-- && num_text[len] == '0')
	    rounded_grid *= 10;
	if (rounded_grid == 10)
	    rounded_grid = 1;
    }

    /* initialize */
    set_font_name(PS.grid_font);
    set_font_size(PS.grid_fontsize);
    set_ps_color(&PS.grid_numbers_color);
    first = 1;

    /* horizontal grid numbers
     * these numbers only appear on the left edge of the first panel.
     * center the numbers on each grid line.
     * suppress number if it falls off the map or would overlay the previous
     *  label
     */
    margin = (int)(0.2 * (double)PS.grid_fontsize + 0.5);
    if (margin < 2)
	margin = 2;
    fprintf(PS.fp, "/mg %d def\n", margin);
    g = floor(PS.w.north / grid) * grid;
    last_bottom = (int)PS.map_top;
    first = 1;
    /* x = XCONV(PS.w.west); */

    for (; g > PS.w.south; g -= grid) {
	/*y = YCONV(g); */

	G_plot_where_xy(PS.w.west, g, &vx, &vy);
	x = (double)vx / 10.;
	y = (double)vy / 10.;

	if (y + PS.grid_fontsize > last_bottom)
	    continue;
	if (y - PS.grid_fontsize < (int)PS.map_bot)
	    continue;
	sprintf(num_text, "%s", format_northing(g, rounded_grid));
	text_box_path(x, y, LEFT, CENTER, num_text, PS.grid_fontsize, 0);
	set_rgb_color(WHITE);
	fprintf(PS.fp, "F ");
	set_ps_color(&PS.grid_numbers_color);
	fprintf(PS.fp, "TIB\n");
	last_bottom = y - PS.grid_fontsize;
	if (first) {
	    first = 0;
	    hy = y + (int)(0.5 * (double)PS.grid_fontsize + 0.5) + margin;
	    hx = x + 0.7 * strlen(num_text) * PS.grid_fontsize + 2 * margin;
	}
    }

    /* vertical grid numbers 
     * center the numbers on each grid line.
     * suppress number if it falls of the map or would overlay the previous
     *  label
     */
    g = floor(PS.w.west / grid) * grid;
    last_right = (int)PS.map_left;
    /* y = YCONV(PS.w.north); */
    for (; g < PS.w.east; g += grid) {
	/* x = XCONV(g); */

	G_plot_where_xy(g, PS.w.north, &vx, &vy);
	x = (double)vx / 10.;
	y = (double)vy / 10.;

	if (x - PS.grid_fontsize < last_right)
	    continue;
	if (x + PS.grid_fontsize > (int)PS.map_right)
	    continue;
	sprintf(num_text, "%s", format_easting(g, rounded_grid));
	vy = y - 0.7 * strlen(num_text) * PS.grid_fontsize - 2 * margin;
	vx = x - (int)(0.5 * (double)PS.grid_fontsize + 0.5) - margin;
	if (vx < hx && vy < hy)
	    continue;
	fprintf(PS.fp, "ZB (%s) PB 90 rotate\n", num_text);
	fprintf(PS.fp, "%d br sub bl add mg add\n", y);
	fprintf(PS.fp, "%d bt bb sub D2 add mg sub neg TR TB\n", x);
	set_rgb_color(WHITE);
	fprintf(PS.fp, "F ");
	set_ps_color(&PS.grid_numbers_color);
	fprintf(PS.fp, "TIB\n");
	last_right = x + PS.grid_fontsize;
    }

    return 0;
}
Example #9
0
void palette_black()
{
	int x;

	for (x=0; x<=255;x++) set_rgb_color(x,0,0,0);
}