131 Week 8 - micro:bit buttons, temps, logs Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

How to access buttons in CODAL

A

uBit.buttonA, uBit.buttonB and uBit.buttonAB for button A, button B and button A+B respectively

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Detecting button presses

A

.isPressed() returns 1 or 0 if the specified button has been pressed.
Synchronous programming, detection of buttons is done in main() function.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Asynchronous programming

A

Asynchronous detection determines when something has happened rather than if it has happened.
MicroBitMessageBus class is to listen to events and delivers MicroBitEvents as they occur.
When an event of interest is detected, MicroBitMessageBus class calls a function linked to that event, known as an event handler.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

release_fibre()

A

Used in asynchronous programming to stop exiting main() once code is executed so that we can use messageBus.listen();
Place at the end of the main() function.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Detecting an event

A

uBit.messageBus.listen(MICROBIT_ID_BUTTON_AB, MICROBIT_BUTTON_EVT_CLICK, onButtonAB);
Has 3 arguments:
ID of component to listen to
Event of interest
Event handler to be called if event is called

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Wildcard event

A

Event ID of: MICROBIT_EVT_ANY
Allows event handler to be called if the component raises any events

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Event handler

A

void onButtonAB(MicroBitEvent e)
Name has to match the argument in messageBus.listen()
Has 1 argument which stores the event that was raised
Can use e.value to return the ID of the event that was raised.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

MicroBitThermometer

A

A class that lets you return the surface temperature of the application MCU - not the ambient temperature

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Get uncalibrated temp reading

A

readTemp = uBit.thermometer.getTemperature();

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Calibrating the temperature

A

Can measure ambient temperature if we know the real temperature by calibrating the thermometer:
uBit.thermometer.setCalibration(readTemp-ambientTemp);
readTemp = uBit.thermometer.getTemperature();

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Asynchronous temperature reading

A

uBit.messageBus.listen(MICROBIT_ID_THERMOMETER, MICROBIT_THERMOMETER_EVT_UPDATE, eventHandlerName);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Sampling period

A

The time between temperature readings.
Can be set using:
uBit.thermometer.setPeriod(time in ms);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Logging data

A

need #include “MicroBitLog.h”
Allows storing of data in a table like format containing rows of readings or other types of data.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

How to log data

A

beginRow() – open a file and create a new row
logData(“label of column”, value_to_log) - identify the label of the column where a value will be entered in the new row.
endRow() - complete logging and close the file.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Timestamp

A

A timestamp can be added before data is started to be collected and logged.
Not necessary but it allows you to create a plot of recorded values.
uBit.log.setTimeStamp(TimeStampFormat::Seconds);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Access the log file

A

uBit.log.setVisibility(true);
Allows you to find the log file (named MY_DATA.HTM) in the micro:bit folder and access it using a browser.

17
Q

Check if the log is full

A

uBit.log.isFull() returns 0 if the log isn’t full and 1 if it is

18
Q

Clear the log

A

uBit.log.clear(); clears the contents of the log file