예제 #1
0
/**
  * Constructor.
  *
  * Create a software representation the micro:bit's 5x5 LED matrix.
  * The display is initially blank.
  *
  * @param id The id the display should use when sending events on the MessageBus. Defaults to MICROBIT_ID_DISPLAY.
  *
  * @param map The mapping information that relates pin inputs/outputs to physical screen coordinates.
  *            Defaults to microbitMatrixMap, defined in MicroBitMatrixMaps.h.
  *
  * @code
  * MicroBitDisplay display;
  * @endcode
  */
MicroBitDisplay::MicroBitDisplay(uint16_t id, const MatrixMap &map) :
    matrixMap(map),
    image(map.width*2,map.height)
{
    uint32_t row_mask;

    this->id = id;
    this->width = map.width;
    this->height = map.height;
    this->rotation = MICROBIT_DISPLAY_ROTATION_0;

    row_mask = 0;
    col_mask = 0;
    strobeRow = 0;
    row_mask = 0;

    for (int i = matrixMap.rowStart; i < matrixMap.rowStart + matrixMap.rows; i++)
        row_mask |= 0x01 << i;

    for (int i = matrixMap.columnStart; i < matrixMap.columnStart + matrixMap.columns; i++)
        col_mask |= 0x01 << i;

    LEDMatrix = new PortOut(Port0, row_mask | col_mask);

    this->greyscaleBitMsk = 0x01;
    this->timingCount = 0;
    this->setBrightness(MICROBIT_DISPLAY_DEFAULT_BRIGHTNESS);
    this->mode = DISPLAY_MODE_BLACK_AND_WHITE;
    this->animationMode = ANIMATION_MODE_NONE;
    this->lightSensor = NULL;

	system_timer_add_component(this);

    status |= MICROBIT_COMPONENT_RUNNING;
}
예제 #2
0
//constructor
CalliopeSoundMotor::CalliopeSoundMotor()
{
    //init sleep pin
    nrf_gpio_cfg_output(CALLIOPE_SM_PIN_NSLEEP);
    nrf_gpio_pin_clear(CALLIOPE_SM_PIN_NSLEEP);

    //set default values
    duty_motor_percent = CALLIOPE_SM_DEFAULT_DUTY_M;
    duty_motor_A_percent = CALLIOPE_SM_DEFAULT_DUTY_M;
    duty_motor_B_percent = CALLIOPE_SM_DEFAULT_DUTY_M;
    motor_AB_current_use = 0;
    frequency_sound_hz = CALLIOPE_SM_DEFAULT_FREQUENCY_S;
    silent_mode = CALLIOPE_SM_DEFAULT_SILENT_MODE;
    mode = 0;

    //init PWM
    this->PWM_init();

    //add RGB LED object to the sytem timer
    system_timer_add_component(this);
}