scenarios = [
{
name: "Temperature Sensor (8-bit ADC)",
description: "A temperature sensor returns raw ADC value 0xB5. If the range is 0-100C mapped to 0-255, what's the temperature?",
inputHex: "B5",
formula: "Temperature = (ADC_Value / 255) x 100C",
answer: val => `${((val / 255) * 100).toFixed(1)}C`,
explanation: "0xB5 = 181 decimal. (181/255) x 100 = 71.0C"
},
{
name: "GPIO Register (Bit Manipulation)",
description: "A GPIO register reads 0x5A. Which pins (0-7) are HIGH?",
inputHex: "5A",
formula: "Convert to binary and check each bit",
answer: val => {
const pins = [];
for (let i = 0; i < 8; i++) {
if (val & (1 << i)) pins.push(i);
}
return `Pins ${pins.join(', ')} are HIGH`;
},
explanation: "0x5A = 01011010 binary. Bits 1, 3, 4, 6 are set (pins 1, 3, 4, 6)"
},
{
name: "LoRaWAN DevAddr",
description: "A device address is 0x26011234. What's the decimal equivalent?",
inputHex: "26011234",
formula: "Direct hex to decimal conversion",
answer: val => val.toLocaleString(),
explanation: "0x26011234 = 637,538,868 decimal"
},
{
name: "MQTT Packet Length",
description: "An MQTT packet header shows remaining length 0x80 0x01. Using variable-length encoding, what's the actual length?",
inputHex: "8001",
formula: "Variable length: (byte1 & 0x7F) + ((byte2 & 0x7F) << 7)",
answer: val => {
const b1 = (val >> 8) & 0xFF;
const b2 = val & 0xFF;
const len = (b1 & 0x7F) + ((b2 & 0x7F) << 7);
return `${len} bytes`;
},
explanation: "(0x80 & 0x7F) + ((0x01 & 0x7F) << 7) = 0 + 128 = 128 bytes"
},
{
name: "BLE UUID (16-bit)",
description: "A BLE characteristic has UUID 0x2A19 (Battery Level). What's the full 128-bit UUID?",
inputHex: "2A19",
formula: "Insert into base UUID: 0000xxxx-0000-1000-8000-00805F9B34FB",
answer: val => `0000${val.toString(16).toUpperCase().padStart(4, '0')}-0000-1000-8000-00805F9B34FB`,
explanation: "16-bit UUIDs expand to: 0000xxxx-0000-1000-8000-00805F9B34FB where xxxx is the short UUID"
}
]
viewof selectedScenario = Inputs.select(scenarios, {
label: "Select Scenario:",
format: s => s.name
})