2022-03-22 17:36:19 +01:00
|
|
|
const compassImagesLeft = [
|
2020-09-11 11:19:33 +02:00
|
|
|
images.createImage(`
|
|
|
|
. . # . .
|
|
|
|
. . . . .
|
|
|
|
. . # . .
|
|
|
|
. . . . .
|
|
|
|
. . . . .
|
|
|
|
`),
|
|
|
|
images.createImage(`
|
|
|
|
. # . . .
|
|
|
|
. . . . .
|
|
|
|
. . # . .
|
|
|
|
. . . . .
|
|
|
|
. . . . .
|
|
|
|
`),
|
|
|
|
images.createImage(`
|
|
|
|
# . . . .
|
|
|
|
. . . . .
|
|
|
|
. . # . .
|
|
|
|
. . . . .
|
|
|
|
. . . . .
|
|
|
|
`),
|
|
|
|
images.createImage(`
|
|
|
|
. . . . .
|
|
|
|
# . . . .
|
|
|
|
. . # . .
|
|
|
|
. . . . .
|
|
|
|
. . . . .
|
|
|
|
`),
|
|
|
|
images.createImage(`
|
|
|
|
. . . . .
|
|
|
|
. . . . .
|
|
|
|
# . # . .
|
|
|
|
. . . . .
|
|
|
|
. . . . .
|
|
|
|
`),
|
|
|
|
images.createImage(`
|
|
|
|
. . . . .
|
|
|
|
. . . . .
|
|
|
|
. . # . .
|
|
|
|
# . . . .
|
|
|
|
. . . . .
|
|
|
|
`),
|
|
|
|
images.createImage(`
|
|
|
|
. . . . .
|
|
|
|
. . . . .
|
|
|
|
. . # . .
|
|
|
|
. . . . .
|
|
|
|
# . . . .
|
|
|
|
`),
|
|
|
|
images.createImage(`
|
|
|
|
. . . . .
|
|
|
|
. . . . .
|
|
|
|
. . # . .
|
|
|
|
. . . . .
|
|
|
|
. # . . .
|
|
|
|
`)];
|
|
|
|
|
2022-03-22 17:36:19 +01:00
|
|
|
const compassImagesRight = [
|
2020-09-11 11:19:33 +02:00
|
|
|
images.createImage(`
|
|
|
|
. . . . .
|
|
|
|
. . . . .
|
|
|
|
. . # . .
|
|
|
|
. . . . .
|
|
|
|
. . # . .
|
|
|
|
`),
|
|
|
|
images.createImage(`
|
|
|
|
. . . . .
|
|
|
|
. . . . .
|
|
|
|
. . # . .
|
|
|
|
. . . . .
|
|
|
|
. . . # .
|
|
|
|
`),
|
|
|
|
images.createImage(`
|
|
|
|
. . . . .
|
|
|
|
. . . . .
|
|
|
|
. . # . .
|
|
|
|
. . . . .
|
|
|
|
. . . . #
|
|
|
|
`),
|
|
|
|
images.createImage(`
|
|
|
|
. . . . .
|
|
|
|
. . . . .
|
|
|
|
. . # . .
|
|
|
|
. . . . #
|
|
|
|
. . . . .
|
|
|
|
`),
|
|
|
|
images.createImage(`
|
|
|
|
. . . . .
|
|
|
|
. . . . .
|
|
|
|
. . # . #
|
|
|
|
. . . . .
|
|
|
|
. . . . .
|
|
|
|
`),
|
|
|
|
images.createImage(`
|
|
|
|
. . . . .
|
|
|
|
. . . . #
|
|
|
|
. . # . .
|
|
|
|
. . . . .
|
|
|
|
. . . . .
|
|
|
|
`),
|
|
|
|
images.createImage(`
|
|
|
|
. . . . #
|
|
|
|
. . . . .
|
|
|
|
. . # . .
|
|
|
|
. . . . .
|
|
|
|
. . . . .
|
|
|
|
`),
|
|
|
|
images.createImage(`
|
|
|
|
. . . # .
|
|
|
|
. . . . .
|
|
|
|
. . # . .
|
|
|
|
. . . . .
|
|
|
|
. . . . .
|
|
|
|
`)];
|
|
|
|
|
2022-03-22 17:36:19 +01:00
|
|
|
const compassImages = compassImagesLeft.concat(compassImagesRight);
|
|
|
|
const compassImagesDownside = compassImagesRight.concat(compassImagesLeft);
|
2020-09-11 11:19:33 +02:00
|
|
|
|
|
|
|
|
2020-09-11 14:18:32 +02:00
|
|
|
namespace basic {
|
2020-09-11 11:19:33 +02:00
|
|
|
/**
|
|
|
|
* Draws needle on the screen which always points to north
|
|
|
|
* @param interval the amount of time (milliseconds) to show the needle. Default is 600.
|
|
|
|
*/
|
|
|
|
//% weight=50 blockGap=8
|
|
|
|
//% blockId=basic_show_compass
|
|
|
|
//% block="show compass needle for $interval|ms"
|
|
|
|
//% interval.shadow=timePicker
|
|
|
|
//% interval.min=1
|
|
|
|
//% interval.defl=600
|
|
|
|
//% parts="ledmatrix"
|
|
|
|
//% advanced=true
|
2022-03-22 17:36:19 +01:00
|
|
|
//% group="LED matrix"
|
2020-09-11 11:19:33 +02:00
|
|
|
export function showCompass(interval = 600) {
|
|
|
|
let i = 0
|
|
|
|
let startTime = input.runningTime()
|
|
|
|
let endTime = startTime + interval
|
|
|
|
let refreshRate = 100
|
|
|
|
let rest = 0
|
|
|
|
|
|
|
|
while ((endTime) > (input.runningTime() + refreshRate)) {
|
|
|
|
i = Math.round((input.compassHeading() - 11.25) / 22.5)
|
2022-03-22 17:36:19 +01:00
|
|
|
let images = (input.isGesture(Gesture.ScreenDown)) ? compassImagesDownside : compassImages;
|
|
|
|
images[i].showImage(0, refreshRate)
|
2020-09-11 11:19:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
rest = (endTime - input.runningTime())
|
|
|
|
if(rest > 0) {
|
|
|
|
i = Math.round((input.compassHeading() - 11.25) / 22.5)
|
2022-03-22 17:36:19 +01:00
|
|
|
let images = (input.isGesture(Gesture.ScreenDown)) ? compassImagesDownside : compassImages;
|
|
|
|
images[i].showImage(0, rest)
|
2020-09-11 11:19:33 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|