Navigasi Materi

Makecode Micro:bit #13 - Compas Alarm

MakeCode micro:bit Lab #13 - Compass Alarm

🧭 MakeCode micro:bit Lab #13 — Compass Alarm

English: Use compass heading to trigger an alarm when the micro:bit faces a target direction.

Indonesia: Gunakan heading kompas untuk menyalakan alarm ketika micro:bit menghadap arah tertentu.

Sensor → Condition → Action

🧭 Simulator / Simulasi

AB
0123VGND
N
E
S
W
0°
North / Utara
0° N90° E180° S270° W
Press RUN to start the compass alarm.
Target direction: 90° East.
Arah target: 90° Timur.

📊 Results / Hasil

🧭
Heading
Arah hadap
North
➡️
Direction
Arah
0
🔔
Alarm
Bunyi alarm

💡 Cara Bermain / How to Play

1
Tekan RUN.
Press RUN.
2
Atur heading ke 90°.
Set the heading to 90°.
3
Ketika tepat 90°, alarm aktif.
When the heading reaches 90°, the alarm activates.
Ini adalah contoh condition: IF heading = 90° THEN play sound.

🎯 Tujuan Pembelajaran / Learning Goal

Menggunakan sensor kompas sebagai input.
/ Use the compass sensor as an input.
Menggunakan kondisi if...then.
/ Use an if...then condition.
Menghubungkan sensor dengan aksi suara.
/ Connect a sensor to a sound action.

🚀 Coba di micro:bit sungguhan!

Try it with a real micro:bit!

Gunakan compass heading dan if...then untuk membuat alarm arah.
Use compass heading and if...then to create a direction alarm.

↗ Open Microsoft MakeCode for micro:bit →

Official MakeCode: makecode.microbit.org

📐 Math Connection

Sudut dan Kondisi

Program membandingkan sudut heading dengan sudut target.

IF heading = 90° → Alarm ON

🧩 Program / Program

Program ini sudah dibuat dalam tiga bentuk: Blocks, JavaScript, dan Python.

forever set heading to compass heading if heading = 90 then play sound on button A pressed show arrow East

Blok utama: compass heading + if...then + play sound.

let heading = 0 basic.forever(function () { heading = input.compassHeading() if (heading == 90) { music.playTone(262, music.beat(BeatFraction.Quarter)) } }) input.onButtonPressed(Button.A, function () { basic.showArrow(ArrowNames.East) })

MakeCode JavaScript: kode ini dapat dimasukkan pada editor JavaScript di MakeCode.

from microbit import * import music while True: heading = compass.heading() if heading == 90: music.play(music.POWER_UP) if button_a.was_pressed(): display.show(Image.ARROW_E)

Python: contoh berbasis MicroPython. Untuk latihan MakeCode, gunakan Blocks atau JavaScript MakeCode sebagai pilihan utama.

🧠 Practice / Latihan

Question / Pertanyaan:

The target heading is 90°. Which condition should activate the alarm?

Arah target adalah 90°. Kondisi mana yang harus mengaktifkan alarm?

🏆 Challenges / Tantangan

Challenge 1 — Find the Target

Press RUN and set the heading to 90°. Then press Check.

Challenge 2 — Think Like a Programmer

Which block makes the decision?

Challenge 3 — Change the Target

If the target is changed from 90° to 180°, what condition should be used?

📐 Math Connection / Hubungan dengan Matematika

Aktivitas ini memperkenalkan konsep persamaan dan kondisi. Sensor menghasilkan nilai sudut, kemudian program membandingkannya dengan nilai target.

heading = 90° → action

Konsep ini nantinya dapat dikembangkan menjadi robot yang berbelok berdasarkan arah.