示例#1
0
文件: main.c 项目: mripard/utbm-LO52
/**
 * Initialisation des differents capteurs et du bluetooth
 */
void init(void)
{
	nx_display_clear();
	nx_display_cursor_set_pos(0, 0);
	nx_display_string("Lo52 project\n");
	nx_display_cursor_set_pos(0, 2);

	//on affiche le niveau de la batterie
	nx_display_uint(nx_avr_get_battery_voltage());
	nx_display_cursor_set_pos(4, 2);
	nx_display_string("/4000\n");
	nx_systick_install_scheduler(watchdog);

	// initialise le radar ultrason
	nx_radar_init(RADAR_SENSOR);

	//initialise le bluetooth
	bt_init();
	nx_display_string("bluetooth...OK");

	//initialise le son
	nx__sound_init();

	// initialise le capteur de contact
	nx_sensors_analog_enable(TOUCH_SENSOR);

	//initialise le capteur de luminosité
	nx_sensors_analog_enable(LIGHT_SENSOR);
	nx_sensors_analog_digi_set(LIGHT_SENSOR, DIGI0);

}
示例#2
0
void sensors_init(void) {
  nx_radar_init(SENSORS_RADAR);
  sensors_wall();
  nx_sensors_analog_enable(SENSORS_TOUCH);
  nx_sensors_analog_enable(SENSORS_LIGHT);
  nx_sensors_analog_digi_set(SENSORS_LIGHT, DIGI0);
}
示例#3
0
文件: main.c 项目: Jazzinghen/NXoSPAM
void main(void) {
  nx_systick_install_scheduler(security_hook);

  bool moving = FALSE;
  S32 total_rotation = 0;
  S8 speed = 60;
  S8 start_angle = 0;

  //tests_all();
  //tests_usb();
  //tests_bt();
  //tests_usb_hardcore();
  //tests_radar();
  //tests_util();
  //tests_defrag();
  
  nx_radar_init(RADAR_SENSOR);
  nx_lightsensor_init(LIGHT_SENSOR);
  //nx_lightsensor_fire_spamlight(LIGHT_SENSOR);
  
 /* for (fuffa_rot = 0; (nx_motors_get_tach_count(0) % 360) < 90; fuffa_rot++) {
      nx_systick_wait_ms(1000);
      nx_motors_rotate_angle(0, 100, 1, TRUE);
  } */
    
  for(;;) {
    nx_systick_wait_ms(500);
    //nx_display_cursor_set_pos(9, 3);
    nx_display_clear();
    total_rotation = nx_motors_get_tach_count(RADAR_MOTOR); 
    display_rotation_data(speed, total_rotation, start_angle);
    
    
    
    switch (nx_avr_get_button()) {
      case BUTTON_LEFT:
       /* if (speed >= -95) { 
          speed -= 5;
        } else {
          speed = -100;
        }*/
        nx_motors_rotate (0, -60);
        nx_systick_wait_ms(100);
        start_angle = nx_motors_get_tach_count(0);
        nx_motors_rotate_angle(RADAR_MOTOR, -35, 45, FALSE);
        /*nx_systick_wait_ms(1000);
         *nx_motors_rotate_angle(0, 100, 45, TRUE);
         */
        break;
      case BUTTON_RIGHT:
        /*if (speed <= 95) { 
          speed += 5;
        } else {
          speed = 100;
        }
        nx_motors_rotate (0, speed);*/
        nx_motors_rotate (0, 60);
        nx_systick_wait_ms(100);
        start_angle = nx_motors_get_tach_count(0);
        nx_motors_rotate_angle(RADAR_MOTOR, 35, 45, FALSE);
        break;
      case BUTTON_OK:
        if (moving) {
          nx_motors_stop(RADAR_MOTOR, TRUE);
          //nx_motors_stop(1, TRUE);
          //nx_motors_stop(2, TRUE);
          moving = !moving;
        } else {
          nx_motors_rotate(RADAR_MOTOR, speed);
          //nx_motors_rotate(1, 20);
          //nx_motors_rotate(2, 20);
          moving = !moving;
        }
        break;
      default:
        break;
    } 
  };
}
示例#4
0
void tests_radar(void) {
#ifdef TEST_PORT4_I2C
  U32 sensor = 3;
#else
  U32 sensor = 2;
#endif

  U8 reading;
  S8 object;
  U8 objects[8];

  hello();

  nx_display_clear();
  nx_display_cursor_set_pos(0, 0);
  nx_radar_init(sensor);

  nx_display_string("Discovering...\n");

  while (!nx_radar_detect(sensor)) {
    nx_display_string("Error! Retrying\n");
    nx_systick_wait_ms(500);

    nx_display_clear();
    nx_display_cursor_set_pos(0, 0);
    nx_display_string("Discovering...\n");
  }

  nx_display_string("Found.\n\n");
  nx_radar_info(sensor);

  while (nx_avr_get_button() != BUTTON_OK);

  // We are toggling between reading all values
  // and reading them one after another. Just for fun and to test
  // both ways to communicate with the US.
  bool read_toggle = TRUE;

  while (nx_avr_get_button() != BUTTON_RIGHT) {
    // We are using the single shot mode, in continuous mode
    // the US doesn't seem to measure more than one byte.
    nx_radar_set_op_mode(sensor, RADAR_MODE_SINGLE_SHOT);
    // Give the sensor the time to receive the echos and store
    // the measurements.
    nx_systick_wait_ms(100);
    // Go on and read and display the values.
    nx_display_clear();
    nx_display_cursor_set_pos(0, 0);

    if( ! read_toggle ) {
      memset(objects, 0, sizeof(objects));
      if( ! nx_radar_read_all(sensor, objects) ) {
        nx_display_string("Error reading!\n");
        break;
      }
    }
    for (object=0 ; object<8 ; object++) {
      nx_display_uint(object);
      nx_display_string("> ");

      if( ! read_toggle )
        reading = objects[object];
      else
        reading = nx_radar_read_distance(sensor, object);

      if (reading > 0x00 && reading < 0xFF) {
        nx_display_uint(reading);
        nx_display_string(" cm");
      } else {
        nx_display_string("n/a");
      }
      if( ! object ) {
        if( ! read_toggle )
          nx_display_string(" (read8)");
        else
          nx_display_string(" (read1)");
      }
      nx_display_end_line();
    }

    read_toggle = ! read_toggle;
    nx_systick_wait_ms(1000);
  }

  nx_radar_close(sensor);
  goodbye();
}